2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
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
78 * This file implements the code that is not demo specific, including the
\r
79 * hardware setup and standard FreeRTOS hook functions.
\r
82 /* Scheduler include files. */
\r
83 #include "FreeRTOS.h"
\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
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
100 /*-----------------------------------------------------------*/
\r
103 * Configure the hardware as necessary to run this demo.
\r
105 static void prvSetupHardware( void );
\r
108 * Configure the system clock for maximum speed.
\r
110 static void prvSystemClockConfig( void );
\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
116 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
117 extern void main_blinky( void );
\r
119 extern void main_full( void );
\r
120 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\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
129 /*-----------------------------------------------------------*/
\r
133 /* Configure the hardware ready to run the demo. */
\r
134 prvSetupHardware();
\r
136 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
138 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
150 /*-----------------------------------------------------------*/
\r
152 static void prvSetupHardware( void )
\r
154 GPIO_InitTypeDef GPIO_InitStruct;
\r
156 /* Configure Flash prefetch and Instruction cache through ART accelerator. */
\r
157 #if( ART_ACCLERATOR_ENABLE != 0 )
\r
159 __HAL_FLASH_ART_ENABLE();
\r
161 #endif /* ART_ACCLERATOR_ENABLE */
\r
163 /* Set Interrupt Group Priority */
\r
164 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );
\r
166 /* Init the low level hardware. */
\r
169 /* Configure the System clock to have a frequency of 200 MHz */
\r
170 prvSystemClockConfig();
\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
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
183 /* MCO2 : Pin PC9 */
\r
184 HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );
\r
186 /*-----------------------------------------------------------*/
\r
188 static void prvSystemClockConfig( void )
\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
197 HSE Frequency(Hz) = 25000000
\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
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
220 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
\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
229 /*-----------------------------------------------------------*/
\r
231 void vApplicationMallocFailedHook( void )
\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
239 /* Force an assert. */
\r
240 configASSERT( ( volatile void * ) NULL );
\r
242 /*-----------------------------------------------------------*/
\r
244 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
246 ( void ) pcTaskName;
\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
253 /* Force an assert. */
\r
254 configASSERT( ( volatile void * ) NULL );
\r
256 /*-----------------------------------------------------------*/
\r
258 void vApplicationIdleHook( void )
\r
260 volatile size_t xFreeHeapSpace;
\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
269 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
271 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
272 ( void ) xFreeHeapSpace;
\r
274 /*-----------------------------------------------------------*/
\r
276 void vAssertCalled( uint32_t ulLine, const char *pcFile )
\r
278 volatile unsigned long ul = 0;
\r
283 taskENTER_CRITICAL();
\r
285 /* Set ul to a non-zero value using the debugger to step out of this
\r
292 taskEXIT_CRITICAL();
\r
294 /*-----------------------------------------------------------*/
\r
296 void vApplicationTickHook( void )
\r
298 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\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
304 /* Call the periodic queue overwrite from ISR demo. */
\r
305 vQueueOverwritePeriodicISRDemo();
\r
307 /* Call the periodic event group from ISR demo. */
\r
308 vPeriodicEventGroupsProcessing();
\r
310 /* Call the code that uses a mutex from an ISR. */
\r
311 vInterruptSemaphorePeriodicTest();
\r
313 /* Use a queue set from an ISR. */
\r
314 vQueueSetAccessQueueSetFromISR();
\r
316 /* Use task notifications from an ISR. */
\r
317 xNotifyTaskFromISR();
\r
321 /*-----------------------------------------------------------*/
\r