1
0

drv_common.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * 2018-11-7 SummerGift change to new framework
  9. */
  10. #include "drv_common.h"
  11. #ifdef RT_USING_PIN
  12. #include "drv_gpio.h"
  13. #endif
  14. #ifdef RT_USING_SERIAL
  15. #include "drv_usart.h"
  16. #endif
  17. #ifdef RT_USING_FINSH
  18. #include <finsh.h>
  19. static void reboot(uint8_t argc, char **argv)
  20. {
  21. rt_hw_cpu_reset();
  22. }
  23. FINSH_FUNCTION_EXPORT_ALIAS(reboot, __cmd_reboot, Reboot System);
  24. #endif /* RT_USING_FINSH */
  25. /* SysTick configuration */
  26. void rt_hw_systick_init(void)
  27. {
  28. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
  29. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  30. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  31. }
  32. /**
  33. * This is the timer interrupt service routine.
  34. *
  35. */
  36. void SysTick_Handler(void)
  37. {
  38. /* enter interrupt */
  39. rt_interrupt_enter();
  40. HAL_IncTick();
  41. rt_tick_increase();
  42. /* leave interrupt */
  43. rt_interrupt_leave();
  44. }
  45. uint32_t HAL_GetTick(void)
  46. {
  47. return rt_tick_get() * 1000 / RT_TICK_PER_SECOND;
  48. }
  49. void HAL_SuspendTick(void)
  50. {
  51. }
  52. void HAL_ResumeTick(void)
  53. {
  54. }
  55. void HAL_Delay(__IO uint32_t Delay)
  56. {
  57. }
  58. /* re-implement tick interface for STM32 HAL */
  59. HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  60. {
  61. /* Return function status */
  62. return HAL_OK;
  63. }
  64. /**
  65. * @brief This function is executed in case of error occurrence.
  66. * @param None
  67. * @retval None
  68. */
  69. void _Error_Handler(char *s, int num)
  70. {
  71. /* USER CODE BEGIN Error_Handler */
  72. /* User can add his own implementation to report the HAL error return state */
  73. while(1)
  74. {
  75. }
  76. /* USER CODE END Error_Handler */
  77. }
  78. /**
  79. * This function will initial STM32 board.
  80. */
  81. RT_WEAK void rt_hw_board_init()
  82. {
  83. /* HAL_Init() function is called at the beginning of the program */
  84. HAL_Init();
  85. /* System clock initialization */
  86. SystemClock_Config();
  87. rt_hw_systick_init();
  88. /* Hardware GPIO initialization */
  89. MX_GPIO_Init();
  90. /* Heap initialization */
  91. #if defined(RT_USING_HEAP)
  92. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  93. #endif
  94. /* Pin driver initialization is open by default */
  95. #ifdef RT_USING_PIN
  96. rt_hw_pin_init();
  97. #endif
  98. /* USART driver initialization is open by default */
  99. #ifdef RT_USING_SERIAL
  100. rt_hw_usart_init();
  101. #endif
  102. /* Set the shell console output device */
  103. #ifdef RT_USING_CONSOLE
  104. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  105. #endif
  106. /* Board underlying hardware initialization */
  107. #ifdef RT_USING_COMPONENTS_INIT
  108. rt_components_board_init();
  109. #endif
  110. }