Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

LedToggle

Posted by Do on May 30, 2013
Hi,
Am trying to flash a led of an STM32-P107, i created a freertos code, i compiled the project without having errors but there is no result on the card, This is my code :


/ Standard includes. /
include
include

/ Scheduler includes. /
include \"FreeRTOS.h\"
include \"task.h\"
include \"queue.h\"
include \"semphr.h\"
include \"leds.h\"
include \"button.h\"
include \"stm32f10x_conf.h\"
include \"stm32_eval.h\"
include \"partest.h\"

/ Task priorities. /
define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )

/ Task priorities. /
define TASKPRIORITY1 (tskIDLE_PRIORITY + 1)
define TASKPRIORITY2 (tskIDLE_PRIORITY + 2)
define TASKPRIORITY3 (tskIDLE_PRIORITY + 3)

/ The rate at which the flash task toggles the LED. /
define mainFLASH_DELAY ( ( portTickType ) 25 / portTICK_RATE_MS )

/ The number of nano seconds between each processor clock. /
define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )

/-----------------------------------------------------------/

/
* Configure the clocks, GPIO and other peripherals as required by the demo.
/
static void prvSetupHardware(void);

/
* The LCD is written two by more than one task so is controlled by a
* \'gatekeeper\' task. This is the only task that is actually permitted to
* access the LCD directly. Other tasks wanting to display a message send
* the message to the gatekeeper.
/
extern int sprintf(char out, const char format, ...);

xTaskHandle xTaskLed;
void vTaskFunction( void * pvParameters );
//void vTaskLed( void *pvParameters );

/-----------------------------------------------------------/

int main(void) {

prvSetupHardware();

setbuf(stdout,NULL);
/* Start the scheduler. */
printf(\"########################## MINI PROJET CS530 ################\\n\");
ButtonInit();
LEDsInit();

xTaskCreate(vTaskFunction,\"vTaskFunction\", configMINIMAL_STACK_SIZE+50 , NULL, TASKPRIORITY1,NULL);
// xTaskCreate( vTaskLed, \"vTaskLed\", configMINIMAL_STACK_SIZE+50, NULL, TASKPRIORITY2, &xTaskLed );
GPIO_WriteBit( GPIOC, GPIO_Pin_6,Bit_SET );
vTaskStartScheduler();

/* Will only get here if there was not enough heap space to create the
idle task. */
return 0;

}
/-----------------------------------------------------------/

static void prvSetupHardware(void) {

USART_InitTypeDef USART_InitStructure;

/* 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 */

ifdef IAP_VECT_TAB_RELOCATE

NVIC_SetVectorTable(NVIC_VectTab_FLASH_RELOCATED, 0x0);

else

NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x0 );

endif

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

/* Configure HCLK clock as SysTick clock source. */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);

/* Configure UART */
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl= USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

STM_EVAL_COMInit(COM2, &USART_InitStructure);

}

/-----------------------------------------------------------/

void vTaskFunction( void * pvParameters )
{

const portTickType xDelay = 500 / portTICK_RATE_MS;

for( ;; )
{

LEDToggle(LEDG);
vTaskDelay( xDelay );
}

}

and this the led.c code:
/
* leds.c

* Created on: Nov 8, 2011
* Author: MMM
*/
include \"leds.h\"

void LEDsInit(void)
{
//GPIO structure used to initialize LED port
GPIO_InitTypeDef GPIO_InitStructure;
//Enable clock on APB2 pripheral bus where LEDs are connected
RCC_APB2PeriphClockCmd(LEDPORTCLK, ENABLE);
//select pins to initialize LED
GPIO_InitStructure.GPIO_Pin = LEDG|LEDB;
//select output push-pull mode
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//highest speed available
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LEDPORT, &GPIO_InitStructure);
}

void LEDToggle(uint32_t LEDn){

{
if(GPIO_ReadOutputDataBit(LEDPORT, LEDn)) //read previous state
{
GPIO_ResetBits(LEDPORT, LEDn); //set to zero
}
else
{
GPIO_SetBits(LEDPORT, LEDn);//set to one
}
}
}

what is wrong please?

RE: LedToggle

Posted by Richard on May 30, 2013
I can't comment on your hardware configuration code as that is very chip specific and outside of the scope of FreeRTOS support. However I do recommend ensuring each part of your application works individually before putting it together.

First, remove all the sprintf() and UART code to cut the project down to a minimum.

Next, if you have not done already, check the LED configuration and toggle code is working without FreeRTOS. Do this by simply calling the initialisation code, and the LED on and LED off code before the scheduler is started. Once you are sure the LED code is working you can start running FreeRTOS - then if the LED is not toggling you know it is not anything to do with the LED interfacing.

When you add in the FreeRTOS code, start with just a single task - the toggle task - again without any printfs or UART code. Put a break point at the beginning of the LED toggling task to ensure the task actually starts executing.

If you have any problems starting the scheduler then report back how far the code gets (step through it to see what happens).

Regards.

RE: LedToggle

Posted by Do on May 31, 2013
I fixed the problem thank you


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner