board.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "board.h"
  17. /**
  18. * @addtogroup STM32
  19. */
  20. /*@{*/
  21. /*******************************************************************************
  22. * Function Name : NVIC_Configuration
  23. * Description : Configures Vector Table base location.
  24. * Input : None
  25. * Output : None
  26. * Return : None
  27. *******************************************************************************/
  28. void NVIC_Configuration(void)
  29. {
  30. #ifdef VECT_TAB_RAM
  31. /* Set the Vector Table base location at 0x20000000 */
  32. NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  33. #else /* VECT_TAB_FLASH */
  34. /* Set the Vector Table base location at 0x08000000 */
  35. NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  36. #endif
  37. }
  38. /*******************************************************************************
  39. * Function Name : SysTick_Configuration
  40. * Description : Configures the SysTick for OS tick.
  41. * Input : None
  42. * Output : None
  43. * Return : None
  44. *******************************************************************************/
  45. void SysTick_Configuration(void)
  46. {
  47. RCC_ClocksTypeDef rcc_clocks;
  48. rt_uint32_t cnts;
  49. RCC_GetClocksFreq(&rcc_clocks);
  50. cnts = (rt_uint32_t)rcc_clocks.HCLK_Frequency / RT_TICK_PER_SECOND;
  51. SysTick_Config(cnts);
  52. SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  53. }
  54. /**
  55. * This is the timer interrupt service routine.
  56. *
  57. */
  58. void rt_hw_timer_handler(void)
  59. {
  60. /* enter interrupt */
  61. rt_interrupt_enter();
  62. rt_tick_increase();
  63. /* leave interrupt */
  64. rt_interrupt_leave();
  65. }
  66. /**
  67. * This function will initial STM32 board.
  68. */
  69. void rt_hw_board_init()
  70. {
  71. /* NVIC Configuration */
  72. NVIC_Configuration();
  73. /* Configure the SysTick */
  74. SysTick_Configuration();
  75. rt_hw_usart_init();
  76. rt_console_set_device(CONSOLE_DEVICE);
  77. }
  78. /*@}*/