board.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-28 flybreak first version
  9. * 2023-01-22 rose_man add RT_USING_SMP
  10. * 2025-08-04 hydevcode first version
  11. */
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <stdio.h>
  15. #include "board.h"
  16. #include <pico/bootrom.h>
  17. #include <pico/stdlib.h>
  18. #include <hardware/clocks.h>
  19. #include <hardware/structs/systick.h>
  20. #include <drv_uart.h>
  21. #define PLL_SYS_KHZ (150 * 1000)
  22. void SysTick_Handler(void)
  23. {
  24. rt_interrupt_enter();
  25. rt_tick_increase();
  26. rt_interrupt_leave();
  27. }
  28. uint32_t systick_config(uint32_t ticks)
  29. {
  30. if ((ticks - 1UL) > M33_SYST_RVR_RELOAD_BITS)
  31. {
  32. return (1UL); /* Reload value impossible */
  33. }
  34. systick_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
  35. systick_hw->csr = M33_SYST_CSR_CLKSOURCE_BITS |
  36. M33_SYST_CSR_TICKINT_BITS |
  37. M33_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
  38. }
  39. #include "pico/runtime.h"
  40. void rt_hw_board_init()
  41. {
  42. #ifdef RT_USING_HEAP
  43. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  44. #endif
  45. set_sys_clock_khz(PLL_SYS_KHZ, true);
  46. alarm_pool_init_default();
  47. systick_config(clock_get_hz(clk_sys) / RT_TICK_PER_SECOND);
  48. #ifdef RT_USING_COMPONENTS_INIT
  49. rt_components_board_init();
  50. #endif
  51. #ifdef RT_USING_SERIAL
  52. stdio_init_all();
  53. rt_hw_uart_init();
  54. #endif
  55. #ifdef RT_USING_CONSOLE
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. #endif
  58. }