How do you write code?

Post here first, or if you can't find a relevant section!
Post Reply
wickeline228
Posts: 2
Joined: Wed Jul 24, 2024 11:48 am

How do you write code?

Post by wickeline228 »

Do you use UART or SWD or something else to write a code? How do you see data is properly polling from a sensor, for example GPS? Do you use UART Serial.println() statements to send it to a PC or use a debugger?

Actually why I am asking is that I am trying to build a set of sensors. All sensors demand UART, so I need 6 UART & going to use SoftwareSerial for that.

I am trying to write a code using SWD and I don't know how to see incoming data using debugger without println(). Is that possible?
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: How do you write code?

Post by STM32ardui »

I upload code via SWD.
And then I can see some Serial.print() output via FTDI (there is MiniDebugger from WeActStudio, buth you have to connect it to SWD and RX/TX).

Someone asked weeks ago about SWO.
I remember something about trace messages and STM32F0/F1 may have this on pin PB3. ITM_SendChar( ... is it still vaild?

What's about debugging?
If you read values from UART into variable, it should be possible to "look" at variable content with debugger?

And what you want to do with all these data coming from 6 UART? How to prcoess them? Store it to SD card?
wickeline228
Posts: 2
Joined: Wed Jul 24, 2024 11:48 am

Re: How do you write code?

Post by wickeline228 »

STM32ardui wrote: Wed Jul 31, 2024 10:39 am I upload code via SWD.
And then I can see some Serial.print() output via FTDI (there is MiniDebugger from WeActStudio, buth you have to connect it to SWD and RX/TX).

Someone asked weeks ago about SWO.
I remember something about trace messages and STM32F0/F1 may have this on pin PB3. ITM_SendChar( ... is it still vaild?

What's about debugging?
If you read values from UART into variable, it should be possible to "look" at variable content with debugger?

And what you want to do with all these data coming from 6 UART? How to prcoess them? Store it to SD card?
I used to use the FTDI to upload code and see data is coming correctly using Serial.println() in the past. But I switched to SWD because it is, I guess, a common way to program the STM32s and I want to learn about more.
What's about debugging?
If you read values from UART into variable, it should be possible to "look" at variable content with debugger?
Yeah using debugger with SWD lets you look into variables without using Serial.println() statements. However I am not sure that it is correct way to write a code or not.
And what you want to do with all these data coming from 6 UART? How to prcoess them? Store it to SD card?
Yep, storing to the SD card.
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: How do you write code?

Post by STM32ardui »

wickeline228 wrote: Wed Jul 31, 2024 11:40 am Yeah using debugger with SWD lets you look into variables without using Serial.println() statements. However I am not sure that it is correct way to write a code or not.
Debugger is for checking code and values. Why should debugger show you wrong content of variables?
If your board is not connected to PC anymore, it is useless to output something with Serial.print().
So there is no correct or incorrect way to write code.
wickeline228 wrote: Wed Jul 31, 2024 11:40 am Yep, storing to the SD card.
Start to be creative!
If you're in doubt that sensors are not sending correct data, you can connect them one by one. So you will have free UART to connect FTDI-adapter.
If you are storing to SD card, you will use SPI interface. Without that you have 4 free pins (MOSI, MISO, CLK, CS) For a display you will need a least DC-pin but need no MISO. A display may be a way to see actual values. Or you can use a SPI to CAN-adapter and send data to PC with way.
If you have a free I2C you can use it also for display or make a connection between two STM32 boards. Board with sensors act as I2C-master, another board as I2C-slave and transmit received data via UART to Serial Monitor.
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: How do you write code?

Post by ag123 »

I think serial lines can be multiplexed, though I've not really tried it
e.g. it may be possible to take 74HC4052
https://assets.nexperia.com/documents/d ... CT4052.pdf
so that stm32 sits on the 'single' side, while the sensors sits on the 'channels' side, then that if you control that multiplexer, which requires just 2 gpios, you can switch between 4 sets of channels/lanes.
if in addition you control the /E (enable) pin, you could even use multiple 74HC4052 and multiplex 4 more sets of channels/lanes
Serial.println() is 'fine' for debugging most of the times, that is especially so if your host is say using usb(-cdc-)serial, then that you can simply Serial.println() whatever you want, add meta info (e.g. tags etc) so that you can simply observe that from the serial terminal app.

SWD / DEBUG etc is literally when you have a *bug*, and you figure out you need to trace codes / execution just to find that bug.

for after all highly complex apps like 3d printers did just that Serial.println() and manages highly complex 3d prints that can potentially have millions of lines of gcodes.

oh about multiplexing uart/serial lines, one of those things I'm yet to try is to multiplex and drive 4 Trinamic stepper drivers e.g. TMC2209
https://www.analog.com/media/en/technic ... ev1.09.pdf
Last edited by ag123 on Wed Jul 31, 2024 2:05 pm, edited 1 time in total.
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: How do you write code?

Post by ag123 »

And for 'naive' users many simply used 'libraries' taking that as a short cut.
The point with that is when you need to 'debug', you'd need to dive into that library and figure out how to add your 'debug' codes, e.g. Serial.println() etc.
Post Reply

Return to “General discussion”