board.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "stm32f4xx.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. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  39. }
  40. /*******************************************************************************
  41. * Function Name : SysTick_Configuration
  42. * Description : Configures the SysTick for OS tick.
  43. * Input : None
  44. * Output : None
  45. * Return : None
  46. *******************************************************************************/
  47. void SysTick_Configuration(void)
  48. {
  49. RCC_ClocksTypeDef rcc_clocks;
  50. rt_uint32_t cnts;
  51. RCC_GetClocksFreq(&rcc_clocks);
  52. cnts = (rt_uint32_t)rcc_clocks.HCLK_Frequency / RT_TICK_PER_SECOND;
  53. cnts = cnts / 8;
  54. SysTick_Config(cnts);
  55. SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
  56. }
  57. /**
  58. * This is the timer interrupt service routine.
  59. *
  60. */
  61. void SysTick_Handler(void)
  62. {
  63. /* enter interrupt */
  64. rt_interrupt_enter();
  65. rt_tick_increase();
  66. /* leave interrupt */
  67. rt_interrupt_leave();
  68. }
  69. /**
  70. * This function will initial STM32 board.
  71. */
  72. void rt_hw_board_init()
  73. {
  74. /* NVIC Configuration */
  75. NVIC_Configuration();
  76. /* Configure the SysTick */
  77. SysTick_Configuration();
  78. rt_hw_usart_init();
  79. #ifdef RT_USING_CONSOLE
  80. rt_console_set_device(CONSOLE_DEVICE);
  81. #endif
  82. }
  83. /*@}*/