]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL/main.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL / main.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /******************************************************************************\r
71  * This project provides two demo applications.  A simple blinky style project,\r
72  * and a more comprehensive test and demo application.  The\r
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
74  * select between the two.  The simply blinky demo is implemented and described\r
75  * in main_blinky.c.  The more comprehensive test and demo application is\r
76  * implemented and described in main_full.c.\r
77  *\r
78  * This file implements the code that is not demo specific, including the\r
79  * hardware setup and standard FreeRTOS hook functions.\r
80  */\r
81 \r
82 /* Scheduler include files. */\r
83 #include "FreeRTOS.h"\r
84 #include "task.h"\r
85 #include "semphr.h"\r
86 \r
87 /* Standard demo includes - these are needed here as the tick hook function is\r
88 defined in this file. */\r
89 #include "TimerDemo.h"\r
90 #include "QueueOverwrite.h"\r
91 #include "EventGroupsDemo.h"\r
92 #include "IntSemTest.h"\r
93 #include "QueueSet.h"\r
94 #include "TaskNotify.h"\r
95 \r
96 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
97 or 0 to run the more comprehensive test and demo application. */\r
98 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY      0\r
99 \r
100 /*-----------------------------------------------------------*/\r
101 \r
102 /*\r
103  * Configure the hardware as necessary to run this demo.\r
104  */\r
105 static void prvSetupHardware( void );\r
106 \r
107 /*\r
108  * Configure the system clock for maximum speed.\r
109  */\r
110 static void prvSystemClockConfig( void );\r
111 \r
112 /*\r
113  * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
114  * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
115  */\r
116 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
117         extern void main_blinky( void );\r
118 #else\r
119         extern void main_full( void );\r
120 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
121 \r
122 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
123 within this file. */\r
124 void vApplicationMallocFailedHook( void );\r
125 void vApplicationIdleHook( void );\r
126 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
127 void vApplicationTickHook( void );\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 int main( void )\r
132 {\r
133         /* Configure the hardware ready to run the demo. */\r
134         prvSetupHardware();\r
135 \r
136         /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
137         of this file. */\r
138         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
139         {\r
140                 main_blinky();\r
141         }\r
142         #else\r
143         {\r
144                 main_full();\r
145         }\r
146         #endif\r
147 \r
148         return 0;\r
149 }\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 static void prvSetupHardware( void )\r
153 {\r
154 GPIO_InitTypeDef  GPIO_InitStruct;\r
155 \r
156         /* Configure Flash prefetch and Instruction cache through ART accelerator. */\r
157         #if( ART_ACCLERATOR_ENABLE != 0 )\r
158         {\r
159                 __HAL_FLASH_ART_ENABLE();\r
160         }\r
161         #endif /* ART_ACCLERATOR_ENABLE */\r
162 \r
163         /* Set Interrupt Group Priority */\r
164         HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );\r
165 \r
166         /* Init the low level hardware. */\r
167         HAL_MspInit();\r
168 \r
169         /* Configure the System clock to have a frequency of 200 MHz */\r
170         prvSystemClockConfig();\r
171 \r
172         /* Enable GPIOB  Clock (to be able to program the configuration\r
173         registers) and configure for LED output. */\r
174         __GPIOG_CLK_ENABLE();\r
175 \r
176         GPIO_InitStruct.Pin = GPIO_PIN_6;\r
177         GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\r
178         GPIO_InitStruct.Pull = GPIO_PULLUP;\r
179         GPIO_InitStruct.Speed = GPIO_SPEED_FAST;\r
180         HAL_GPIO_Init( GPIOG, &GPIO_InitStruct );\r
181 \r
182         /* MCO2 : Pin PC9 */\r
183         HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void prvSystemClockConfig( void )\r
188 {\r
189         /* The system Clock is configured as follow :\r
190                 System Clock source            = PLL (HSE)\r
191                 SYSCLK(Hz)                     = 200000000\r
192                 HCLK(Hz)                       = 200000000\r
193                 AHB Prescaler                  = 1\r
194                 APB1 Prescaler                 = 4\r
195                 APB2 Prescaler                 = 2\r
196                 HSE Frequency(Hz)              = 25000000\r
197                 PLL_M                          = 25\r
198                 PLL_N                          = 400\r
199                 PLL_P                          = 2\r
200                 PLL_Q                          = 7\r
201                 VDD(V)                         = 3.3\r
202                 Main regulator output voltage  = Scale1 mode\r
203                 Flash Latency(WS)              = 7 */\r
204         RCC_ClkInitTypeDef RCC_ClkInitStruct;\r
205         RCC_OscInitTypeDef RCC_OscInitStruct;\r
206 \r
207         /* Enable HSE Oscillator and activate PLL with HSE as source */\r
208         RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\r
209         RCC_OscInitStruct.HSEState = RCC_HSE_ON;\r
210         RCC_OscInitStruct.HSIState = RCC_HSI_OFF;\r
211         RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\r
212         RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\r
213         RCC_OscInitStruct.PLL.PLLM = 25;\r
214         RCC_OscInitStruct.PLL.PLLN = 400;\r
215         RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\r
216         RCC_OscInitStruct.PLL.PLLQ = 7;\r
217         HAL_RCC_OscConfig(&RCC_OscInitStruct);\r
218 \r
219         /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2\r
220         clocks dividers */\r
221         RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);\r
222         RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\r
223         RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\r
224         RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;\r
225         RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;\r
226         configASSERT( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) == HAL_OK );\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 void vApplicationMallocFailedHook( void )\r
231 {\r
232         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
233         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
234         internally by FreeRTOS API functions that create tasks, queues, software\r
235         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
236         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
237 \r
238         /* Force an assert. */\r
239         configASSERT( ( volatile void * ) NULL );\r
240 }\r
241 /*-----------------------------------------------------------*/\r
242 \r
243 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
244 {\r
245         ( void ) pcTaskName;\r
246         ( void ) pxTask;\r
247 \r
248         /* Run time stack overflow checking is performed if\r
249         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
250         function is called if a stack overflow is detected. */\r
251 \r
252         /* Force an assert. */\r
253         configASSERT( ( volatile void * ) NULL );\r
254 }\r
255 /*-----------------------------------------------------------*/\r
256 \r
257 void vApplicationIdleHook( void )\r
258 {\r
259 volatile size_t xFreeHeapSpace;\r
260 \r
261         /* This is just a trivial example of an idle hook.  It is called on each\r
262         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
263         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
264         memory management section on the http://www.FreeRTOS.org web site for memory\r
265         management options.  If there is a lot of heap memory free then the\r
266         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
267         RAM. */\r
268         xFreeHeapSpace = xPortGetFreeHeapSize();\r
269 \r
270         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
271         ( void ) xFreeHeapSpace;\r
272 }\r
273 /*-----------------------------------------------------------*/\r
274 \r
275 void vAssertCalled( uint32_t ulLine, const char *pcFile )\r
276 {\r
277 volatile unsigned long ul = 0;\r
278 \r
279         ( void ) pcFile;\r
280         ( void ) ulLine;\r
281 \r
282         taskENTER_CRITICAL();\r
283         {\r
284                 /* Set ul to a non-zero value using the debugger to step out of this\r
285                 function. */\r
286                 while( ul == 0 )\r
287                 {\r
288                         __NOP();\r
289                 }\r
290         }\r
291         taskEXIT_CRITICAL();\r
292 }\r
293 /*-----------------------------------------------------------*/\r
294 \r
295 void vApplicationTickHook( void )\r
296 {\r
297         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
298         {\r
299                 /* The full demo includes a software timer demo/test that requires\r
300                 prodding periodically from the tick interrupt. */\r
301                 vTimerPeriodicISRTests();\r
302 \r
303                 /* Call the periodic queue overwrite from ISR demo. */\r
304                 vQueueOverwritePeriodicISRDemo();\r
305 \r
306                 /* Call the periodic event group from ISR demo. */\r
307                 vPeriodicEventGroupsProcessing();\r
308 \r
309                 /* Call the code that uses a mutex from an ISR. */\r
310                 vInterruptSemaphorePeriodicTest();\r
311 \r
312                 /* Use a queue set from an ISR. */\r
313                 vQueueSetAccessQueueSetFromISR();\r
314 \r
315                 /* Use task notifications from an ISR. */\r
316                 xNotifyTaskFromISR();\r
317         }\r
318         #endif\r
319 }\r
320 /*-----------------------------------------------------------*/\r
321 \r
322 \r
323 \r