This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Usage Fault in App Scheduler

I'm using and NRF52 with S132 and SDK13.0. I'm using Keil as my IDE.

My application acts as a central for smart phones to connect to and also acts as a peripheral to conect to multiple other devices.

Currently my app works well with up to 2 smart phones configured and connected, and up to 4 of the external devices connected simultaneously.

I am currently trying to add the capability for more smart phones to connect to my device. Unfortunately, when I configure my device to be able to connect to more than 2 smart phones, it starts receiving usage faults. My knowledge of debugging this is somewhat limited so, the method i use and conclusion I've drawn may be wrong. I'd love some help to figure it out.

I've been using this app note to help me.

The image below shows the registers, fault reports, and location (i believe this is correct) of the fault. image description

here's my process for coming to that point

  1. Link Register is 0xFFFFFFE9, bit 2 is zero so, The main statck is used.
  2. The main stack pointer (MSP) points to 0x2000E6E8
  3. So looking at the contents of memory at 0x2000E6E8, I can see the previous execution context
  4. The Link register of the previous execution context is 0x022EBB, minus 1 because it is in thumb mode, gives 0x022EBA. This shows where the code is returning to and this is shown in the disassembly window as m_queue_start_index = next_index(m_queue_start_index); So think it's coming back from event_handler(p_event_data, event_data_size);
  5. The Fault Report window shows it is a usage fault with INVSTATE set which means

the processor has attempted to execute an instruction that makes illegal use of the Execution Program Status Register (EPSR). When this bit is set, the PC value stacked for the exception return points to the instruction that attempted the illegal use of the EPSR. Potential reasons: a) Loading a branch target address to PC with LSB=0. b) Stacked PSR corrupted during exception or interrupt handling. c) Vector table contains a vector address with LSB=0.

So I think that the error is happening in event_handler(p_event_data, event_data_size) in app_scheduler.c but, when I put some debug statements around my app_scheduler event statement, i always see it start and finish. I've also check my appsceduler queue usage using app_sched_queue_utilization_get but never see more than a 40% utilisation

It may not be related, but I'm also occasionally seeing a busfault with IBUSSERR set and I get the same LR value of the previous execution context which is 0x022EBB, minus 1 because it is in thumb mode, gives 0x022EBA.

instruction bus error. The processor detects the instruction bus error on prefetching an instruction, but it sets the IBUSERR flag to 1 only if it attempts to issue the faulting instruction. When the processor sets this bit it does not write a fault address to SCB->BFAR. Potential reasons: a) Branch to invalid memory regions for example caused by incorrect function pointers. b) Invalid return due to corrupted stack pointer or stack content. c) Incorrect entry in the exception vector table.

How can I debug this further. Also, what does the 0xCAFEBABE in R3 of the registers window mean? I doubt this is just some random address

Edit 01 Aug for Clarification The issue manifests itself in the following way:

  1. Connect Smart phones and external device to my device.
  2. Let the devices run. The external devices generate data at a rate of 25Hz. In my event handler for the notification , I notify the smartphones with the new data and add an app scheduler event to the queue to log the received data.
  3. Eventually (after a few minutes), I get a Bus Fault or usage fault. This happens sometime between finishing processing an app scheduler event and processing the next one in the queue. It does not happen in my BLE service event handlers. I have not seen any issues when there is not another app scheduler event to process.

If I don't enable the Bus Fault and Usage fault handlers then The code goes into the hard fault handler.

If I look at the call stack when in the hardfault handler, there is no information. The image below shows the register values from the hardfault handler with the bus fault and usage fault handlers turned off (in this case it looks like I got a bus fault).

image description

  • @RK when you talked about catch points, where you referring to monitor mode debugging? I've sent away a PCB to be made so I can use the ETM on the Dev Kit. @Hung Bui, its easy to reproduce but takes a couple of minutes to occur. I'll try create a simplified demonstration

  • no - not MMD. What I'm talking about it breakpoints on exceptions, which get taken before the fault handler is called. I never saw them on the nRF51 series, when I started working with the '52 they showed up enabled (I use Crossworks which is basically Segger Embedded Studio). It was confusing at first because they caused debug stops at points I didn't expect and got turned off at some point. I just don't remember the term for them and don't have a board handy right now (been in Atmel land for a while recently which is mostly cortex M0 again).

    Nor has my google-fu turned up the term. Either way - on the M4 you should be able to take a breakpoint before the exception handler runs which is handy dandy for figuring out where you were without having to work backwards.

  • there you go - that MMD post did have it in it in a comment. It's called Vector Catch (so I wasn't that far off). Even googling that there's not a lot of information. I must have read about it in the M4 debug and trace technical manual or something.

  • I've managed to fix this. Turns out there was a potential pointer error in one of my events. Thanks for your help, I've definitely learnt a lot about debugging hardfaults etc

Related