fix: add full ITM initialization for STM32F4 SWD trace compatibility#8
Open
Biancaa-R wants to merge 3 commits intoniekiran:masterfrom
Open
fix: add full ITM initialization for STM32F4 SWD trace compatibility#8Biancaa-R wants to merge 3 commits intoniekiran:masterfrom
Biancaa-R wants to merge 3 commits intoniekiran:masterfrom
Conversation
Refactor ITM functions and add documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For the ITM debugging ,
The implemented code didnt work on my STM32F407G Disc board .
In the initially provided code ,there is
The earlier ITM_SendChar() implementation only enabled TRCENA (DEMCR bit 24)
As it happened along the transfer. -> while (!(ITM_STIMULUS_PORT0 & 1)); wasnt set .
This patch adds an explicit ITM_Init() function that happens before hand.
Without these steps, the ITM hardware didnt work in my case.

and printf() redirection via ITM remains non-functional.
A separate ITM_Init() function has been added to perform full trace setup.
This ensures proper SWO output on STM32F407G-DISC boards under the latest
This approach maintains backward compatibility while ensuring consistent
trace output on all supported IDE versions.
(In the video it had worked on your side ,could be due to versions of STM32Cube ide not sure.)
This method works on the latest cube ide.
proof of working
The issue being:
Your ITM_SendChar() contains an initial busy-wait
// Wait until ITM TxFIFO is ready (bit 0 is 1)
while (!(ITM_STIMULUS_PORT0 & 1)); // <-- this can hang forever
//Enable TRCENA
DEMCR |= ( 1 << 24);
...
If ITM/TPIU isn't enabled yet, that first while will block forever .
Replacing the function with this safer version (still minimal, keeps your behavior but avoids the hang):
// Write to ITM stimulus port 0
// Note: The port is 32-bit, but we only write a byte.
ITM_STIMULUS_PORT0 = (uint32_t)ch;