How to use Printf with STM32 Microcontroller- Serial Wire Viewer (SWV)

preview_player
Показать описание
Learn how to use printf with STM32 microcontroller using STM32CubeIDE. We’ll debug STM32 using ST-LinkV2 Debugger on STM32 Nucleo Board. We’ll use Serial Wire Viewer (SWV) of STM32 MCU. As all ARM Cortex-M3+ microcontroller supports SWO and SWV feature. Printf style debugging is very popular with STM32 Microcontrollers.

[SUPPORT]

[RESOURCES]

[TIMESTAMPS]
00:00 Introduction
00:18 Altium Free Trial
00:42 Create STM32 Project
02:47 add ITM_SendChar
05:21 write printf function
07:20 Debug Settings
07:57 Add printf in program
08:50 SWV ITM Data Console
09:00 Configure trace SWV Settings
09:22 Start trace
09:42 Output on SWV Console
12:25 outro
Рекомендации по теме
Комментарии
Автор

2:52 you forgot to add it in the description

giupeppe
Автор

I found this very helpful, quickly got me using and understanding stm32 swv. Thank you very much.

oieieio
Автор

This does not seem to work on BluePill with genuine STM32F103C8T6 and genuine ST-Link V3.

undercrackers
Автор

Did the same way but output is not came
In serial monitor no output

industrialautomation
Автор

yw

#define ITM_TRACE_EN *((volatile uint32_t*)
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*)

/* Debug function for printf used in __write() */
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;
}

hligfl
Автор

Hi!
I didnt get any output. Did exactly like showed. STM stucks in while(!(ITM_STIMULUS_PORT0 & 1));
Ideas?

michav
Автор

I facing the warning that say's the 'no st-link detected ! please st-link or restatrt the debug session.' Even I followed the same steps. Plese solve the problem.

ShubhamBhosale
Автор

Hi! Great tutorial and it does work on the STM32 Nucleo board however I have the STM32f411 Blackpill board which needs to be connected to an external ST-Link v2 debugger. This doesnt print on that. From what I looked into the datasheets the memory addresses for the registers used in code that we added in the syscall is the same. Any suggestions on what to do?

adilmubashirchaudhry
Автор

Thanks for the guide! I've been having trouble getting this to work though. I'm hoping you might be able to help. I've been trying to get this setup on the b-g431-b-esc1 discovery board, which uses STM32G431CB. At this moment nothing is printing, but I have noticed while debugging that I get stuck in the ITM_SendChar() function - specifically in the while loop - while(!ITM_STIMULUS_PORT0 & 1). I'm too new to C to make sense of what's happening. Any ideas? Thanks!

Llammars
Автор

TRACE button is greyed out. What to do?

ioan
Автор

The constants used both in the video and in the comments below are erroneous. Gave no output.
I removed the extra U (??) and made all 4 bytes long (not 4.5)
#define ITM_TRACE_EN *((volatile uint32_t*)
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU)
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*)

PerOveHusy
Автор

_write is never called. And i cant figure out, where _write would be called from.

SurvivalSquirrel
Автор

It is useless to watch and waste of time

rajathg.m