nikola1010 wrote on Monday, August 24, 2015:
Hi all,
just succedded in compilation of FreeRTOS and wanted to try simple pin toggle.
Small dev board that I got off ebay has led on PC13 (logic low active).
When I put code from task into main it works, but in task itself it does’t.
Could someone provide hint on that? (thank you in advance
------8<--------------8<--------------8<--------------8<--------------8<--------
/* Standard includes. */
#include <string.h>/* Scheduler includes. */
#include “FreeRTOS.h”
#include “task.h”
#include “queue.h”#include “stm32f10x.h”
#include “stm32f10x_rtc.h”
#include “stm32f10x_gpio.h”/* The time between cycles of the ‘check’ task - which depends on whether the
check task has detected an error or not. */
#define mainCHECK_DELAY_NO_ERROR ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
#define mainCHECK_DELAY_ERROR ( ( TickType_t ) 500 / portTICK_PERIOD_MS )/* Task priorities. */
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define mainECHO_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )/-----------------------------------------------------------/
/*
- Configure the hardware for the demo.
*/
static void prvSetupHardware( void );/* The ‘check’ task as described at the top of this file. */
static void prvMyTask( void *pvParameters );/-----------------------------------------------------------/
uint8_t gBITSET=0;
#define mainDELAY_LOOP_COUNT ( 0xffffff )int main( void )
{
#ifdef DEBUG
debug();
#endif/* Set up the clocks and memory interface. */ prvSetupHardware(); /* Create the 'check' task, which is also defined within this file. */ xTaskCreate( prvMyTask, "MyTask", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the idle task. The idle task is created within vTaskStartScheduler(). */ for( ;; );
}
/-----------------------------------------------------------/static void prvCheckTask( void *pvParameters )
{for( ;; ) { for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ ) // PAUSE {} GPIO_WriteBit(GPIOC , GPIO_Pin_13 , Bit_RESET); for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ ) // PAUSE {} GPIO_WriteBit(GPIOC , GPIO_Pin_13 , Bit_SET); }
}
/-----------------------------------------------------------/static void prvSetupHardware( void )
{
/* RCC system reset(for debug purpose). */
RCC_DeInit ();/* Enable HSE. */ RCC_HSEConfig( RCC_HSE_ON ); /* Wait till HSE is ready. */ while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); /* HCLK = SYSCLK. */ RCC_HCLKConfig( RCC_SYSCLK_Div1 ); /* PCLK2 = HCLK. */ RCC_PCLK2Config( RCC_HCLK_Div1 ); /* PCLK1 = HCLK/2. */ RCC_PCLK1Config( RCC_HCLK_Div2 ); /* ADCCLK = PCLK2/4. */ RCC_ADCCLKConfig( RCC_PCLK2_Div4 ); /* Flash 2 wait state. */ *( volatile unsigned long * )0x40022000 = 0x01; /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 ); /* Enable PLL. */ RCC_PLLCmd( ENABLE ); /* Wait till PLL is ready. */ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Select PLL as system clock source. */ RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source. */ while (RCC_GetSYSCLKSource() != 0x08); /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE ); /* Set the Vector Table base address at 0x08000000. */ NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 ); NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); /* Configure HCLK clock as SysTick clock source. */ SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK ); /* SPI2 Periph clock enable */ RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ); /**************************************/ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_WriteBit(GPIOC , GPIO_Pin_13 , Bit_SET);
}
/-----------------------------------------------------------/void vApplicationStackOverflowHook( TaskHandle_t pxTask, char pcTaskName )
{
/ This function will get called if a task overflows its stack. If the
parameters are corrupt then inspect pxCurrentTCB to find which was the
offending task. */( void ) pxTask; ( void ) pcTaskName; for( ;; );
}
/-----------------------------------------------------------/void assert_failed( unsigned char *pucFile, unsigned long ulLine )
{
( void ) pucFile;
( void ) ulLine;for( ;; );
}