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