board.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2006-2021, 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. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdio.h>
  13. #include "board.h"
  14. #include "hardware/structs/systick.h"
  15. #define PLL_SYS_KHZ (133 * 1000)
  16. void isr_systick(void)
  17. {
  18. /* enter interrupt */
  19. rt_interrupt_enter();
  20. rt_tick_increase();
  21. /* leave interrupt */
  22. rt_interrupt_leave();
  23. }
  24. uint32_t systick_config(uint32_t ticks)
  25. {
  26. if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS)
  27. {
  28. return (1UL); /* Reload value impossible */
  29. }
  30. mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
  31. mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS |
  32. M0PLUS_SYST_CSR_TICKINT_BITS |
  33. M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
  34. return (0UL); /* Function successful */
  35. }
  36. void rt_hw_board_init()
  37. {
  38. set_sys_clock_khz(PLL_SYS_KHZ, true);
  39. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  40. alarm_pool_init_default();
  41. // Start and end points of the constructor list,
  42. // defined by the linker script.
  43. extern void (*__init_array_start)();
  44. extern void (*__init_array_end)();
  45. // Call each function in the list.
  46. // We have to take the address of the symbols, as __init_array_start *is*
  47. // the first function pointer, not the address of it.
  48. for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p) {
  49. (*p)();
  50. }
  51. /* Configure the SysTick */
  52. systick_config(frequency_count_khz(CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY) * 1000 / RT_TICK_PER_SECOND);
  53. stdio_init_all();
  54. rt_hw_uart_init();
  55. #ifdef RT_USING_CONSOLE
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. #endif
  58. }