Target halted due to a break instruction in user code(Cause=6 means "Instruction bus error")

Hi,
I am trying to port FreeRtos to PIC32MZ2048EFH144 micro controller. I was created some small applications and able to use demo applications also. now i integrated the main application code which has 18 application tasks. When i am trying to run all of them, i am getting “Target halted due to a break instruction in user code” error in debugger and “General Exception Instruction bus error (cause=6, addr=a5a5a5a5).” message in console.

The below is the execution flow of the tasks running with respective priority numbers outputted the Console:

Resetting nRST Pin

Resetting nRST Pin completed
TCP/IP Stack: Initialization Started

FW_Version is 1:2
****** IP Address :1******

**********Time Sync from Ext to Internal RTC Write completed ***********
POWER ON
Internal RTC Time & Date : 23:39:54 01/22/20

_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11MVB INIT SUCCESS

_MVB_Data_Process Running at 10
step-1

step-2

_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11VCU COMM TIMEOUT

_MVB_Data_Process Running at 10
GPRS Modem Power ON*

GPRS Module Powered ON

_Gprs_StateMachine Running at 9
_GpsDataRx Running at 8
_RecordMVBEventRecorderData Running at 7
_HttpStreamDatapost Running at 6
_TCP_Tasks Running at 5
_WDT_Trigger Running at 4
_LocoConfig_to_EEPROM Running at 3
_APP_Tasks Running at 2
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_MVB_Data_Process Running at 10AT

_Gprs_StateMachine Running at 9
_GpsDataRx Running at 8
_RecordMVBEventRecorderData Running at 7
_HttpStreamDatapost Running at 6
_TCP_Tasks Running at 5
_WDT_Trigger Running at 4
_LocoConfig_to_EEPROM Running at 3
_APP_Tasks Running at 2
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_MVB_Data_Process Running at 10At CMD Time OUT -> AT

_Gprs_StateMachine Running at 9
_GpsDataRx Running at 8
_RecordMVBEventRecorderData Running at 7
_HttpStreamDatapost Running at 6
_TCP_Tasks Running at 5
_WDT_Trigger Running at 4
_LocoConfig_to_EEPROM Running at 3
_APP_Tasks Running at 2
_SYS_Tasks Running at 18
_SYS_RTCC_Tasks Running at 17
_SYS_FS_Tasks Running at 16
_SYS_TMR_Tasks Running at 15
_DRV_SDCARD_Tasks Running at 14
_LED_Control Running at 13
_SDCard_Process Running at 12
_SDCard_LogDeletion Running at 11
_MVB_Data_Process Running at 10AT

_Gprs_StateMachine Running at 9
_GpsDataRx Running at 8
_RecordMVBEventRecorderData Running at 7
_HttpStreamDatapost Running at 6
_TCP_Tasks Running at 5
_WDT_Trigger Running at 4
_LocoConfig_to_EEPROM Running at 3
_APP_Tasks Running at 2

General Exception Instruction bus error (cause=6, addr=a5a5a5a5).

Considerations:

  1. Initially i was able to run from 18 to 10, then system got into exceptional error. then i went through Execution memory and found problem in 9th priority task in which one Do{} while() loop stopping the system. So after avoiding that , now running full tasks i.e from 18 to 2(task 1 was not created) .
    In this situation i thought a watch Dog timer resets the application as scheduler hide in do{} while() loop. is it Correct??
  2. after solving the first case, i was able to run all the task up to 3 iterations, but again the system got into exceptional error. this time i am not able to find the error.
  3. I am using 4 uarts . 1 for GPS which continuously causing interrupt and 2 for GPRS and 3 for COM port. In addition i am using Ethernet, SD card etc mentioned above in console output.
    Please help me as early as possible .

Thank you in advance.

As I’m not familiar with your application I have no way of knowing.

This is the value the stack is filled with when a task is created, so it looks like a stack or other corruption issue. Are you familiar with this page FreeRTOS - Open Source RTOS Kernel for small embedded systems - it lists things like how to check for stack overflows, how to use configASSERT(), etc. to help you during development.

I would also recommend familiarising yourself with the “Interrupt Service Routines” section on this PIC32 specific page: Free RTOS for PIC32MZ microcontroller with MIPS M14K core

Thank you Sir,
My problem solved. The bug is in UART ISR in which i am calling SYSCONSOLEPRINT(); So RTOS doesnot allow to switch another operation without using proper ISR API’s given by FREERTOS like GiveFromISR();. So when i removed it apllication working fine.

Hi,
As i am getting this error again i need to resume the thread.
The following is the case i analysed:

Without mutex and semaphore, the application is running continously. but when i added mutex and semaphore the application is halting approximately after 20 minutes with the error stated above.
Application description:

Total tasks 17;
number of mutex- 6
binary semaphore - 1 for Synchronization between task and ISR

Among all these tasks , the heavy weight tasks are gps,gprs and tcpip.
now the problem is not because of Mallochook and stackoverflow hook. It is because of general exception handler. When i see execution memory at the time of target halted the API flow is like this:
Initialise or deinitialise of ipv4,dns,dhcp

TCPIP_Notification_RemoveAll

Tcpip_heap_freeinline

uxlistremove

Vportfree

_tcpipstacksignalhandlersetparams

SYS_RESET_SoftwareReset::PLIB_DEVCON_SystemUnlock::DEVCON_SystemUnlock_Default

SYS_RESET_SoftwareReset::PLIB_RESET_SoftwareResetEnable

_genearal_exception_hadler(in which target is halting and reporting me an error)

Calloc(next API to be called listed in execution memory)

Note:

  1. I am printing data in uart console approx 2.5 kb /each iteration
  2. I am using Heap3.c

So please give me some valuable suggestions to resolve this issue.

Regards,
Sai kumar korada

@rtel Hi sir,
When can i expect the reply for the above question.

It is very difficult for us to debug an exception in your code remotely. Last time, if I interpret your post correctly, it was because you were printing to the console from an interrupt - are you doing that from any other interrupts, or anything else that is not really valid from an interrupt? What happens if you remove all console printing, does the code continue?

@saikumar.k Exception code 6 is mainly caused by either calling a non ISR API function from an ISR or using an application/RTOS object before it has been created.
No one here knows your code so it’s impossible for us to tell you exactly what is wrong with it. Hopefully we’re pointing you in the right direction, as that is the only thing we can realistically do.

1 Like

Hi @SergentSloGin,
Your suggestions are really helpful. I reviewed your instructions and commented all printf statements. Afterwords application ran successfully upto some extent which was longer than earlier and then i got exception error.
I reviewed my code and found i am calling API’s in ISR which are necessary here.

Also my sincere request to you to review my ISR file once.
System_Interrupt.c.c (8.9 KB)

In that file, i must have to run Ethrenet,SPI , Sys_timer etc in ISR only. How to overcome this problem. Also i was tried to create sys_timer as separate task by providing task synchronization using semaphore but remaining tasks running out of sync. Maximum running time is utilized by sys_timer task only.

in addition i am posting System_interrupt_a.S file please refer to that also.

#include <xc.h>

#include “ISR_Support.h”

/* TMR Instance 0 Interrupt */
// .extern IntHandlerDrvTmrInstance0
//
// .section .vector_9,code, keep
// .equ __vector_dispatch_9, IntVectorDrvTmrInstance0
// .global __vector_dispatch_9
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvTmrInstance0
//
//IntVectorDrvTmrInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvTmrInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvTmrInstance0

//#if 0
//
// /* TMR Instance 1 Interrupt /
// .extern IntHandlerDrvTmrInstance1
//
// .section .vector_19,code, keep
// .equ __vector_dispatch_19, IntVectorDrvTmrInstance1
// .global __vector_dispatch_19
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvTmrInstance1
//
//IntVectorDrvTmrInstance1:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvTmrInstance1
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvTmrInstance1
//
//
/
TMR Instance 2 Interrupt */
.extern IntHandlerDrvTmrInstance2

.section .vector_14,code, keep
.equ __vector_dispatch_14, IntVectorDrvTmrInstance2
.global __vector_dispatch_14
.set nomicromips
.set noreorder
.set nomips16
.set noat
.ent IntVectorDrvTmrInstance2

IntVectorDrvTmrInstance2:
portSAVE_CONTEXT
la s6, IntHandlerDrvTmrInstance2
jalr s6
nop
portRESTORE_CONTEXT
.end IntVectorDrvTmrInstance2

//#endif

//
///* USART Instance 0 Interrupt /
//
// .extern IntHandlerDrvUsartReceiveInstance0
//
// .section .vector_158,code, keep
// .equ __vector_dispatch_158, IntVectorDrvUsartReceiveInstance0
// .global __vector_dispatch_158
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartReceiveInstance0
//
//IntVectorDrvUsartReceiveInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartReceiveInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartReceiveInstance0
//
//
// .extern IntHandlerDrvUsartTransmitInstance0
//
// .section .vector_159,code, keep
// .equ __vector_dispatch_159, IntVectorDrvUsartTransmitInstance0
// .global __vector_dispatch_159
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartTransmitInstance0
//
//IntVectorDrvUsartTransmitInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartTransmitInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartTransmitInstance0
//
//
// .extern IntHandlerDrvUsartErrorInstance0
//
// .section .vector_157,code, keep
// .equ __vector_dispatch_157, IntVectorDrvUsartErrorInstance0
// .global __vector_dispatch_157
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartErrorInstance0
//
//IntVectorDrvUsartErrorInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartErrorInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartErrorInstance0
//
//
//
///
USART Instance 1 Interrupt /
//
// .extern IntHandlerDrvUsartReceiveInstance1
//
// .section .vector_113,code, keep
// .equ __vector_dispatch_113, IntVectorDrvUsartReceiveInstance1
// .global __vector_dispatch_113
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartReceiveInstance1
//
//IntVectorDrvUsartReceiveInstance1:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartReceiveInstance1
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartReceiveInstance1
//
//
// .extern IntHandlerDrvUsartTransmitInstance1
//
// .section .vector_114,code, keep
// .equ __vector_dispatch_114, IntVectorDrvUsartTransmitInstance1
// .global __vector_dispatch_114
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartTransmitInstance1
//
//IntVectorDrvUsartTransmitInstance1:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartTransmitInstance1
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartTransmitInstance1
//
//
// .extern IntHandlerDrvUsartErrorInstance1
//
// .section .vector_112,code, keep
// .equ __vector_dispatch_112, IntVectorDrvUsartErrorInstance1
// .global __vector_dispatch_112
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartErrorInstance1
//
//IntVectorDrvUsartErrorInstance1:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartErrorInstance1
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartErrorInstance1
//
//
//
///
USART Instance 3 Interrupt /
//
// .extern IntHandlerDrvUsartReceiveInstance3
//
// .section .vector_171,code, keep
// .equ __vector_dispatch_171, IntVectorDrvUsartReceiveInstance3
// .global __vector_dispatch_171
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartReceiveInstance3
//
//IntVectorDrvUsartReceiveInstance3:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartReceiveInstance3
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartReceiveInstance3
//
//
// .extern IntHandlerDrvUsartTransmitInstance3
//
// .section .vector_172,code, keep
// .equ __vector_dispatch_172, IntVectorDrvUsartTransmitInstance3
// .global __vector_dispatch_172
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartTransmitInstance3
//
//IntVectorDrvUsartTransmitInstance3:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartTransmitInstance3
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartTransmitInstance3
//
//
// .extern IntHandlerDrvUsartErrorInstance3
//
// .section .vector_170,code, keep
// .equ __vector_dispatch_170, IntVectorDrvUsartErrorInstance3
// .global __vector_dispatch_170
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartErrorInstance3
//
//IntVectorDrvUsartErrorInstance3:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartErrorInstance3
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartErrorInstance3
//
//
//
///
USART Instance 4 Interrupt /
//
// .extern IntHandlerDrvUsartReceiveInstance4
//
// .section .vector_180,code, keep
// .equ __vector_dispatch_180, IntVectorDrvUsartReceiveInstance4
// .global __vector_dispatch_180
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartReceiveInstance4
//
//IntVectorDrvUsartReceiveInstance4:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartReceiveInstance4
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartReceiveInstance4
//
//
// .extern IntHandlerDrvUsartTransmitInstance4
//
// .section .vector_181,code, keep
// .equ __vector_dispatch_181, IntVectorDrvUsartTransmitInstance4
// .global __vector_dispatch_181
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartTransmitInstance4
//
//IntVectorDrvUsartTransmitInstance4:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartTransmitInstance4
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartTransmitInstance4
//
//
// .extern IntHandlerDrvUsartErrorInstance4
//
// .section .vector_179,code, keep
// .equ __vector_dispatch_179, IntVectorDrvUsartErrorInstance4
// .global __vector_dispatch_179
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorDrvUsartErrorInstance4
//
//IntVectorDrvUsartErrorInstance4:
// portSAVE_CONTEXT
// la s6, IntHandlerDrvUsartErrorInstance4
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorDrvUsartErrorInstance4
//
//
//
///
SPI Instance 0 Interrupt /
// .extern IntHandlerSPIRxInstance0
//
// .section .vector_110,code, keep
// .equ __vector_dispatch_110, IntVectorSPIRxInstance0
// .global __vector_dispatch_110
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorSPIRxInstance0
//
//IntVectorSPIRxInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerSPIRxInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorSPIRxInstance0
//
//
// .extern IntHandlerSPITxInstance0
//
// .section .vector_111,code, keep
// .equ __vector_dispatch_111, IntVectorSPITxInstance0
// .global __vector_dispatch_111
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorSPITxInstance0
//
//IntVectorSPITxInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerSPITxInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorSPITxInstance0
//
//
// .extern IntHandlerSPIFaultInstance0
//
// .section .vector_109,code, keep
// .equ __vector_dispatch_109, IntVectorSPIFaultInstance0
// .global __vector_dispatch_109
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVectorSPIFaultInstance0
//
//IntVectorSPIFaultInstance0:
// portSAVE_CONTEXT
// la s6, IntHandlerSPIFaultInstance0
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVectorSPIFaultInstance0
//
//
///
ETHMAC Interrupt */
// .extern IntHandler_ETHMAC
//
// .section .vector_153,code, keep
// .equ __vector_dispatch_153, IntVector_ETHMAC
// .global __vector_dispatch_153
// .set nomicromips
// .set noreorder
// .set nomips16
// .set noat
// .ent IntVector_ETHMAC
//
//IntVector_ETHMAC:
// portSAVE_CONTEXT
// la s6, IntHandler_ETHMAC
// jalr s6
// nop
// portRESTORE_CONTEXT
// .end IntVector_ETHMAC
//

/*******************************************************************************
End of File
*/

I appreciate your help. thank you

I haven’t reviewed your isms, but as was mentioned, ISR can’t call any of the non-ISR API, and shouldn’t do I/O that can take awhile. If in response to an ISR you want to do something like that, the ISR should signal a task to do that action. ISR need to be quick, doing minimal work to handle the interrupt, and any longer operation should be deferred to a task.

I had a brief scan of the file and as I mentioned before and richard-damon re-iterated, ISRs need to do as little as possible. Defer to tasks any processing that isn’t time critical.

I found the following ISRs where you seem to be calling a task from within the ISR. Don’t do that. Post a message to a task and let the task monitor those messages to decide what needs to be done.

void __ISR(_SPI1_RX_VECTOR, ipl3AUTO) _IntHandlerSPIRxInstance0(void)
{
    DRV_SPI_Tasks(sysObj.spiObjectIdx0);
}
void __ISR(_SPI1_TX_VECTOR, ipl3AUTO) _IntHandlerSPITxInstance0(void)
{
    DRV_SPI_Tasks(sysObj.spiObjectIdx0);
}
void __ISR(_SPI1_FAULT_VECTOR, ipl3AUTO) _IntHandlerSPIFaultInstance0(void)
{
    DRV_SPI_Tasks(sysObj.spiObjectIdx0);
}
void __ISR(_ETHERNET_VECTOR, ipl5AUTO) _IntHandler_ETHMAC(void)
{
    DRV_ETHMAC_Tasks_ISR((SYS_MODULE_OBJ)0);
}

Hope this helps.