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 #include "SPI_Server_Config.h"
40 #include "SPI_Server.h"
42 #include "stm32f4xx_hal.h"
45 static void SystemClock_Config(void);
46 static void Error_Handler(void);
52 // Hardware Abstraction Layer (HAL) initialization
55 // System initialization
57 SystemCoreClockUpdate();
59 // Initialize kernel, create threads and start kernel
60 (void)osKernelInitialize();
61 (void)SPI_Server_Start();
62 (void)osKernelStart();
68 #ifdef RTE_CMSIS_RTOS2_RTX5
70 * Override default HAL_GetTick function
72 uint32_t HAL_GetTick (void) {
73 static uint32_t ticks = 0U;
76 if (osKernelGetState () == osKernelRunning) {
77 ret = (uint32_t)osKernelGetTickCount ();
79 /* If Kernel is not running wait approximately 1 ms then increment
80 and return auxiliary tick counter value */
81 for (i = (SystemCoreClock >> 14U); i > 0U; i--) {
82 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
83 __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();
95 * @brief System Clock Configuration
96 * The system Clock is configured as follow :
97 * System Clock source = PLL (HSE)
98 * SYSCLK(Hz) = 168000000
99 * HCLK(Hz) = 168000000
103 * HSE Frequency(Hz) = 8000000
109 * Main regulator output voltage = Scale1 mode
110 * Flash Latency(WS) = 5
114 static void SystemClock_Config(void)
116 RCC_ClkInitTypeDef RCC_ClkInitStruct;
117 RCC_OscInitTypeDef RCC_OscInitStruct;
119 /* Enable Power Control clock */
120 __HAL_RCC_PWR_CLK_ENABLE();
122 /* The voltage scaling allows optimizing the power consumption when the device is
123 clocked below the maximum system frequency, to update the voltage scaling value
124 regarding system frequency refer to product datasheet. */
125 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
127 /* Enable HSE Oscillator and activate PLL with HSE as source */
128 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
129 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
130 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
131 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
132 RCC_OscInitStruct.PLL.PLLM = 25U;
133 RCC_OscInitStruct.PLL.PLLN = 336U;
134 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
135 RCC_OscInitStruct.PLL.PLLQ = 7U;
136 if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
138 /* Initialization Error */
142 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
144 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
145 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
146 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
147 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
148 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
149 if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
151 /* Initialization Error */
155 /* STM32F405x/407x/415x/417x Revision Z devices: prefetch is supported */
156 if (HAL_GetREVID() == 0x1001)
158 /* Enable the Flash prefetch */
159 __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
164 * @brief This function is executed in case of error occurrence.
168 static __NO_RETURN void Error_Handler(void)
170 /* User may add here some code to deal with this error */
176 #ifdef USE_FULL_ASSERT
179 * @brief Reports the name of the source file and the source line number
180 * where the assert_param error has occurred.
181 * @param file: pointer to the source file name
182 * @param line: assert_param error line source number
185 void assert_failed(uint8_t* file, uint32_t line)
187 /* User can add his own implementation to report the file name and line number,
188 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
206 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/