Why isn’t my printf output showing on the SWV ITM console for STM32F401CDU6?

Good day @everyone I am trying to use the printf and the SWV for stm32f401CDU6 board wrote my code on the stm32cubeIDE (main.c) I have pasted the ITM funtionality code to the syscalls.c and have done the changes needed at the write function I have done my debugging using 84MHz(which is the board frequency) yet my printf code is not yet played on the SWV ITM date console(i have also done the port selection) what can I do next
25 Replies
ZacckOsiemo
ZacckOsiemo4w ago
People may need to see your code, this issue always catches me off in new projects have to spend an hour and it works
Okpara Elvis
Okpara Elvis4w ago
ok
Okpara Elvis
Okpara Elvis4w ago
i didn't use the graphic approach
attachment 0
attachment 1
Umesh Lokhande
In syscalls.c file you need to add few more lines of code at the top. Here it is
// Debug Exception & Monitor Control Register Base Address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)

//ITM Register Address
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000)
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00)

void ITM_SendChar(uint8_t ch)
{
// Enable TRCENA
DEMCR |= (1<<24);

// Enable Stimulus Port0
ITM_TRACE_EN |= (1<<0);

// Read FIFO Status in bit[0]:
while(!(ITM_STIMULUS_PORT0 & 1));

// Write to ITM Stimulus Port0
ITM_STIMULUS_PORT0 = ch;
}
// Debug Exception & Monitor Control Register Base Address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)

//ITM Register Address
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000)
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00)

void ITM_SendChar(uint8_t ch)
{
// Enable TRCENA
DEMCR |= (1<<24);

// Enable Stimulus Port0
ITM_TRACE_EN |= (1<<0);

// Read FIFO Status in bit[0]:
while(!(ITM_STIMULUS_PORT0 & 1));

// Write to ITM Stimulus Port0
ITM_STIMULUS_PORT0 = ch;
}
Okpara Elvis
Okpara Elvis4w ago
///////////////////////////////////////////////////////////////////////////////////////////////////////// // Implementation of printf like feature using ARM Cortex M3/M4/ ITM functionality // This function will not work for ARM Cortex M0/M0+ // If you are using Cortex M0, then you can use semihosting feature of openOCD ///////////////////////////////////////////////////////////////////////////////////////////////////////// //Debug Exception and Monitor Control Register base address #define DEMCR ((volatile uint32_t) 0xE000EDFCU ) /* ITM register addresses */ #define ITM_STIMULUS_PORT0 ((volatile uint32_t) 0xE0000000 ) #define ITM_TRACE_EN ((volatile uint32_t) 0xE0000E00 ) void ITM_SendChar(uint8_t ch) { //Enable TRCENA DEMCR |= ( 1 << 24); //enable stimulus port 0 ITM_TRACE_EN |= ( 1 << 0); // read FIFO status in bit [0]: while(!(ITM_STIMULUS_PORT0 & 1)); //Write to ITM stimulus port0 ITM_STIMULUS_PORT0 = ch; }
Okpara Elvis
Okpara Elvis4w ago
I have added this line of code the output is not display
Umesh Lokhande
Also, confirm if in debugger settings you have setup properly especially to enable SWV & Clock settings. In your case may change for different clock speed if you're not running @ 16MHz
attachment 0
Okpara Elvis
Okpara Elvis4w ago
Yes I have done that; enable the SWV and set clock speed to 84
Umesh Lokhande
This code seems like missing pointers to hold memory addresses. Please copy paste my suggested lines of code or compare both carefully. Following part of your code
// Debug Exception & Monitor Control Register Base Address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)

//ITM Register Address
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000)
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00)
// Debug Exception & Monitor Control Register Base Address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)

//ITM Register Address
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000)
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00)
Okpara Elvis
Okpara Elvis4w ago
ok
Okpara Elvis
Okpara Elvis4w ago
I have also used your suggested code line do you think the problem could e from the hardware And its my first time using this board
attachment 0
attachment 1
Umesh Lokhande
Unfortunately, I never used STM32 BlackPill. So it'll be difficult for me to say anything whether it's an issue with stlinkv2 clones or something
Okpara Elvis
Okpara Elvis4w ago
ok thanks for your effort
Umesh Lokhande
Welcome!
accur4te
accur4te4w ago
@Okpara Elvis did you update your clone st link programmer firmware ? If yes than u have bricked it
Okpara Elvis
Okpara Elvis4w ago
yes did
Okpara Elvis
Okpara Elvis4w ago
this there anything I can do about that?
Okpara Elvis
Okpara Elvis4w ago
but the upgrade was successful
accur4te
accur4te4w ago
yeah but few people have reported it, after the new 1.17 update if you update your firmware of the Chinese clone programmer via the stm32 cube programmer , it will be rendered it useless.
accur4te
accur4te4w ago
try using another or a new clone
Umesh Lokhande
Recently, I'm using official STLINK-V3MODS programmer and debugger at just $ 9.30 ~ ₹ 792.00. You can even solder this programmer & debugger on a custom motherboard/pcb for field update!
attachment 0
undefined.elf
undefined.elf3w ago
@Okpara Elvis is it solved? or should I help? after seeing the picture of your stlink sadly it doesn't have SWO capality
undefined.elf
undefined.elf3w ago
No description
undefined.elf
undefined.elf3w ago
you need something like this to use that see this has a SWO pin now you can change your stlink or I can give you another suggestions that use printf via UART if you need any help please mention me

Did you find this page helpful?