2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
36 * This file implements the code that is not demo specific, including the
\r
37 * hardware setup and standard FreeRTOS hook functions.
\r
40 /* Scheduler include files. */
\r
41 #include "FreeRTOS.h"
\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
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
58 /*-----------------------------------------------------------*/
\r
61 * Configure the hardware as necessary to run this demo.
\r
63 static void prvSetupHardware( void );
\r
66 * Configure the system clock for maximum speed.
\r
68 static void prvSystemClockConfig( void );
\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
74 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
75 extern void main_blinky( void );
\r
77 extern void main_full( void );
\r
78 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\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
87 /*-----------------------------------------------------------*/
\r
91 /* Configure the hardware ready to run the demo. */
\r
94 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
96 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
108 /*-----------------------------------------------------------*/
\r
110 static void prvSetupHardware( void )
\r
112 GPIO_InitTypeDef GPIO_InitStruct;
\r
114 /* Configure Flash prefetch and Instruction cache through ART accelerator. */
\r
115 #if( ART_ACCLERATOR_ENABLE != 0 )
\r
117 __HAL_FLASH_ART_ENABLE();
\r
119 #endif /* ART_ACCLERATOR_ENABLE */
\r
121 /* Set Interrupt Group Priority */
\r
122 HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 );
\r
124 /* Init the low level hardware. */
\r
127 /* Configure the System clock to have a frequency of 200 MHz */
\r
128 prvSystemClockConfig();
\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
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
141 /* MCO2 : Pin PC9 */
\r
142 HAL_RCC_MCOConfig( RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1 );
\r
144 /*-----------------------------------------------------------*/
\r
146 static void prvSystemClockConfig( void )
\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
155 HSE Frequency(Hz) = 25000000
\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
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
178 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
\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
187 /*-----------------------------------------------------------*/
\r
189 void vApplicationMallocFailedHook( void )
\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
197 /* Force an assert. */
\r
198 configASSERT( ( volatile void * ) NULL );
\r
200 /*-----------------------------------------------------------*/
\r
202 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
204 ( void ) pcTaskName;
\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
211 /* Force an assert. */
\r
212 configASSERT( ( volatile void * ) NULL );
\r
214 /*-----------------------------------------------------------*/
\r
216 void vApplicationIdleHook( void )
\r
218 volatile size_t xFreeHeapSpace;
\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
227 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
229 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
230 ( void ) xFreeHeapSpace;
\r
232 /*-----------------------------------------------------------*/
\r
234 void vAssertCalled( uint32_t ulLine, const char *pcFile )
\r
236 volatile unsigned long ul = 0;
\r
241 taskENTER_CRITICAL();
\r
243 /* Set ul to a non-zero value using the debugger to step out of this
\r
250 taskEXIT_CRITICAL();
\r
252 /*-----------------------------------------------------------*/
\r
254 void vApplicationTickHook( void )
\r
256 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0 )
\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
262 /* Call the periodic queue overwrite from ISR demo. */
\r
263 vQueueOverwritePeriodicISRDemo();
\r
265 /* Call the periodic event group from ISR demo. */
\r
266 vPeriodicEventGroupsProcessing();
\r
268 /* Call the code that uses a mutex from an ISR. */
\r
269 vInterruptSemaphorePeriodicTest();
\r
271 /* Use a queue set from an ISR. */
\r
272 vQueueSetAccessQueueSetFromISR();
\r
274 /* Use task notifications from an ISR. */
\r
275 xNotifyTaskFromISR();
\r
279 /*-----------------------------------------------------------*/
\r