Program an STM32F411 with an Raspberry Pi

Post here first, or if you can't find a relevant section!
Sparky
Posts: 8
Joined: Tue Jun 27, 2023 9:34 am

Program an STM32F411 with an Raspberry Pi

Post by Sparky »

Hello everyone,

I'm currently trying to program (upload a code) a STM32F411CEU6 board and a NUCLEO-F103RB with an Raspberry Pi 4, in Raspbian OS.
To get started I install Arduino IDE on the Raspberry Pi, then I configure the settings and add the following link in the "Additional Boards Manager URLs" : https://GitHub.com/stm32duino/BoardMana ... index.json
And I could add the associated STM32duino package.
I did select the appropriated STM32 board to the IDE before uploading the code. The problem is that I could successfully upload the code (no error message) on the board but It doesn't really execute properly. The code is pretty simple : LED blinking and print a message on the serial monitor.

After that, I found the following link :
https://raw.githubusercontent.com/koend ... index.json

where I could successfully upload and execute a code on the NUCLEO-F103RB but not on the STM32F411 board.
And my big questions are : why I could upload a code on the NUCLEO-F103RB and not on the STM32F411 board ? what can I do/try to upload a code AND execute It correctly on STM32F411CEU6 board ?

Take note, that the first link work on an Windows OS because I could successfully upload and execute a code on both board and many others.

I didn't find many website that talk about uploading a code from an Rasppbery Pi 4 to an STM32, so I hope this forum can help me.

Thank you in advance for your help :)

P.S: It's my first time posting a subject on a forum, if there is anything wrong in my post, please let me know.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Program an STM32F411 with an Raspberry Pi

Post by GonzoG »

Nucleo board have a built-in ST-Link programmer and you probably used it to flash board.
F411 board (probably "black pill") does not have one. You need to manually reset board into bootloader mode and use DFU as an upload method.
Sparky
Posts: 8
Joined: Tue Jun 27, 2023 9:34 am

Re: Program an STM32F411 with an Raspberry Pi

Post by Sparky »

Hello,

Actually I asked the same question to the STM32 technical support and what I understand is that Nucleo board by default uses "Mass Storage" a feature of ST-Link V2.1 and other boards use boards based on STM32CubeProgrammer, or other mainly community-based methods.
As there is no version of STM32CubeProgrammer for ARM architecture (like an Raspberry Pi) or for other methods but on the other hand, he think that "Mass storage" method will work for an ARM architecture like an Raspberry Pi (which actually did).

The partial solution that he gave me is to build the binary and externally download it.
Exporting binary can be done in Arduino IDE by doing "Sketch">"Export compiled Binary". Loading the binary can be done by different methods (ST-Link, usb-dfu, uart), so there are also different open command line solutions for downloading; I list them (https://packages.debian.org/bookworm/stlink-tools, https://packages.debian.org/bookworm/dfu-util, https://packages.debian.org/bookworm/stm32flash respectively); all should have version for ARM architecture.
This is his solution to upload a code from an Raspberry Pi.

GonzoG I think you were right about using DFU as an upload method. I'm currently trying it but didn't succeed...I don't know If you have any good link about this method (altough I'm searching for it too :) ).
Last edited by Sparky on Fri Jun 30, 2023 9:18 am, edited 2 times in total.
hobbya
Posts: 49
Joined: Thu Dec 19, 2019 3:27 pm
Answers: 1

Re: Program an STM32F411 with an Raspberry Pi

Post by hobbya »

You are not alone regarding the frustration to enter DFU mode with STM32F411. There is a workaround below:
viewtopic.php?t=1680

Here is a bit explanation about the problem associated with HSI.
https://www.st.com/resource/en/applicat ... ronics.pdf
Read p.143.
Sparky
Posts: 8
Joined: Tue Jun 27, 2023 9:34 am

Re: Program an STM32F411 with an Raspberry Pi

Post by Sparky »

Hello,

Thank you Hobbya for the two link that you provided me. I will come back to let you know If the proposed solution did work for me or not :) .
The part about HSI seems to be very complicated, hope I don't have to deal with the clocks... :roll:
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Program an STM32F411 with an Raspberry Pi

Post by ag123 »

for Nucleo based boards you can probably use something like
https://github.com/stlink-org/stlink
as Nucleo based boards has an on-board st-link chip

for the 'black pill' STM32F411CE type of boards, either get a standalone st-link v2 programmer
https://www.adafruit.com/product/2548
https://www.st.com/en/development-tools/st-link-v2.html

and link up the SWD wires appropriately

or if you want to use DFU, it is built in:
you need something like DFU util
https://dfu-util.sourceforge.net/

and the 'ritual;' and button dance is something like
get ready the command

Code: Select all

dfu-util -RD -a 0 -s 0x8000000 mysketch.bin
- press both reset and boot0
- release reset but hold boot0
- release boot0 1 sec later
hit enter for the command and it should flash away
- press reset and your sketch should run

if you want usb-CDC-serial remember to select it when you build your sketch so that it would appear as a 'virtual com port' in linux /dev/ttyACMx, /dev/ttyUSBx etc
Sparky
Posts: 8
Joined: Tue Jun 27, 2023 9:34 am

Re: Program an STM32F411 with an Raspberry Pi

Post by Sparky »

Hello ag123,

Thank you for your explanation.
In our case we have made a customize board based on the STM32F411CEU6, which is more simple than a "black pill".
For exemple, If we want to use the DFU upload method , our board doesn't have a micro-USB port but we have acess to all the STM32F411CEU6 pins.
Do you know If I'ts possible to use DFU with only the pinout of the STM32 ?

Thank you in advance for your response.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Program an STM32F411 with an Raspberry Pi

Post by GonzoG »

@Sparky
mini/micro USB is just a connector. You don't need it to use USB. Just connect D+, D- and GND.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Program an STM32F411 with an Raspberry Pi

Post by ag123 »

Aliexpress is my favourite to look for such board hacks :
https://www.aliexpress.com/w/wholesale- ... o-dip.html

like @GonzoG mentioned, find the D+ , D-, GND and 5V lines (normally goes to a LDO to power your board) and maybe hook up with one of those micro-usb to DIP adapter. 5V could be optional if you are powering it externally.
then you can simply connect a micro USB cable that is used to charge mobile phones.

next, set boot0 (pull it high to 3.3v), and press reset
that should leave it in DFU mode if no other things such as uart is connected.

after that dfu-util steps are the same.

Alternately, if you know how to get the RPi UART to work, and you can turn that in to a /dev/ttySx com port, you could also use uart to upload firmware (I think normally pins PA9 TX, PA10 RX and GND)

there is this 'old' python code that I've used for a long time
https://github.com/jsnyder/stm32loader

The boot0 and reset steps are the same.

Or alternately if you use an ST-Link V2 dongle as discussed earlier and wire up the SWD lines, it is mostly just press reset once and connect away.
you could do without messing with boot0.
Sparky
Posts: 8
Joined: Tue Jun 27, 2023 9:34 am

Re: Program an STM32F411 with an Raspberry Pi

Post by Sparky »

Hello guys,

Sorry for the late response.
Thank you for your responses.
I found a ST link V2 device, I will try to upload with this method.
But I will also try the DFU method If it doesn't work properly.
And I will comeback with my feedback on it.

Thanks,
Post Reply

Return to “General discussion”