Content originally posted in LPCWare by Brutte on Sun Aug 05 07:34:49 MST 2012
Quote:
This is a single-chip embedded system with no standard IO, I need a simple 1-2 words that can be serially pushed out a spare pin and read with a logic analyser.
An assert.h is a standard feature. Works great, from attinys to x86.
It is you who provide the implementation of the core of the assert().
I sometimes insert asm("bkpt 0x00"), sometimes asm("nop") and nothing stops you from providing a more/less advanced BSOD.
I wonder why cannot you use OCD for asserts? Why necessarily a blinking LED, a.k.a. logic analyser, when (most of) ARMs have full-blown features on-board?
But, if you really need that IO, unless it is tn4-ish "single-chip embedded system", I suggest a software driven UART tx on an arbitrary pin.
Quote:
If I have the address I can look at the map file to find the culprit.
Sure, you can find the file, function, the line and the cause. But that is what assert was made for. Finally, after 10 minutes of searching *.lst you will get to the conclusion:
Quote: Target, complaining
>>Oops, assertion failed in MyProject/src/foo.c in function boo(), at line 17, because somehow pinNumber >= MAX_PINS and you are kindly requested to fix that. PC is 0xef45c03 if that can help.
but looks like reinventing the wheel.
Quote:
I can't find any mention of using the SCB for this in the UM or anywhere else and a Google of SCB_DCRSR only brings up a single page
Quote: ARM ARMv7-M
Debug Core Register Selector Register (DCRSR)
The DCRSR write-only register generates a handshake to the core to transfer the selected register to/from the DCRDR. The DHCSR S_REGRDY bit is cleared when the DCRSR is written, and remains clear until the core transaction completes. This register is only accessible from Debug state.
(...)
[4:0] REGSEL:
00000: R0
00001: R1
…
01100: R12
01101: the current SP
01110: LR
01111: DebugReturnAddress()
10000: xPSR / Flags, Execution Number, and state information
10001: MSP (Main SP)
10010: PSP (Process SP)
10100: CONTROL bits [31:24], FAULTMASK bits [23:16],
BASEPRI bits [15:8], and PRIMASK bits [7:0]
Search CMSIS for "DCRSR" and I am sure you will eventually find it:) It belongs to System Control Block (SCB).
A Debug Return Address should give you a PC value.
As an alternative, you can also try reading DWT_PCSR.