]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/main.c
5aa2863a82215c71ae91acdcf1e57421f2ede6ad
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / main.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
32  * select between the two.  The simply blinky demo is implemented and described\r
33  * in main_blinky.c.  The more comprehensive test and demo application is\r
34  * implemented and described in main_full.c.\r
35  *\r
36  * This file implements the code that is not demo specific, including the\r
37  * hardware setup and standard FreeRTOS hook functions.\r
38  */\r
39 \r
40 /* Scheduler include files. */\r
41 #include "FreeRTOS.h"\r
42 #include "task.h"\r
43 #include "semphr.h"\r
44 \r
45 /* Standard demo includes - these are needed here as the tick hook function is\r
46 defined in this file. */\r
47 #include "TimerDemo.h"\r
48 #include "QueueOverwrite.h"\r
49 #include "EventGroupsDemo.h"\r
50 #include "IntSemTest.h"\r
51 #include "QueueSet.h"\r
52 #include "TaskNotify.h"\r
53 \r
54 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
55 or 0 to run the more comprehensive test and demo application. */\r
56 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
57 \r
58 /*-----------------------------------------------------------*/\r
59 \r
60 /*\r
61  * Configure the hardware as necessary to run this demo.\r
62  */\r
63 static void prvSetupHardware( void );\r
64 \r
65 /*\r
66  * Configure the system clock for maximum speed.\r
67  */\r
68 static void prvSystemClockConfig( void );\r
69 \r
70 /*\r
71  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
72  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
73  */\r
74 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
75         extern void main_blinky( void );\r
76 #else\r
77         extern void main_full( void );\r
78 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
79 \r
80 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
81 within this file. */\r
82 void vApplicationMallocFailedHook( void );\r
83 void vApplicationIdleHook( void );\r
84 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
85 void vApplicationTickHook( void );\r
86 \r
87 /*-----------------------------------------------------------*/\r
88 \r
89 int main( void )\r
90 {\r
91         /* Configure the hardware ready to run the demo. */\r
92         prvSetupHardware();\r
93 \r
94         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
95         of this file. */\r
96         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
97         {\r
98                 main_blinky();\r
99         }\r
100         #else\r
101         {\r
102                 main_full();\r
103         }\r
104         #endif\r
105 \r
106         return 0;\r
107 }\r
108 /*-----------------------------------------------------------*/\r
109 \r
110 static void prvSetupHardware( void )\r
111 {\r
112 GPIO_InitTypeDef  GPIO_InitStruct;\r
113 \r
114         /* Configure Flash prefetch and Instruction cache through ART accelerator. */\r
115         #if( ART_ACCLERATOR_ENABLE != 0 )\r
116         {\r
117                 __HAL_FLASH_ART_ENABLE();\r
118         }\r
119         #endif /* ART_ACCLERATOR_ENABLE */\r
120 \r
121         /* Set Interrupt Group Priority */\r
122         HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );\r
123 \r
124         /* Init the low level hardware. */\r
125         HAL_MspInit();\r
126 \r
127         /* Configure the System clock to have a frequency of 200 MHz */\r
128         prvSystemClockConfig();\r
129 \r
130         /* Enable GPIOB  Clock (to be able to program the configuration\r
131         registers) and configure for LED output. */\r
132         __GPIOG_CLK_ENABLE();\r
133         __HAL_RCC_GPIOF_CLK_ENABLE();\r
134 \r
135         GPIO_InitStruct.Pin = GPIO_PIN_10;\r
136         GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\r
137         GPIO_InitStruct.Pull = GPIO_PULLUP;\r
138         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;\r
139         HAL_GPIO_Init( GPIOF, &GPIO_InitStruct );\r
140 \r
141         /* MCO2 : Pin PC9 */\r
142         HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 static void prvSystemClockConfig( void )\r
147 {\r
148         /* The system Clock is configured as follow :\r
149                 System Clock source            = PLL (HSE)\r
150                 SYSCLK(Hz)                     = 200000000\r
151                 HCLK(Hz)                       = 200000000\r
152                 AHB Prescaler                  = 1\r
153                 APB1 Prescaler                 = 4\r
154                 APB2 Prescaler                 = 2\r
155                 HSE Frequency(Hz)              = 25000000\r
156                 PLL_M                          = 25\r
157                 PLL_N                          = 400\r
158                 PLL_P                          = 2\r
159                 PLL_Q                          = 7\r
160                 VDD(V)                         = 3.3\r
161                 Main regulator output voltage  = Scale1 mode\r
162                 Flash Latency(WS)              = 7 */\r
163         RCC_ClkInitTypeDef RCC_ClkInitStruct;\r
164         RCC_OscInitTypeDef RCC_OscInitStruct;\r
165 \r
166         /* Enable HSE Oscillator and activate PLL with HSE as source */\r
167         RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\r
168         RCC_OscInitStruct.HSEState = RCC_HSE_ON;\r
169         RCC_OscInitStruct.HSIState = RCC_HSI_OFF;\r
170         RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\r
171         RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\r
172         RCC_OscInitStruct.PLL.PLLM = 25;\r
173         RCC_OscInitStruct.PLL.PLLN = 400;\r
174         RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\r
175         RCC_OscInitStruct.PLL.PLLQ = 7;\r
176         HAL_RCC_OscConfig(&RCC_OscInitStruct);\r
177 \r
178         /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2\r
179         clocks dividers */\r
180         RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);\r
181         RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\r
182         RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\r
183         RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;\r
184         RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;\r
185         configASSERT( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) == HAL_OK );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 void vApplicationMallocFailedHook( void )\r
190 {\r
191         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
192         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
193         internally by FreeRTOS API functions that create tasks, queues, software\r
194         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
195         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
196 \r
197         /* Force an assert. */\r
198         configASSERT( ( volatile void * ) NULL );\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
203 {\r
204         ( void ) pcTaskName;\r
205         ( void ) pxTask;\r
206 \r
207         /* Run time stack overflow checking is performed if\r
208         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
209         function is called if a stack overflow is detected. */\r
210 \r
211         /* Force an assert. */\r
212         configASSERT( ( volatile void * ) NULL );\r
213 }\r
214 /*-----------------------------------------------------------*/\r
215 \r
216 void vApplicationIdleHook( void )\r
217 {\r
218 volatile size_t xFreeHeapSpace;\r
219 \r
220         /* This is just a trivial example of an idle hook.  It is called on each\r
221         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
222         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
223         memory management section on the http://www.FreeRTOS.org web site for memory\r
224         management options.  If there is a lot of heap memory free then the\r
225         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
226         RAM. */\r
227         xFreeHeapSpace = xPortGetFreeHeapSize();\r
228 \r
229         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
230         ( void ) xFreeHeapSpace;\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 void vAssertCalled( uint32_t ulLine, const char *pcFile )\r
235 {\r
236 volatile unsigned long ul = 0;\r
237 \r
238         ( void ) pcFile;\r
239         ( void ) ulLine;\r
240 \r
241         taskENTER_CRITICAL();\r
242         {\r
243                 /* Set ul to a non-zero value using the debugger to step out of this\r
244                 function. */\r
245                 while( ul == 0 )\r
246                 {\r
247                         __NOP();\r
248                 }\r
249         }\r
250         taskEXIT_CRITICAL();\r
251 }\r
252 /*-----------------------------------------------------------*/\r
253 \r
254 void vApplicationTickHook( void )\r
255 {\r
256         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
257         {\r
258                 /* The full demo includes a software timer demo/test that requires\r
259                 prodding periodically from the tick interrupt. */\r
260                 vTimerPeriodicISRTests();\r
261 \r
262                 /* Call the periodic queue overwrite from ISR demo. */\r
263                 vQueueOverwritePeriodicISRDemo();\r
264 \r
265                 /* Call the periodic event group from ISR demo. */\r
266                 vPeriodicEventGroupsProcessing();\r
267 \r
268                 /* Call the code that uses a mutex from an ISR. */\r
269                 vInterruptSemaphorePeriodicTest();\r
270 \r
271                 /* Use a queue set from an ISR. */\r
272                 vQueueSetAccessQueueSetFromISR();\r
273 \r
274                 /* Use task notifications from an ISR. */\r
275                 xNotifyTaskFromISR();\r
276         }\r
277         #endif\r
278 }\r
279 /*-----------------------------------------------------------*/\r
280 \r
281 \r
282 \r