1
0

board.c 2.4 KB

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