board.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-02 hqfang first version
  9. *
  10. */
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "cpuport.h"
  15. #ifdef RT_USING_SERIAL
  16. #include <drv_usart.h>
  17. #endif
  18. /** _end symbol defined in linker script of Nuclei SDK */
  19. extern void *_end;
  20. /** _heap_end symbol defined in linker script of Nuclei SDK */
  21. extern void *_heap_end;
  22. #define HEAP_BEGIN &_end
  23. #define HEAP_END &_heap_end
  24. /*
  25. * - Implemented and defined in Nuclei SDK system_<Device>.c file
  26. * - Required macro NUCLEI_BANNER set to 0
  27. */
  28. extern void _init(void);
  29. /*
  30. * - Check MCU pin assignment here https://doc.nucleisys.com/nuclei_board_labs/hw/hw.html
  31. * - If you changed menuconfig to use different peripherals such as SPI, ADC, GPIO,
  32. * HWTIMER, I2C, PWM, UART, WDT, RTC, please add or change related pinmux configuration
  33. * code in functions(rt_hw_*_drvinit) below
  34. */
  35. void rt_hw_spi_drvinit(void)
  36. {
  37. }
  38. void rt_hw_adc_drvinit(void)
  39. {
  40. }
  41. void rt_hw_gpio_drvinit(void)
  42. {
  43. // Clock on all the GPIOs and AF
  44. rcu_periph_clock_enable(RCU_GPIOA);
  45. rcu_periph_clock_enable(RCU_GPIOB);
  46. rcu_periph_clock_enable(RCU_GPIOC);
  47. rcu_periph_clock_enable(RCU_GPIOD);
  48. rcu_periph_clock_enable(RCU_GPIOE);
  49. rcu_periph_clock_enable(RCU_AF);
  50. }
  51. void rt_hw_hwtimer_drvinit(void)
  52. {
  53. }
  54. void rt_hw_i2c_drvinit(void)
  55. {
  56. }
  57. void rt_hw_pwm_drvinit(void)
  58. {
  59. }
  60. void rt_hw_rtc_drvinit(void)
  61. {
  62. }
  63. void rt_hw_uart_drvinit(void)
  64. {
  65. /* Notice: Debug UART4 GPIO pins are already initialized in nuclei_sdk */
  66. }
  67. void rt_hw_wdt_drvinit(void)
  68. {
  69. }
  70. void rt_hw_drivers_init(void)
  71. {
  72. #ifdef RT_USING_PIN
  73. rt_hw_gpio_drvinit();
  74. #endif
  75. #ifdef BSP_USING_UART
  76. rt_hw_uart_drvinit();
  77. #endif
  78. #ifdef BSP_USING_SPI
  79. rt_hw_spi_drvinit();
  80. #endif
  81. #ifdef BSP_USING_I2C
  82. rt_hw_i2c_drvinit();
  83. #endif
  84. #ifdef BSP_USING_ADC
  85. rt_hw_adc_drvinit();
  86. #endif
  87. #ifdef BSP_USING_WDT
  88. rt_hw_wdt_drvinit();
  89. #endif
  90. #ifdef BSP_USING_RTC
  91. rt_hw_rtc_drvinit();
  92. #endif
  93. #ifdef BSP_USING_HWTIMER
  94. rt_hw_hwtimer_drvinit();
  95. #endif
  96. #ifdef BSP_USING_PWM
  97. rt_hw_pwm_drvinit();
  98. #endif
  99. }
  100. /**
  101. * @brief Setup hardware board for rt-thread
  102. *
  103. */
  104. void rt_hw_board_init(void)
  105. {
  106. /* OS Tick Configuration */
  107. rt_hw_ticksetup();
  108. #ifdef RT_USING_HEAP
  109. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  110. #endif
  111. _init(); // __libc_init_array is not used in RT-Thread
  112. /* Board hardware drivers initialization */
  113. rt_hw_drivers_init();
  114. /* USART driver initialization is open by default */
  115. #ifdef RT_USING_SERIAL
  116. rt_hw_usart_init();
  117. #endif
  118. /* Set the shell console output device */
  119. #ifdef RT_USING_CONSOLE
  120. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  121. #endif
  122. /* Board underlying hardware initialization */
  123. #ifdef RT_USING_COMPONENTS_INIT
  124. rt_components_board_init();
  125. #endif
  126. }
  127. /******************** end of file *******************/