1 /*------------------------------------------------------------------------------
2 * Copyright (c) 2020 Arm Limited (or its affiliates). All
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * 1.Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2.Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3.Neither the name of Arm nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without
16 * specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *------------------------------------------------------------------------------
31 * Purpose: Main module
32 *----------------------------------------------------------------------------*/
39 static void SystemClock_Config(void);
40 static void Error_Handler(void);
46 // Hardware Abstraction Layer (HAL) initialization
49 // System initialization
51 SystemCoreClockUpdate();
53 // Initialize kernel, create threads and start kernel
54 (void)osKernelInitialize();
55 osThreadNew(cmsis_dv, NULL, NULL); // Create validation main thread
56 (void)osKernelStart();
62 #ifdef RTE_CMSIS_RTOS2_RTX5
64 * Override default HAL_GetTick function
66 uint32_t HAL_GetTick (void) {
67 static uint32_t ticks = 0U;
70 if (osKernelGetState () == osKernelRunning) {
71 ret = (uint32_t)osKernelGetTickCount ();
73 /* If Kernel is not running wait approximately 1 ms then increment
74 and return auxiliary tick counter value */
75 for (i = (SystemCoreClock >> 14U); i > 0U; i--) {
76 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
77 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
89 * @brief System Clock Configuration
90 * The system Clock is configured as follow :
91 * System Clock source = PLL (HSE)
92 * SYSCLK(Hz) = 168000000
93 * HCLK(Hz) = 168000000
97 * HSE Frequency(Hz) = 8000000
103 * Main regulator output voltage = Scale1 mode
104 * Flash Latency(WS) = 5
108 static void SystemClock_Config(void)
110 RCC_ClkInitTypeDef RCC_ClkInitStruct;
111 RCC_OscInitTypeDef RCC_OscInitStruct;
113 /* Enable Power Control clock */
114 __HAL_RCC_PWR_CLK_ENABLE();
116 /* The voltage scaling allows optimizing the power consumption when the device is
117 clocked below the maximum system frequency, to update the voltage scaling value
118 regarding system frequency refer to product datasheet. */
119 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
121 /* Enable HSE Oscillator and activate PLL with HSE as source */
122 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
123 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
124 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
125 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
126 RCC_OscInitStruct.PLL.PLLM = 25U;
127 RCC_OscInitStruct.PLL.PLLN = 336U;
128 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
129 RCC_OscInitStruct.PLL.PLLQ = 7U;
130 if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
132 /* Initialization Error */
136 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
138 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
139 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
140 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
141 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
142 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
143 if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
145 /* Initialization Error */
149 /* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported */
150 if (HAL_GetREVID() == 0x1001)
152 /* Enable the Flash prefetch */
153 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
158 * @brief This function is executed in case of error occurrence.
162 static void Error_Handler(void)
164 /* User may add here some code to deal with this error */
170 #ifdef USE_FULL_ASSERT
173 * @brief Reports the name of the source file and the source line number
174 * where the assert_param error has occurred.
175 * @param file: pointer to the source file name
176 * @param line: assert_param error line source number
179 void assert_failed(uint8_t* file, uint32_t line)
181 /* User can add his own implementation to report the file name and line number,
182 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
200 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/