STM32 (stm32f103c8) Serial wire debug -- STM32CubeIDE
HTML-код
- Опубликовано: 7 фев 2025
- In this video I'm showing how to setup the STM32 serial wire debug and to use it as a serial monitor for displaying data from the microelectronic on the debugging console in the STM32CubeIDE
Project code : github.com/fox...
Thank you so much for this video! It's such a great help for all my debugging. Thank you again!
Great detailed step-by-step explanation!
IT worked very well...Thank you sooo much :)
I'm glad it helped :) .
Thank you very much for your video...
I was looking for something like this thank you
Amazing, can you explain why we needed the 220 resistor?
Thanks. I don't remember exactly but it should be for restricting the current.
@@OussamaOusmoi Thank you🙏
How are printfs via ITM different than printfs over SWV?
I thought both use SWD+SWO, yet ITM_SendChar() doesn't work for me, despite have an SWD+SWO compatible chip and debugger!
Does GDB / OpenOCD support this?
Sincerely i never heard of ITM till now :), it looks very similar to the method i used in my video though .
I still didn't have the chance to try OpenOCD as well.
Sorry i can't help you much on this.
if you got any results it would be great if you share it with us :).
Good lucj
Now why can't you do that with a simple Serial Wire method? It really drives me nuts that I have to include so much unreadable garbage code to my main program in order to trace some variables.
I want to be able to use is in a compact and neat way that doesn't mess up readability of my program.
Maybe you can write the extra code in a separate header, and include it in your main program, that way you will only call the print function in your main program.
@@OussamaOusmoi then why doesn't everyone else do It? I'm an electronic engineer and every time dealing with code I just wonder what a weird mindset programmers have, they seem to never strive for compact, neat and readable coding method.
@@andrewFJ I agree with you, but for tutorials we tend to put all in one file as a simplification for the videos. You are free to structure your code as you like though :)
@@OussamaOusmoi Anyways thanks for your video, at least it explains something. Just one more question, perhaps if I debug my MCU via USB can I get messaged back or the "trace asynchronous SW" is the only way?
@@andrewFJ Via USB it will act as COM port, and you could use it as a serial dongle, however it needs extra setup for the project, you may search for serial communication for stm32 microcontrollers .
Good luck .
Thank you it works
You're welcome!
Is it possible to capture this data with some external app. For example if I wish to visualize my data via python script, and I still wish to avoid using the USB2Serial dongle, could I somehow capture the data sent to this port via python script?
It's probably possible using openocd and pyocd , but i wouldn't recommend going that path, as the SWD is only intended for debugging purposes, not for communication .
I would suggest looking at virtual serial implementation on STM32 microcontrollers using something called CDC.
check out a youtube channel called Controllers Tech, he has a good video on that .
once you have implemented that, you can then easily use pyserial to communicate with the device .
Good luck.
Hi! thanks a lot for the detailed walk-through. I'm working with stm32f4 discovery board with 168 MHz core clock. I did whatever you mentioned in the video and still I get nothing in my SWV console and timline graph. Can anyone give me any idea why this thing is not working?
Hi, is the st-link programmer integrated with the board ?
I just googled the board, and it looks like it has an integrated st-link, i wonder if the swdo pin not used, you can try using an external st link if you have, check out this link electronics.stackexchange.com/questions/230036/problems-connecting-st-link-v2-and-stm32f4-discovery-board
Hi, thanks for the reply. The st-link is indeed provided with the board. It is also detected via the debugger (The scan option). However, my "printf"s dont appear in the SWV console and my global variable "counter" does not appear on the SWV timelime graph s.th. I can however see it changing in the live expression section, top right of the CubeIDE.
Can I somehow route the output to a file instead to the console?
mmm, I'm not sure about that, as this meant to be for debugging purpose mostly. You probably need to use a serial to usb in this case, and dump the serial data to a file.
I did everything as instructed but now I get this error:
"Error in final launch sequence:
Failed to start GDB server
Failed to start GDB server
Error in initializing ST-LINK device.
Reason: (18) Could not verify ST device! Abort connection"
Is there something I'm missing?
In what step do you get this error exactly ?.
are you able to program the STM32 normally ?.
@@OussamaOusmoi I am able to flash code to the STM 32 normally. But when I try to run debug I get this error.
I wanted to debug with printf.
@@wangere7697 Checkout this link community.st.com/s/question/0D50X0000BUjpxvSQB/error-in-initializing-stlink-device-reason-18-could-not-verify-st-device-abort-connection
It seems like other people getting similar error and it looks like it's probably due to a counterfeit board . do you have other board to try with ?
@@OussamaOusmoi Thank you.
I am expecting some few boards this week.
@@OussamaOusmoi Thank you.
I am expecting some few boards this week.
Hi, amazing it worked, and could we use St link/V2/01-0 i.e the big programmer to program the same in Blue pill?
Yes you could use the big programmer as well, and it does support the SWD out of the box .
Tx!
while soldering the wire to pin on stlink I fucked it up badly, my hands were shaking so much that all the pins on stlink got attached together due to solder and now my stlink is not working XD. I have order 2 other stlinks V2 to test on them but can u give me anytips how to solder wire on IC pin so I don't fuck it up again ?
Oh no dude , sorry to hear that... :) . but yeah the IC has a bit small footprint .
I usually use more flux, and I put very little solder at the tip of the wire, and tack it down to the pin .
Maybe try practice first on some scrap pcb if you have
Good luck :)