cdb1702 wrote on Sunday, April 01, 2012:
For a better understanding I use the same project with a define FLAGRTOS that can have 3 values
0 for demo CDC : all is ok (link with P.C. + LED blinking)
1 for demo FreeRTOS : all is ok led blinking
2 for demo CDC+ a big delay + calls to FreeRTOS functions (with this define there is link with P.C. until FreeRTOS is not invoked)
/**
*****************************************************************************
**
** File : main.c
**
** Abstract : main function.
**
** Functions : main
**
** Environment : Atollic TrueSTUDIO®
** STMicroelectronics STM32F4xx Standard Peripherals Library
**
** Distribution: The file is distributed “as is,” without any warranty
** of any kind.
**
** ©Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. Distribution of this file (unmodified or modified) is not
** permitted. Atollic AB permit registered Atollic TrueSTUDIO® users the
** rights to distribute the assembled, compiled & linked contents of this
** file as part of an application binary file, provided that it is built
** using the Atollic TrueSTUDIO® toolchain.
**
**
*****************************************************************************
*/
/* Includes */
#include “stm32f4xx.h”
#include “usbd_cdc_core.h”
#include “usbd_cdc.h”
#include “usbd_usr.h”
#include “usbd_desc.h”
/* FreeRTOS includes */
#include “FreeRTOS.h” // automaticamente include FreeRTOSConfig.h
#include “task.h”
#include “semphr.h”
#define FLAGRTOS 2
#define queueSIZE 6
#define DELAY 125 /* msec */
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );
/* Task functions declarations */
static void vLEDTask( void *pvParameters );
/* initial arguments for vLEDTask task (which LED and what is the delay) */
static const int LEDS = {{LED3,DELAY*1},
{LED4,DELAY*2},
{LED5,DELAY*3},
{LED6,DELAY*4}};
/* semaphores, queues declarations */
xSemaphoreHandle xSemaphoreSW = NULL;
xQueueHandle xQueue;
xTaskHandle xLED_Tasks;
/* Private macro */
/* Private variables */
/* Private function prototypes */
void Delay(__IO uint32_t nTick);
/* Private functions */
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END ;
/**
**===========================================================================
**
** Abstract: main program
**
**===========================================================================
*/
uint16_t cdc_DataTx (uint8_t* Buf, uint32_t Len);
int main(void)
{
int i = 0;
STM32F4_Discovery_LEDInit(LED3);
STM32F4_Discovery_LEDInit(LED4);
STM32F4_Discovery_LEDInit(LED5);
STM32F4_Discovery_LEDInit(LED6);
STM32F4_Discovery_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
STM32F4_Discovery_LEDOn(LED3);
Delay(0xFFFF);
#if FLAGRTOS==0 // CDC only
//usb init
USBD_Init(&USB_OTG_dev,
#ifdef USE_USB_OTG_HS
USB_OTG_HS_CORE_ID,
#else
USB_OTG_FS_CORE_ID,
#endif
&USR_desc,
&USBD_CDC_cb,
&USR_cb);
while (1)
{
if (i++ == 0x100000)
{
STM32F4_Discovery_LEDToggle(LEDGREEN);
i=0;
}
}
#endif
#if FLAGRTOS==1 // FreeRTOS only
xQueue=xQueueCreate(1,queueSIZE*sizeof(uint8_t));
xTaskCreate( vLEDTask, ( signed portCHAR * ) “LED3”, configMINIMAL_STACK_SIZE, (void *)LEDS,tskIDLE_PRIORITY, &xLED_Tasks );
/* Start the scheduler. */
vTaskStartScheduler();
/* Will only get here if there was not enough heap space to create the idle task. */
return 0;
#endif
#if FLAGRTOS==2 // FreeRTOS after about 30 seconds
//usb init
USBD_Init(&USB_OTG_dev,
#ifdef USE_USB_OTG_HS
USB_OTG_HS_CORE_ID,
#else
USB_OTG_FS_CORE_ID,
#endif
&USR_desc,
&USBD_CDC_cb,
&USR_cb);
Delay(600000000);
/* create a pipe for MEMS->TIM4 data exchange */
xQueue=xQueueCreate(1,queueSIZE*sizeof(uint8_t));
xTaskCreate( vLEDTask, ( signed portCHAR * ) “LED3”, configMINIMAL_STACK_SIZE, (void *)LEDS,tskIDLE_PRIORITY, &xLED_Tasks );
/* Start the scheduler. */
vTaskStartScheduler();
/* Will only get here if there was not enough heap space to create the idle task. */
return 0;
#endif
}
void vLEDTask( void *pvParameters )
{
volatile int *LED;
LED = (int *) pvParameters;
for( ;; )
{
STM32F4_Discovery_LEDToggle(LEDGREEN);
vTaskDelay(10000);
}
}
void Delay(__IO uint32_t nTick)
{
for(; nTick != 0; nTick-);
}
/*---------------------------------------*/
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
/* Run time stack overflow checking is performed if
configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. */
for( ;; );
}
void vApplicationIdleHook( void )
{
volatile size_t xFreeStackSpace;
/* This function is called on each cycle of the idle task. In this case it
does nothing useful, other than report the amout of FreeRTOS heap that
remains unallocated. */
xFreeStackSpace = xPortGetFreeHeapSize();
if( xFreeStackSpace > 100 )
{
/* By now, the kernel has allocated everything it is going to, so
if there is a lot of heap remaining unallocated then
the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
reduced accordingly. */
}
}