11/*
2- * File : board.c
3- * This file is part of RT-Thread RTOS
4- * COPYRIGHT (C) 2009 RT-Thread Develop Team
2+ * Copyright (c) 2006-2018, RT-Thread Development Team
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
55 *
6- * The license and distribution terms for this file may be
7- * found in the file LICENSE in this distribution or at
8- * http://www.rt-thread.org/license/LICENSE
96 *
107 * Change Logs:
118 * Date Author Notes
@@ -47,6 +44,7 @@ void HAL_MspInit(void)
4744 __HAL_AFIO_REMAP_SWJ_NOJTAG ();
4845}
4946
47+
5048void SystemClock_Config (void )
5149{
5250 rt_err_t ret = RT_EOK ;
@@ -63,7 +61,19 @@ void SystemClock_Config(void)
6361 RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSE ;
6462 RCC_OscInitStruct .PLL .PLLMUL = RCC_PLL_MUL9 ;
6563 ret = HAL_RCC_OscConfig (& RCC_OscInitStruct );
66- RT_ASSERT (ret == HAL_OK );
64+ if (ret == HAL_TIMEOUT )
65+ {
66+ /* HSE timeout switch to HSI */
67+ rt_memset (& RCC_OscInitStruct , 0 , sizeof (RCC_OscInitStruct ));
68+ RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI ;
69+ RCC_OscInitStruct .HSIState = RCC_HSI_ON ;
70+ RCC_OscInitStruct .HSICalibrationValue = 16 ;
71+ RCC_OscInitStruct .PLL .PLLState = RCC_PLL_ON ;
72+ RCC_OscInitStruct .PLL .PLLSource = RCC_PLLSOURCE_HSI_DIV2 ;
73+ RCC_OscInitStruct .PLL .PLLMUL = RCC_PLL_MUL16 ;
74+ ret = HAL_RCC_OscConfig (& RCC_OscInitStruct );
75+ RT_ASSERT (ret == HAL_OK );
76+ }
6777
6878 /* Initializes the CPU, AHB and APB busses clocks */
6979 RCC_ClkInitStruct .ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
@@ -103,6 +113,39 @@ void SystemClock_Config(void)
103113#endif
104114}
105115
116+ static void m3_m4_delay_us (rt_uint32_t us )
117+ {
118+ __IO uint32_t Delay = us * (SystemCoreClock / 8U / 1000000U );
119+ do
120+ {
121+ __NOP ();
122+ }
123+ while (Delay -- );
124+ }
125+
126+ void HAL_Delay (__IO uint32_t Delay )
127+ {
128+ m3_m4_delay_us (Delay * 10 );
129+ }
130+
131+ extern __IO uint32_t uwTick ;
132+ uint32_t HAL_GetTick (void )
133+ {
134+ HAL_Delay (1 );
135+ uwTick ++ ;
136+ return uwTick ;
137+ }
138+
139+ void HAL_SuspendTick (void )
140+ {
141+ /* we should not suspend tick */
142+ }
143+
144+ void HAL_ResumeTick (void )
145+ {
146+ /* we should not resume tick */
147+ }
148+
106149/**
107150 * This is the timer interrupt service routine.
108151 *
@@ -111,6 +154,7 @@ void SysTick_Handler(void)
111154{
112155 /* enter interrupt */
113156 rt_interrupt_enter ();
157+
114158 HAL_IncTick ();
115159 rt_tick_increase ();
116160 /* leave interrupt */
0 commit comments