board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-08-23 liYony first version
  9. */
  10. #include "board.h"
  11. #include <stdint.h>
  12. #include "drv_usart.h"
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. extern uint32_t SystemCoreClock;
  16. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  17. {
  18. NVIC_SetPriority(SysTicK_IRQn,0xf0);
  19. NVIC_SetPriority(Software_IRQn,0xf0);
  20. NVIC_EnableIRQ(SysTicK_IRQn);
  21. NVIC_EnableIRQ(Software_IRQn);
  22. SysTick->CTLR=0;
  23. SysTick->SR=0;
  24. SysTick->CNT=0;
  25. SysTick->CMP=ticks-1;
  26. SysTick->CTLR=0xF;
  27. return 0;
  28. }
  29. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  30. #define RT_HEAP_SIZE (4096)
  31. static uint32_t rt_heap[RT_HEAP_SIZE];
  32. RT_WEAK void *rt_heap_begin_get(void)
  33. {
  34. return rt_heap;
  35. }
  36. RT_WEAK void *rt_heap_end_get(void)
  37. {
  38. return rt_heap + RT_HEAP_SIZE;
  39. }
  40. #endif
  41. /**
  42. * This function will initial your board.
  43. */
  44. void rt_hw_board_init()
  45. {
  46. /* System Tick Configuration */
  47. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  48. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  49. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  50. #endif
  51. /* USART driver initialization is open by default */
  52. #ifdef RT_USING_SERIAL
  53. rt_hw_usart_init();
  54. #endif
  55. #ifdef RT_USING_CONSOLE
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. #endif
  58. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  59. #ifdef RT_USING_COMPONENTS_INIT
  60. rt_components_board_init();
  61. #endif
  62. }
  63. void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  64. void SysTick_Handler(void)
  65. {
  66. GET_INT_SP();
  67. /* enter interrupt */
  68. rt_interrupt_enter();
  69. SysTick->SR=0;
  70. rt_tick_increase();
  71. /* leave interrupt */
  72. rt_interrupt_leave();
  73. FREE_INT_SP();
  74. }