• AVR Freaks

Hot!Harmony configuration problem for freeRTOS

Author
gulivet
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/02/18 08:26:33
  • Location: 0
  • Status: offline
2020/02/23 07:14:02 (permalink)
0

Harmony configuration problem for freeRTOS

Hello,
I have a problem that I think is related to harmony. I want to use freeRTOS on a PIC32 ethernet starter kit 1 card (PIC32MX795F512L). I generate the code thanks to harmony. To test the code I declared a task which is supposed to blink LEDs, here is the code:


// Main LED Flash
static void TaskBlinkLED(void* led)
{
TRISDbits.TRISD0=0;
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
while (1)
{
/* Simply toggle the LED every 500ms, blocking between each toggle. */
LATDbits.LATD0=1;
vTaskDelay( xDelay );
LATDbits.LATD0=0;
vTaskDelay( xDelay );

}
vTaskDelete(NULL);
}
int main()
{
/* Initialize all modules */
SYS_Initialize (NULL);

xTaskCreate(TaskBlinkLED, (const portCHAR*) "LED", 1024, NULL, 1 , NULL);
vTaskStartScheduler();

while ( true )
{
}


return ( EXIT_FAILURE );
}
 
The problem is that the first vTaskDelay in my function does not work and sends me in a general exception funciton. I specify that the LED lights up well at the start of the function, but as the exception is an infinite loop, the LED never goes out. I give you the FreeRTOSConfig.h that I use, I changed the values to be able to use the vTaskDelay but nothing helps.
 
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ ( 80000000UL )
#define configTICK_RATE_HZ ( ( TickType_t ) 250 )
#define configMAX_PRIORITIES ( 5UL )
#define configMINIMAL_STACK_SIZE ( 128 )
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configTOTAL_HEAP_SIZE ( ( size_t ) 28000 )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configQUEUE_REGISTRY_SIZE 0
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 1
#define configUSE_NEWLIB_REENTRANT 0
#define configUSE_TASK_FPU_SUPPORT 0

/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_MALLOC_FAILED_HOOK 1
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 2
/* Software timer related definitions. */
#define configUSE_TIMERS 0
#define configTIMER_TASK_PRIORITY 0
#define configTIMER_QUEUE_LENGTH 0
#define configTIMER_TASK_STACK_DEPTH 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
/* Misc */
#define configUSE_APPLICATION_TASK_TAG 0

/* Interrupt nesting behaviour configuration. */
#define configPERIPHERAL_CLOCK_HZ ( 80000000UL )
#define configISR_STACK_SIZE ( 512 )
/* The priority at which the tick interrupt runs. This should probably be kept at lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY (1)
/* The maximum interrupt priority from which FreeRTOS.org API functions can be called.
*Only API functions that end in ...FromISR() can be used within interrupts. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY (3)
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 1
 
I also tried to debug to see which instruction was throwing the exception. And it turns out that by executing the code instruction by instruction with a breakpoint on the vTaskDelay, the exception is no longer thrown. The task runs perfectly well and the led goes out normally, but in standard execution it is no longer working.
 
As I tested a lot of things to solve the problem, I think that it may be a problem with harmony, which is not able to generate proper code for this card. If nevertheless you have ideas on something that I would have misconfigured, please tell me!
 
Thank you for your advice and have a nice day
#1
BillP
Super Member
  • Total Posts : 389
  • Reward points : 0
  • Joined: 2014/09/28 07:53:35
  • Location: CA
  • Status: offline
Re: Harmony configuration problem for freeRTOS 2020/02/25 09:14:10 (permalink)
0
Could it be that SYS_Initialize() creates a task or interrupt handler that cannot return?
#2
gulivet
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2020/02/18 08:26:33
  • Location: 0
  • Status: offline
Re: Harmony configuration problem for freeRTOS 2020/02/25 10:00:53 (permalink)
0
The Sys_Initialize() has been created by harmony, I read it to see if there was something strange but it seems like a pretty normal init.
You have some usb intitialize because I'm trying to use usb cdc with FreeRTOS, but even with only FreeRTOS it had the same problem. Here is the funciton, in case an error was hidden in it : 
void SYS_Initialize ( void* data )
{
/* Start out with interrupts disabled before configuring any modules */
__builtin_disable_interrupts();

CLK_Initialize();
/* Configure KSEG0 as cacheable memory. This is needed for Prefetch Buffer */
__builtin_mtc0(16, 0,(__builtin_mfc0(16, 0) | 0x3));
/* Configure Flash Wait States and Prefetch */
CHECONbits.PFMWS = 2;
CHECONbits.PREFEN = 3;
/* Set the SRAM wait states to zero */
BMXCONbits.BMXWSDRM = 0;
 
 
GPIO_Initialize();

/* Initialize USB Driver */
sysObj.drvUSBFSObject = DRV_USBFS_Initialize(DRV_USBFS_INDEX_0, (SYS_MODULE_INIT *) &drvUSBFSInit);

/* Initialize the USB device layer */
sysObj.usbDevObject0 = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 , ( SYS_MODULE_INIT* ) & usbDevInitData);

APP_Initialize();

EVIC_Initialize();
/* Enable global interrupts */
__builtin_enable_interrupts();

}
#3
ric
Super Member
  • Total Posts : 26975
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Harmony configuration problem for freeRTOS 2020/02/26 18:11:20 (permalink)
0
Rather than changing the font of your code, place "code" tags around it to display nicely.
That is [CODE] before the block, and [/CODE] after it, but use lower case "code" and "/code" between the square brackets.
void SYS_Initialize ( void* data )
{
/* Start out with interrupts disabled before configuring any modules */
__builtin_disable_interrupts();

CLK_Initialize();
/* Configure KSEG0 as cacheable memory. This is needed for Prefetch Buffer */
__builtin_mtc0(16, 0,(__builtin_mfc0(16, 0) | 0x3));
/* Configure Flash Wait States and Prefetch */
CHECONbits.PFMWS = 2;
CHECONbits.PREFEN = 3;
/* Set the SRAM wait states to zero */
BMXCONbits.BMXWSDRM = 0;
 
 
GPIO_Initialize();

/* Initialize USB Driver */
sysObj.drvUSBFSObject = DRV_USBFS_Initialize(DRV_USBFS_INDEX_0, (SYS_MODULE_INIT *) &drvUSBFSInit);

/* Initialize the USB device layer */
sysObj.usbDevObject0 = USB_DEVICE_Initialize (USB_DEVICE_INDEX_0 , ( SYS_MODULE_INIT* ) & usbDevInitData);

APP_Initialize();

EVIC_Initialize();
/* Enable global interrupts */
__builtin_enable_interrupts();

}

 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
NKurzman
A Guy on the Net
  • Total Posts : 18663
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Harmony configuration problem for freeRTOS 2020/02/26 18:43:43 (permalink)
0
1. Which Version of Harmony?
2. Make sure any Harmony Service that you are using are up and running.  ie if vTaskDelay() is using system timer services you need to make sure that is running before using it (in V1.XX and 2.XX it took a few loops to initialize System Timer services, For a lame reason)).
3. Check return values on any functions that return them.
4. Only use the Version of XC32 that the Release notes indicate.  Or you may get issues.
5. Only use the Version of FReeRTOS that is included with Harmony, Newer versions may not work.  You can update as needed later after it works, same with the compiler IF your needed it.
#5
Jump to:
© 2020 APG vNext Commercial Version 4.5