board.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <stm32f2xx.h>
  17. #include "board.h"
  18. /**
  19. * @addtogroup STM32
  20. */
  21. /*@{*/
  22. /*******************************************************************************
  23. * Function Name : NVIC_Configuration
  24. * Description : Configures Vector Table base location.
  25. * Input : None
  26. * Output : None
  27. * Return : None
  28. *******************************************************************************/
  29. void NVIC_Configuration(void)
  30. {
  31. #ifdef VECT_TAB_RAM
  32. /* Set the Vector Table base location at 0x20000000 */
  33. NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  34. #else /* VECT_TAB_FLASH */
  35. /* Set the Vector Table base location at 0x08000000 */
  36. NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  37. #endif
  38. }
  39. /*******************************************************************************
  40. * Function Name : SysTick_Configuration
  41. * Description : Configures the SysTick for OS tick.
  42. * Input : None
  43. * Output : None
  44. * Return : None
  45. *******************************************************************************/
  46. void SysTick_Configuration(void)
  47. {
  48. RCC_ClocksTypeDef rcc_clocks;
  49. rt_uint32_t cnts;
  50. RCC_GetClocksFreq(&rcc_clocks);
  51. cnts = (rt_uint32_t)rcc_clocks.HCLK_Frequency / RT_TICK_PER_SECOND;
  52. SysTick_Config(cnts);
  53. SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  54. }
  55. /**
  56. * This is the timer interrupt service routine.
  57. *
  58. */
  59. void SysTick_Handler(void)
  60. {
  61. /* enter interrupt */
  62. rt_interrupt_enter();
  63. rt_tick_increase();
  64. /* leave interrupt */
  65. rt_interrupt_leave();
  66. }
  67. /**
  68. * This function will initial STM32 board.
  69. */
  70. void rt_hw_board_init()
  71. {
  72. /* NVIC Configuration */
  73. NVIC_Configuration();
  74. /* Configure the SysTick */
  75. SysTick_Configuration();
  76. rt_hw_usart_init();
  77. #ifdef RT_USING_CONSOLE
  78. rt_console_set_device(CONSOLE_DEVICE);
  79. #endif
  80. }
  81. /*@}*/