board.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  30. * This function will initial your board.
  31. */
  32. void rt_hw_board_init()
  33. {
  34. /* System Tick Configuration */
  35. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  36. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  37. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  38. #endif
  39. /* USART driver initialization is open by default */
  40. #ifdef RT_USING_SERIAL
  41. rt_hw_usart_init();
  42. #endif
  43. #ifdef RT_USING_CONSOLE
  44. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  45. #endif
  46. #ifdef RT_USING_PIN
  47. /* pin must initialized before i2c */
  48. rt_hw_pin_init();
  49. #endif
  50. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  51. #ifdef RT_USING_COMPONENTS_INIT
  52. rt_components_board_init();
  53. #endif
  54. }
  55. void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  56. void SysTick_Handler(void)
  57. {
  58. GET_INT_SP();
  59. /* enter interrupt */
  60. rt_interrupt_enter();
  61. SysTick->SR = 0;
  62. rt_tick_increase();
  63. /* leave interrupt */
  64. rt_interrupt_leave();
  65. FREE_INT_SP();
  66. }