123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2018-11-7 SummerGift first version
- */
- #include <drv_common.h>
- #include <bsp_api.h>
- #include "board.h"
- #ifdef RT_USING_PIN
- #include <drv_gpio.h>
- #endif
- #ifdef RT_USING_SERIAL
- #ifdef RT_USING_SERIAL_V2
- #include <drv_usart_v2.h>
- #else
- #include <drv_usart.h>
- #endif
- #endif
- #ifdef RT_USING_FINSH
- #include <finsh.h>
- static void reboot(uint8_t argc, char **argv)
- {
- NVIC_SystemReset();
- }
- MSH_CMD_EXPORT(reboot, Reboot System);
- #endif /* RT_USING_FINSH */
- /* SysTick configuration */
- void rt_hw_systick_init(void)
- {
- SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
- NVIC_SetPriority(SysTick_IRQn, 0xFF);
- }
- /**
- * This is the timer interrupt service routine.
- *
- */
- void SysTick_Handler(void)
- {
- /* enter interrupt */
- rt_interrupt_enter();
- rt_tick_increase();
- /* leave interrupt */
- rt_interrupt_leave();
- }
- /**
- * @brief This function is executed in case of error occurrence.
- * @param None
- * @retval None
- */
- void _Error_Handler(char *s, int num)
- {
- /* USER CODE BEGIN Error_Handler */
- /* User can add his own implementation to report the HAL error return state */
- while (1)
- {
- }
- /* USER CODE END Error_Handler */
- }
- /**
- * This function will delay for some us.
- *
- * @param us the delay time of us
- */
- void rt_hw_us_delay(rt_uint32_t us)
- {
- rt_uint32_t ticks;
- rt_uint32_t told, tnow, tcnt = 0;
- rt_uint32_t reload = SysTick->LOAD;
- ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
- told = SysTick->VAL;
- while (1)
- {
- tnow = SysTick->VAL;
- if (tnow != told)
- {
- if (tnow < told)
- {
- tcnt += told - tnow;
- }
- else
- {
- tcnt += reload - tnow + told;
- }
- told = tnow;
- if (tcnt >= ticks)
- {
- break;
- }
- }
- }
- }
- /**
- * This function will initial STM32 board.
- */
- RT_WEAK void rt_hw_board_init()
- {
- rt_hw_systick_init();
- /* Heap initialization */
- #if defined(RT_USING_HEAP)
- rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
- #endif
- /* Pin driver initialization is open by default */
- #ifdef RT_USING_PIN
- rt_hw_pin_init();
- #endif
- /* USART driver initialization is open by default */
- #ifdef RT_USING_SERIAL
- rt_hw_usart_init();
- #endif
- /* Set the shell console output device */
- #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
- rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
- #endif
- /* Board underlying hardware initialization */
- #ifdef RT_USING_COMPONENTS_INIT
- rt_components_board_init();
- #endif
- }
- FSP_CPP_HEADER
- void R_BSP_WarmStart(bsp_warm_start_event_t event);
- FSP_CPP_FOOTER
- /*******************************************************************************************************************//**
- * This function is called at various points during the startup process. This implementation uses the event that is
- * called right before main() to set up the pins.
- *
- * @param[in] event Where at in the start up process the code is currently at
- **********************************************************************************************************************/
- void R_BSP_WarmStart (bsp_warm_start_event_t event)
- {
- if (BSP_WARM_START_RESET == event)
- {
- #if BSP_FEATURE_FLASH_LP_VERSION != 0
- /* Enable reading from data flash. */
- R_FACI_LP->DFLCTL = 1U;
- /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
- * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
- #endif
- }
- if (BSP_WARM_START_POST_C == event)
- {
- /* C runtime environment and system clocks are setup. */
- /* Configure pins. */
- R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
- }
- }
- #if BSP_TZ_SECURE_BUILD
- BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
- /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
- BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
- {
- }
- #endif
|