This application just creates a single task to blink an LED, the LED state must be changed every 2000ms.
Code Example:
#include "bsp.h"
/*Function to act as task*/
static void vTask( void *parameters );
int main( void )
{
HAL_Init( ); /*Inicializamos la librerÃa*/
/*enable RTT and system view*/
SEGGER_SYSVIEW_Conf( );
SEGGER_SYSVIEW_Start( );
/*register task using the function vTask with (128*4) bytes de stack, no parameters
priority of 1 and no task handler registered*/
xTaskCreate( vTask, "Task", 128u, NULL, 1u, NULL );
vTaskStartScheduler( ); /*run the RTOS scheduler*/
return 0u;
}
/*Simple task that intialize one pin as output and toggle the pin state every 2000ms*/
static void vTask( void *parameters )
{
GPIO_InitTypeDef GPIO_InitStruct; /* GPIO PIN Handler */
__HAL_RCC_GPIOC_CLK_ENABLE( ); /* Enable the clock for the port C */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /* Configure the Pin as output */
GPIO_InitStruct.Pull = GPIO_NOPULL; /* Configure pin as no pull up - no pull down */
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* Configure frequency of pin as High */
GPIO_InitStruct.Pin = GPIO_PIN_0; /* Configure PIN 0 */
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct ); /* Initialize the GPIO */
for( ; ; ) /* Loop of Task */
{
HAL_GPIO_TogglePin( GPIOC, GPIO_PIN_0 ); /* change the state of pin 0, port c */
HAL_Delay( 2000u ); /* Delay of 2000ms */
}
}
SystemView Output
The timeline shows the task execution, observe that the task is only
|
|
When the time delay elapsed the task will execute again. Notice that
|