Skip to content

Commit

Permalink
Add black box pointer output to freeze handler (#690)
Browse files Browse the repository at this point in the history
* Working on freeze handler, pointers not right yet and OLED doesn't paint anymore currently

* Dbt format and todo

* * Blackbox pointers are outputted via RTT
* (Seemingly) Fixed SEGGER_RTT symbol
* Fixed OLED not updating freeze display
* Added commit id to blackbox
* Fixed blackbox stack pointers
  • Loading branch information
PaulFreund authored Nov 7, 2023
1 parent 0188b9d commit 1dc06e1
Show file tree
Hide file tree
Showing 85 changed files with 643 additions and 460 deletions.
3 changes: 3 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"request": "launch",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/Debug/deluge.elf",
"windows": {
"serverpath": "C:\\Program Files\\SEGGER\\JLink\\JLinkGDBServerCL.exe",
},
"servertype": "jlink",
"device": "R7S721020",
"interface": "swd",
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
"SDRAM",
"Synthstrom"
],
"cortex-debug.armToolchainPath.windows": "${workspaceRoot}/toolchain/win32-x86_64/arm-none-eabi-gcc/bin",
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ execute_process(
string(TIMESTAMP DATE_TODAY "%Y.%m.%d")

# Build our version string
set(BUILD_COMMIT_SHORT "${GIT_COMMIT_SHORT}") # Used in firmware
set(BUILD_VERSION_STRING "${PROJECT_VERSION}${SEMVER_PRERELEASE_ID}-${GIT_COMMIT_SHORT}") # Used in firmware
set(BUILD_VERSION_SUFFIX "-v${PROJECT_VERSION}${SEMVER_PRERELEASE_ID}+${DATE_TODAY}-${GIT_COMMIT_SHORT}") # Used for filename

Expand Down
129 changes: 65 additions & 64 deletions src/RTT/SEGGER_RTT.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ static unsigned char _aTerminalId[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
//
// RTT Control Block and allocate buffers for channel 0
//
SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT_REAL));
SEGGER_RTT_PUT_CB_SECTION(SEGGER_RTT_CB_ALIGN(SEGGER_RTT_CB _SEGGER_RTT));

SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBufferReal[BUFFER_SIZE_UP]));
SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBufferReal[BUFFER_SIZE_DOWN]));

// Stuff ingeniously messed with by Rohan to get around cache, which would stop RTT from working
#define _SEGGER_RTT (*(SEGGER_RTT_CB*)((char*)&_SEGGER_RTT_REAL + UNCACHED_MIRROR_OFFSET))
#define _SEGGER_RTT_UNCACHED (*(SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + UNCACHED_MIRROR_OFFSET))
#define _acUpBuffer ((char*)_acUpBufferReal + UNCACHED_MIRROR_OFFSET)
#define _acDownBuffer ((char*)_acDownBufferReal + UNCACHED_MIRROR_OFFSET)

Expand All @@ -278,7 +278,7 @@ static unsigned char _ActiveTerminal;
*/
#define INIT() \
do { \
if (_SEGGER_RTT.acID[0] == '\0') { \
if (_SEGGER_RTT_UNCACHED.acID[0] == '\0') { \
_DoInit(); \
} \
} while (0)
Expand All @@ -287,7 +287,7 @@ static void _DoInit(void) {
//
// Initialize control block
//
p = &_SEGGER_RTT;
p = &_SEGGER_RTT_UNCACHED;
p->MaxNumUpBuffers = SEGGER_RTT_MAX_NUM_UP_BUFFERS;
p->MaxNumDownBuffers = SEGGER_RTT_MAX_NUM_DOWN_BUFFERS;
//
Expand All @@ -314,7 +314,7 @@ static void _DoInit(void) {
// in initializer memory (usually flash) by J-Link
//
// GCC gets deeply confused by the UNCACHED_MIRROR_OFFSET trickery
// happening inside _SEGGER_RTT. It's not easy to explain what we're doing
// happening inside _SEGGER_RTT_UNCACHED. It's not easy to explain what we're doing
// here either, so simply silence the warning for now.
#pragma GCC push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
Expand Down Expand Up @@ -556,7 +556,7 @@ unsigned SEGGER_RTT_ReadUpBufferNoLock(unsigned BufferIndex, void* pData, unsign
#endif
//
INIT();
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
pBuffer = (unsigned char*)pData;
RdOff = pRing->RdOff;
WrOff = pRing->WrOff;
Expand Down Expand Up @@ -650,7 +650,7 @@ unsigned SEGGER_RTT_ReadNoLock(unsigned BufferIndex, void* pData, unsigned Buffe
#endif
//
INIT();
pRing = &_SEGGER_RTT.aDown[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aDown[BufferIndex];
pBuffer = (unsigned char*)pData;
RdOff = pRing->RdOff;
WrOff = pRing->WrOff;
Expand Down Expand Up @@ -820,7 +820,7 @@ void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuff
//
// Get "to-host" ring buffer and copy some elements into local variables.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
//
// Check if we will overwrite data and need to adjust the RdOff.
//
Expand Down Expand Up @@ -929,7 +929,7 @@ unsigned SEGGER_RTT_WriteSkipNoLock(unsigned BufferIndex, const void* pBuffer, u
// 1) is the most common case for large buffers and assuming that J-Link reads the data fast enough
//
pData = (const char*)pBuffer;
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
RdOff = pRing->RdOff;
WrOff = pRing->WrOff;
if (RdOff <= WrOff) { // Case 1), 2) or 3)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ unsigned SEGGER_RTT_WriteDownBufferNoLock(unsigned BufferIndex, const void* pBuf
// Get "to-target" ring buffer.
// It is save to cast that to a "to-host" buffer. Up and Down buffer differ in volatility of offsets that might be modified by J-Link.
//
pRing = (SEGGER_RTT_BUFFER_UP*)&_SEGGER_RTT.aDown[BufferIndex];
pRing = (SEGGER_RTT_BUFFER_UP*)&_SEGGER_RTT_UNCACHED.aDown[BufferIndex];
//
// How we output depends upon the mode...
//
Expand Down Expand Up @@ -1084,7 +1084,7 @@ unsigned SEGGER_RTT_WriteNoLock(unsigned BufferIndex, const void* pBuffer, unsig
//
// Get "to-host" ring buffer.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
//
// How we output depends upon the mode...
//
Expand Down Expand Up @@ -1262,7 +1262,7 @@ unsigned SEGGER_RTT_PutCharSkipNoLock(unsigned BufferIndex, char c) {
//
// Get "to-host" ring buffer.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
//
// Get write position and handle wrap-around if necessary
//
Expand Down Expand Up @@ -1315,7 +1315,7 @@ unsigned SEGGER_RTT_PutCharSkip(unsigned BufferIndex, char c) {
//
// Get "to-host" ring buffer.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
//
// Get write position and handle wrap-around if necessary
//
Expand Down Expand Up @@ -1372,7 +1372,7 @@ unsigned SEGGER_RTT_PutChar(unsigned BufferIndex, char c) {
//
// Get "to-host" ring buffer.
//
pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
//
// Get write position and handle wrap-around if necessary
//
Expand Down Expand Up @@ -1479,8 +1479,8 @@ int SEGGER_RTT_HasKey(void) {
int r;

INIT();
RdOff = _SEGGER_RTT.aDown[0].RdOff;
if (RdOff != _SEGGER_RTT.aDown[0].WrOff) {
RdOff = _SEGGER_RTT_UNCACHED.aDown[0].RdOff;
if (RdOff != _SEGGER_RTT_UNCACHED.aDown[0].WrOff) {
r = 1;
}
else {
Expand All @@ -1505,7 +1505,7 @@ unsigned SEGGER_RTT_HasData(unsigned BufferIndex) {
SEGGER_RTT_BUFFER_DOWN* pRing;
unsigned v;

pRing = &_SEGGER_RTT.aDown[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aDown[BufferIndex];
v = pRing->WrOff;
return v - pRing->RdOff;
}
Expand All @@ -1526,7 +1526,7 @@ unsigned SEGGER_RTT_HasDataUp(unsigned BufferIndex) {
SEGGER_RTT_BUFFER_UP* pRing;
unsigned v;

pRing = &_SEGGER_RTT.aUp[BufferIndex];
pRing = &_SEGGER_RTT_UNCACHED.aUp[BufferIndex];
v = pRing->RdOff;
return pRing->WrOff - v;
}
Expand Down Expand Up @@ -1557,18 +1557,18 @@ int SEGGER_RTT_AllocDownBuffer(const char* sName, void* pBuffer, unsigned Buffer
SEGGER_RTT_LOCK();
BufferIndex = 0;
do {
if (_SEGGER_RTT.aDown[BufferIndex].pBuffer == NULL) {
if (_SEGGER_RTT_UNCACHED.aDown[BufferIndex].pBuffer == NULL) {
break;
}
BufferIndex++;
} while (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers);
if (BufferIndex < _SEGGER_RTT.MaxNumDownBuffers) {
_SEGGER_RTT.aDown[BufferIndex].sName = sName;
_SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;
_SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;
_SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
} while (BufferIndex < _SEGGER_RTT_UNCACHED.MaxNumDownBuffers);
if (BufferIndex < _SEGGER_RTT_UNCACHED.MaxNumDownBuffers) {
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].RdOff = 0u;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].WrOff = 0u;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].Flags = Flags;
}
else {
BufferIndex = -1;
Expand Down Expand Up @@ -1603,18 +1603,18 @@ int SEGGER_RTT_AllocUpBuffer(const char* sName, void* pBuffer, unsigned BufferSi
SEGGER_RTT_LOCK();
BufferIndex = 0;
do {
if (_SEGGER_RTT.aUp[BufferIndex].pBuffer == NULL) {
if (_SEGGER_RTT_UNCACHED.aUp[BufferIndex].pBuffer == NULL) {
break;
}
BufferIndex++;
} while (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers);
if (BufferIndex < _SEGGER_RTT.MaxNumUpBuffers) {
_SEGGER_RTT.aUp[BufferIndex].sName = sName;
_SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;
_SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;
_SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
} while (BufferIndex < _SEGGER_RTT_UNCACHED.MaxNumUpBuffers);
if (BufferIndex < _SEGGER_RTT_UNCACHED.MaxNumUpBuffers) {
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].RdOff = 0u;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].WrOff = 0u;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].Flags = Flags;
}
else {
BufferIndex = -1;
Expand Down Expand Up @@ -1653,16 +1653,16 @@ int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBu
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumUpBuffers) {
SEGGER_RTT_LOCK();
if (BufferIndex > 0u) {
_SEGGER_RTT.aUp[BufferIndex].sName = sName;
_SEGGER_RTT.aUp[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aUp[BufferIndex].RdOff = 0u;
_SEGGER_RTT.aUp[BufferIndex].WrOff = 0u;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].RdOff = 0u;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].WrOff = 0u;
}
_SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1702,16 +1702,16 @@ int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* p
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumDownBuffers) {
SEGGER_RTT_LOCK();
if (BufferIndex > 0u) {
_SEGGER_RTT.aDown[BufferIndex].sName = sName;
_SEGGER_RTT.aDown[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT.aDown[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT.aDown[BufferIndex].RdOff = 0u;
_SEGGER_RTT.aDown[BufferIndex].WrOff = 0u;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].pBuffer = (char*)pBuffer;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].SizeOfBuffer = BufferSize;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].RdOff = 0u;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].WrOff = 0u;
}
_SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1741,9 +1741,9 @@ int SEGGER_RTT_SetNameUpBuffer(unsigned BufferIndex, const char* sName) {
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumUpBuffers) {
SEGGER_RTT_LOCK();
_SEGGER_RTT.aUp[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].sName = sName;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1773,9 +1773,9 @@ int SEGGER_RTT_SetNameDownBuffer(unsigned BufferIndex, const char* sName) {
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumDownBuffers) {
SEGGER_RTT_LOCK();
_SEGGER_RTT.aDown[BufferIndex].sName = sName;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].sName = sName;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1805,9 +1805,9 @@ int SEGGER_RTT_SetFlagsUpBuffer(unsigned BufferIndex, unsigned Flags) {
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumUpBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumUpBuffers) {
SEGGER_RTT_LOCK();
_SEGGER_RTT.aUp[BufferIndex].Flags = Flags;
_SEGGER_RTT_UNCACHED.aUp[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1837,9 +1837,9 @@ int SEGGER_RTT_SetFlagsDownBuffer(unsigned BufferIndex, unsigned Flags) {
int r;

INIT();
if (BufferIndex < (unsigned)_SEGGER_RTT.MaxNumDownBuffers) {
if (BufferIndex < (unsigned)_SEGGER_RTT_UNCACHED.MaxNumDownBuffers) {
SEGGER_RTT_LOCK();
_SEGGER_RTT.aDown[BufferIndex].Flags = Flags;
_SEGGER_RTT_UNCACHED.aDown[BufferIndex].Flags = Flags;
SEGGER_RTT_UNLOCK();
r = 0;
}
Expand Down Expand Up @@ -1888,7 +1888,8 @@ int SEGGER_RTT_SetTerminal(unsigned char TerminalId) {
ac[0] = 0xFFu;
if (TerminalId < sizeof(_aTerminalId)) { // We only support a certain number of channels
ac[1] = _aTerminalId[TerminalId];
pRing = &_SEGGER_RTT.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
pRing = &_SEGGER_RTT_UNCACHED
.aUp[0]; // Buffer 0 is always reserved for terminal I/O, so we can use index 0 here, fixed
SEGGER_RTT_LOCK(); // Lock to make sure that no other task is writing into buffer, while we are and number of free bytes in buffer does not change downwards after checking and before writing
if ((pRing->Flags & SEGGER_RTT_MODE_MASK) == SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL) {
_ActiveTerminal = TerminalId;
Expand Down Expand Up @@ -1943,7 +1944,7 @@ int SEGGER_RTT_TerminalOut(unsigned char TerminalId, const char* s) {
//
// Get "to-host" ring buffer.
//
pRing = &_SEGGER_RTT.aUp[0];
pRing = &_SEGGER_RTT_UNCACHED.aUp[0];
//
// Need to be able to change terminal, write data, change back.
// Compute the fixed and variable sizes.
Expand Down Expand Up @@ -2021,7 +2022,7 @@ int SEGGER_RTT_TerminalOut(unsigned char TerminalId, const char* s) {
* Number of bytes that are free in the selected up buffer.
*/
unsigned SEGGER_RTT_GetAvailWriteSpace(unsigned BufferIndex) {
return _GetAvailWriteSpace(&_SEGGER_RTT.aUp[BufferIndex]);
return _GetAvailWriteSpace(&_SEGGER_RTT_UNCACHED.aUp[BufferIndex]);
}

/*********************************************************************
Expand All @@ -2045,13 +2046,13 @@ unsigned SEGGER_RTT_GetBytesInBuffer(unsigned BufferIndex) {
// Avoid warnings regarding volatile access order. It's not a problem
// in this case, but dampen compiler enthusiasm.
//
RdOff = _SEGGER_RTT.aUp[BufferIndex].RdOff;
WrOff = _SEGGER_RTT.aUp[BufferIndex].WrOff;
RdOff = _SEGGER_RTT_UNCACHED.aUp[BufferIndex].RdOff;
WrOff = _SEGGER_RTT_UNCACHED.aUp[BufferIndex].WrOff;
if (RdOff <= WrOff) {
r = WrOff - RdOff;
}
else {
r = _SEGGER_RTT.aUp[BufferIndex].SizeOfBuffer - (WrOff - RdOff);
r = _SEGGER_RTT_UNCACHED.aUp[BufferIndex].SizeOfBuffer - (WrOff - RdOff);
}
return r;
}
Expand Down
Loading

0 comments on commit 1dc06e1

Please sign in to comment.