board.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "drv_gpio.h"
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. extern uint32_t SystemCoreClock;
  17. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  18. {
  19. NVIC_SetPriority(SysTicK_IRQn, 0xf0);
  20. NVIC_SetPriority(Software_IRQn, 0xf0);
  21. NVIC_EnableIRQ(SysTicK_IRQn);
  22. NVIC_EnableIRQ(Software_IRQn);
  23. SysTick->CTLR = 0;
  24. SysTick->SR = 0;
  25. SysTick->CNT = 0;
  26. SysTick->CMP = ticks - 1;
  27. SysTick->CTLR = 0xF;
  28. return 0;
  29. }
  30. /**
  31. * This function will initial your board.
  32. */
  33. void rt_hw_board_init()
  34. {
  35. /* System Tick Configuration */
  36. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  37. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  38. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  39. #endif
  40. /* USART driver initialization is open by default */
  41. #ifdef RT_USING_SERIAL
  42. rt_hw_usart_init();
  43. #endif
  44. #ifdef RT_USING_CONSOLE
  45. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  46. #endif
  47. #ifdef RT_USING_PIN
  48. /* pin must initialized before i2c */
  49. rt_hw_pin_init();
  50. #endif
  51. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  52. #ifdef RT_USING_COMPONENTS_INIT
  53. rt_components_board_init();
  54. #endif
  55. }
  56. void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  57. void SysTick_Handler(void)
  58. {
  59. GET_INT_SP();
  60. /* enter interrupt */
  61. rt_interrupt_enter();
  62. SysTick->SR = 0;
  63. rt_tick_increase();
  64. /* leave interrupt */
  65. rt_interrupt_leave();
  66. FREE_INT_SP();
  67. }