Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
953 Views

FreeRTOS on Nios II runs, but get a soft_exception after breakpoint

I am trying to implement a simple FreeRTOS V9.0 demo on my existing NiosII system. I am using FreeRTOS demo for Nios II pretty much as is. The only changes I had to do were: 

  • Change my BSP type to HAL 

  • Regenerate BSP 

  • Modify system.h to remove# define ALT_ENHANCED_INTERRUPT_API_PRESENT and add# define ALT_LEGACY_INTERRUPT_API_PRESENT 

  • Modify FreeRTOSConfig.h to match my platform settings 

  • Make a very simple demo (see below) 

 

 

This runs great! I can use the debugger to pause the CPU inside mytask and see that the cntr variable has, in fact, increased the expected number of times, given the duration that the CPU was running prior to me pausing it. The problem happens afterwards where, as soon as I continue CPU execution (single step, or free running), I immediately hit a soft_exception in port_asm.s where the debugger is showing the CPU stuck on the break statement. The comment next to this assembly line implies that I hit some unexpected instruction. However, why would this only happen after a breakpoint? 

 

.section .exceptions.soft, "xa"soft_exceptions: ldw et, 0(ea) # Load the instruction where the interrupt occured. movhi at, %hi(0x003B683A) # Load the registers with the trap instruction code ori at, at, %lo(0x003B683A) cmpne et, et, at # Compare the trap instruction code to the last excuted instruction beq et, r0, call_scheduler # its a trap so switchcontext break # This is an un-implemented instruction or muldiv problem. br restore_context # its something else 

 

static void MyTask( void *p){ static volatile u32 cntr = 0; while(1) { cntr++; vTaskDelay(100); cntr++; } } static StackType_t MyTaskStack; StaticTask_t MyTaskBuffer; int main() { TaskHandle_t taskHandle; taskHandle = xTaskCreateStatic( MyTask, "MyTaskName", NumEntries(MyTaskStack), NULL, 2 | portPRIVILEGE_BIT, // Low priority numbers denote low priority tasks. MyTaskStack, &MyTaskBuffer); if (NULL == taskHandle) asm( "break" ); vTaskStartScheduler(); // Will only reach here if there is insufficient heap available to start the scheduler. for( ;; ); }
0 Kudos
1 Reply
Highlighted
Valued Contributor III
36 Views

After some deep diving into FreeRTOS port_asm.S file and comparing it against the standard exception handling code in HAL, I figured out the problem. The issue is that the FreeRTOS port requires that HAL must have hal.enable_runtime_stack_checking set to false. Having changed just that one setting, I am now able to properly continue executing after hitting a breakpoint.

0 Kudos