]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil/main.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_STM32F7_STM32756G-EVAL_IAR_Keil / 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         __HAL_RCC_GPIOF_CLK_ENABLE();\r
176 \r
177         GPIO_InitStruct.Pin = GPIO_PIN_10;\r
178         GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\r
179         GPIO_InitStruct.Pull = GPIO_PULLUP;\r
180         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;\r
181         HAL_GPIO_Init( GPIOF, &GPIO_InitStruct );\r
182 \r
183         /* MCO2 : Pin PC9 */\r
184         HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvSystemClockConfig( void )\r
189 {\r
190         /* The system Clock is configured as follow :\r
191                 System Clock source            = PLL (HSE)\r
192                 SYSCLK(Hz)                     = 200000000\r
193                 HCLK(Hz)                       = 200000000\r
194                 AHB Prescaler                  = 1\r
195                 APB1 Prescaler                 = 4\r
196                 APB2 Prescaler                 = 2\r
197                 HSE Frequency(Hz)              = 25000000\r
198                 PLL_M                          = 25\r
199                 PLL_N                          = 400\r
200                 PLL_P                          = 2\r
201                 PLL_Q                          = 7\r
202                 VDD(V)                         = 3.3\r
203                 Main regulator output voltage  = Scale1 mode\r
204                 Flash Latency(WS)              = 7 */\r
205         RCC_ClkInitTypeDef RCC_ClkInitStruct;\r
206         RCC_OscInitTypeDef RCC_OscInitStruct;\r
207 \r
208         /* Enable HSE Oscillator and activate PLL with HSE as source */\r
209         RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;\r
210         RCC_OscInitStruct.HSEState = RCC_HSE_ON;\r
211         RCC_OscInitStruct.HSIState = RCC_HSI_OFF;\r
212         RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\r
213         RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\r
214         RCC_OscInitStruct.PLL.PLLM = 25;\r
215         RCC_OscInitStruct.PLL.PLLN = 400;\r
216         RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\r
217         RCC_OscInitStruct.PLL.PLLQ = 7;\r
218         HAL_RCC_OscConfig(&RCC_OscInitStruct);\r
219 \r
220         /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2\r
221         clocks dividers */\r
222         RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);\r
223         RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\r
224         RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\r
225         RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;\r
226         RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;\r
227         configASSERT( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) == HAL_OK );\r
228 }\r
229 /*-----------------------------------------------------------*/\r
230 \r
231 void vApplicationMallocFailedHook( void )\r
232 {\r
233         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
234         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
235         internally by FreeRTOS API functions that create tasks, queues, software\r
236         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
237         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
238 \r
239         /* Force an assert. */\r
240         configASSERT( ( volatile void * ) NULL );\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
245 {\r
246         ( void ) pcTaskName;\r
247         ( void ) pxTask;\r
248 \r
249         /* Run time stack overflow checking is performed if\r
250         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
251         function is called if a stack overflow is detected. */\r
252 \r
253         /* Force an assert. */\r
254         configASSERT( ( volatile void * ) NULL );\r
255 }\r
256 /*-----------------------------------------------------------*/\r
257 \r
258 void vApplicationIdleHook( void )\r
259 {\r
260 volatile size_t xFreeHeapSpace;\r
261 \r
262         /* This is just a trivial example of an idle hook.  It is called on each\r
263         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
264         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
265         memory management section on the http://www.FreeRTOS.org web site for memory\r
266         management options.  If there is a lot of heap memory free then the\r
267         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
268         RAM. */\r
269         xFreeHeapSpace = xPortGetFreeHeapSize();\r
270 \r
271         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
272         ( void ) xFreeHeapSpace;\r
273 }\r
274 /*-----------------------------------------------------------*/\r
275 \r
276 void vAssertCalled( uint32_t ulLine, const char *pcFile )\r
277 {\r
278 volatile unsigned long ul = 0;\r
279 \r
280         ( void ) pcFile;\r
281         ( void ) ulLine;\r
282 \r
283         taskENTER_CRITICAL();\r
284         {\r
285                 /* Set ul to a non-zero value using the debugger to step out of this\r
286                 function. */\r
287                 while( ul == 0 )\r
288                 {\r
289                         __NOP();\r
290                 }\r
291         }\r
292         taskEXIT_CRITICAL();\r
293 }\r
294 /*-----------------------------------------------------------*/\r
295 \r
296 void vApplicationTickHook( void )\r
297 {\r
298         #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )\r
299         {\r
300                 /* The full demo includes a software timer demo/test that requires\r
301                 prodding periodically from the tick interrupt. */\r
302                 vTimerPeriodicISRTests();\r
303 \r
304                 /* Call the periodic queue overwrite from ISR demo. */\r
305                 vQueueOverwritePeriodicISRDemo();\r
306 \r
307                 /* Call the periodic event group from ISR demo. */\r
308                 vPeriodicEventGroupsProcessing();\r
309 \r
310                 /* Call the code that uses a mutex from an ISR. */\r
311                 vInterruptSemaphorePeriodicTest();\r
312 \r
313                 /* Use a queue set from an ISR. */\r
314                 vQueueSetAccessQueueSetFromISR();\r
315 \r
316                 /* Use task notifications from an ISR. */\r
317                 xNotifyTaskFromISR();\r
318         }\r
319         #endif\r
320 }\r
321 /*-----------------------------------------------------------*/\r
322 \r
323 \r
324 \r