1 /*------------------------------------------------------------------------------
2 * Copyright (c) 2022 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"
44 // Private function prototypes
45 static void Error_Handler(void);
46 static void SystemClock_Config(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
99 static void SystemClock_Config(void)
101 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
102 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
104 /** Configure the main internal regulator output voltage
106 __HAL_RCC_PWR_CLK_ENABLE();
107 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
109 /** Initializes the RCC Oscillators according to the specified parameters
110 * in the RCC_OscInitTypeDef structure.
112 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
113 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
114 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
115 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
116 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
117 RCC_OscInitStruct.PLL.PLLM = 10;
118 RCC_OscInitStruct.PLL.PLLN = 210;
119 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
120 RCC_OscInitStruct.PLL.PLLQ = 7;
121 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
126 /** Initializes the CPU, AHB and APB buses clocks
128 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
129 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
130 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
131 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
132 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
133 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
135 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
142 * @brief This function is executed in case of error occurrence.
146 static __NO_RETURN void Error_Handler(void)
148 /* User may add here some code to deal with this error */
154 #ifdef USE_FULL_ASSERT
157 * @brief Reports the name of the source file and the source line number
158 * where the assert_param error has occurred.
159 * @param file: pointer to the source file name
160 * @param line: assert_param error line source number
163 void assert_failed(uint8_t* file, uint32_t line)
165 /* User can add his own implementation to report the file name and line number,
166 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
173 #endif /* USE_FULL_ASSERT */