board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard first implementation
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "stm32f4xx.h"
  13. #include "board.h"
  14. #include "usart.h"
  15. #include "gpio.h"
  16. /**
  17. * @addtogroup STM32
  18. */
  19. /*@{*/
  20. /*******************************************************************************
  21. * Function Name : NVIC_Configuration
  22. * Description : Configures Vector Table base location.
  23. * Input : None
  24. * Output : None
  25. * Return : None
  26. *******************************************************************************/
  27. void NVIC_Configuration(void)
  28. {
  29. #ifdef VECT_TAB_RAM
  30. /* Set the Vector Table base location at 0x20000000 */
  31. NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  32. #else /* VECT_TAB_FLASH */
  33. /* Set the Vector Table base location at 0x08000000 */
  34. NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  35. #endif
  36. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  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. cnts = cnts / 8;
  52. SysTick_Config(cnts);
  53. SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
  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. #ifdef RT_USING_HEAP
  77. rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
  78. #endif
  79. rt_components_board_init();
  80. #ifdef RT_USING_CONSOLE
  81. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  82. #endif
  83. }
  84. /*@}*/