Back Channel

STM32 printf over ITM Exercise

Task

This board's only serial port is wired to its cellular modem, so a debug line sent there would garble the link. Your debugger can read text from the chip another way, on ITM stimulus port 0 over the trace pin.

Print the board's boot count once on ITM port 0, with printf, like this: boots:7 read_boots() returns the count. printf hands every character it makes to a function named _write, and you write that function. The registers and bit fields are on the Datasheet tab, under CoreDebug and ITM.

Circuit

Block diagram: U1, an STM32F4, sends ITM port 0 out of its trace pin PB3 SWO to TP1, a debug probe with a trace console, and sends USART1 TX on PA9 to U2, a cellular modem, with a common ground

Pass condition

ITM port 0 shows the line once, with this board's count, and USART1 sends nothing. Trace is set up the way a real chip needs it. Each test stores its own count.

Expected output for the seven boots case: the trace console shows the one line boots:7 on ITM port 0, once after reset, and USART1 sends nothing

Notes

Your program must work whether or not a debugger set trace up before it runs. Without one, the ITM starts switched off and locked. printf is never called from an interrupt handler. A handler records an event, and main prints it.

Related challenges

Loading the interactive arena.