]> begriffs open source - cmsis-driver-validation/blob - Tools/SPI_Server/Board/STM32F429I-DISC1/main.c
Add SPI_Server and USART_Server applications for STM32F429I-DISC1 board
[cmsis-driver-validation] / Tools / SPI_Server / Board / STM32F429I-DISC1 / main.c
1 /*------------------------------------------------------------------------------
2  * Copyright (c) 2022 Arm Limited (or its affiliates). All
3  * rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
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.
17  *
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  *------------------------------------------------------------------------------
30  * Name:    main.c
31  * Purpose: Main module
32  *----------------------------------------------------------------------------*/
33
34 #include "main.h"
35
36 #include <string.h>
37 #include <stdio.h>
38
39 #include "SPI_Server_Config.h"
40 #include "SPI_Server.h"
41
42 #include "stm32f4xx_hal.h"
43
44 // Private function prototypes
45 static void Error_Handler(void);
46 static void SystemClock_Config(void);
47
48
49 // Main function
50 int32_t main (void) {
51
52   // Hardware Abstraction Layer (HAL) initialization
53   (void)HAL_Init();
54
55   // System initialization
56   SystemClock_Config();
57   SystemCoreClockUpdate();
58
59   // Initialize kernel, create threads and start kernel
60   (void)osKernelInitialize();
61   (void)SPI_Server_Start();
62   (void)osKernelStart();
63
64   for (;;) {}
65 }
66
67
68 #ifdef RTE_CMSIS_RTOS2_RTX5
69 /**
70   * Override default HAL_GetTick function
71   */
72 uint32_t HAL_GetTick (void) {
73   static uint32_t ticks = 0U;
74          uint32_t i, ret;
75
76   if (osKernelGetState () == osKernelRunning) {
77     ret = (uint32_t)osKernelGetTickCount ();
78   } else {
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();
84     }
85     ticks = ticks + 1U;
86     ret = ticks;
87   }
88
89   return ret;
90 }
91 #endif
92
93
94 /**
95   * @brief System Clock Configuration
96   * @param  None
97   * @retval None
98   */
99 static void SystemClock_Config(void)
100 {
101   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
102   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
103
104   /** Configure the main internal regulator output voltage
105   */
106   __HAL_RCC_PWR_CLK_ENABLE();
107   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
108
109   /** Initializes the RCC Oscillators according to the specified parameters
110   * in the RCC_OscInitTypeDef structure.
111   */
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)
122   {
123     Error_Handler();
124   }
125
126   /** Initializes the CPU, AHB and APB buses clocks
127   */
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;
134
135   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
136   {
137     Error_Handler();
138   }
139 }
140
141 /**
142   * @brief  This function is executed in case of error occurrence.
143   * @param  None
144   * @retval None
145   */
146 static __NO_RETURN void Error_Handler(void)
147 {
148   /* User may add here some code to deal with this error */
149   for (;;)
150   {
151   }
152 }
153
154 #ifdef  USE_FULL_ASSERT
155
156 /**
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
161   * @retval None
162   */
163 void assert_failed(uint8_t* file, uint32_t line)
164 {
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) */
167
168   /* Infinite loop */
169   while (1)
170   {
171   }
172 }
173 #endif /* USE_FULL_ASSERT */