beginner question

Post here first, or if you can't find a relevant section!
Post Reply
skypickle
Posts: 5
Joined: Sun Apr 03, 2022 1:33 am

beginner question

Post by skypickle »

If the blue/black pill are programmed with ST-Link Mini V2 Programmer, what is the usb port for?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: beginner question

Post by ag123 »

the usb port can be used for your sketch when you use Serial.print() or Serial.read();
and for stm32f4xx the usb port can be used to program it over usb (DFU).
skypickle
Posts: 5
Joined: Sun Apr 03, 2022 1:33 am

Re: beginner question

Post by skypickle »

so the black pill can be programmed over usb . What is DFU?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: beginner question

Post by ag123 »

have you taken a look at the wiki?
https://github.com/stm32duino/wiki/wiki
the formal STM core is here
https://github.com/stm32duino/Arduino_Core_STM32
but follow instructions in the wiki to install it.

tell us more about what you have e.g. stm32f401cc black pill etc.

stm32f4xx can be programmed with a usb cable
but u'd need to set boot0 for that, for blackpill stm32f401/f411 the button dance is
- press reset and boot0
- hold boot0, release reset
- release boot0 2 secs later.

then you can use stm32 cube programmer to program it
https://www.st.com/en/development-tools ... eprog.html
https://learn.adafruit.com/adafruit-stm ... er-details

more commonly if you have installed arduino ide (1.8.x) and stm32cube programmer and stm32duino core per the wiki
after the button dance, you can click upload (or download) to program it over the usb cable.

the first sketch to do is to blink the led on board
that is normally the 'hello world' of the duino* world.

edit:
DFU - device firmware update
https://www.usb.org/sites/default/files/DFU_1.1.pdf
stm32 has a slight difference in protocol DFU 1.1a
https://www.st.com/resource/en/applicat ... ronics.pdf
the main difference is an addition of setting the start address to load the firmware
it is possible to use dfu-util (it is easier to use this in linux)
http://dfu-util.sourceforge.net/
to program the firmware
the command normally is of the form

Code: Select all

dfu-util -a 0 -s 0x8000000 -RD sketch.bin
Last edited by ag123 on Mon Apr 04, 2022 7:52 am, edited 2 times in total.
skypickle
Posts: 5
Joined: Sun Apr 03, 2022 1:33 am

Re: beginner question

Post by skypickle »

thank you for taking the time to answer. it helps.
I had looked at the GitHub I missed but the wiki. The wiki makes it easier.
Since I use Arduino I will keep to that-having no experience writing hex/bin.
Would there be any advantage using hex/bin?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: beginner question

Post by ag123 »

in Arduino (IDE) *1.8.x*, the java version, don't use the typescript 2.x version just yet, if you select Sketch > export compiled binary
you would get a bin file in the project folder.

and you can install the bin file 'manually' using stm32 cube programmer as is illustrated in this Adafruit guide:
https://learn.adafruit.com/adafruit-stm ... er-details
for stm32f401/f411 black pill, instead of having to connect wires with reset and boot0, they are conveniently done with toggle buttons for the boot0 and reset pins.

normally, within the arduino ide, it is setting the correct 'upload method' in tools menu to 'DFU' and clicking 'upload'. but before that you have to complete the button presses so that the stm32f4xx chip is in dfu mode waiting to receive the file.

for that matter you could also purchase the stm32f405 feather board directly from Adafruit itself. It is a little pricy but that it is one of the rather well designed 'tiny' (small) boards around.
skypickle
Posts: 5
Joined: Sun Apr 03, 2022 1:33 am

Re: beginner question

Post by skypickle »

So i followed this tutorial
https://www.sgbotic.com/index.php?dispa ... page_id=49
STCube programmer is installed and can run.

My tools menu looks like this:
https://i.imgur.com/suTqBR0.png

I wrote the hello world sketch in the arduino ide,

Code: Select all

/*
  Blink onboard LED at 0.1 second interval
*/
void setup() {
  // initialize digital pin PB2 as an output.
  pinMode(PC13, OUTPUT); // LED connect to pin PC13
}
void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for 100mS
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for 100mS
}
IT compiles without error.
I put the black pill into DFU mode.
I clicked upload and got this error:

Code: Select all

Arduino: 1.8.19 (Windows 10), Board: "Generic STM32F4 series, BlackPill F401CC, STM32CubeProgrammer (DFU), Enabled (generic 'Serial'), CDC (generic 'Serial' supersede U(S)ART), Low/Full Speed, Smallest (-Os default), None, Newlib Nano (default)"

Sketch uses 23680 bytes (9%) of program storage space. Maximum is 262144 bytes.

Global variables use 3864 bytes (5%) of dynamic memory, leaving 61672 bytes for local variables. Maximum is 65536 bytes.

      -------------------------------------------------------------------

                       STM32CubeProgrammer v2.10.0                  

      -------------------------------------------------------------------







Error: Target device not found
Establishing connection with the device failed
the selected serial port Establishing connection with the device failed does not exist or your board is not connected



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
In Device manager (windows 10) under USB controllers I see a new device with a yellow triangle
'Unknown USB Device (Device Descriptor failed)'

I tried to update the driver for the device but that fails.

help
skypickle
Posts: 5
Joined: Sun Apr 03, 2022 1:33 am

Re: beginner question

Post by skypickle »

so I saved the hello world example as a compiled binary.
I successfully uploaded the bin file with STM32Cube Programmer
and it runs fine.

I went back to Arduino IDE and now it uploads the code.

It seems the board is not reliably entering DFU mode. Sometimes I just need to power cycle it (unplug from USB and replug it) and then it enters DFU mode. The best test for knowing if I am in DFU mode is to try and connect with the STM32CubeProgrammer.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: beginner question

Post by ag123 »

usb tend to stall for me as well.

In linux i used usbreset
https://github.com/jkulesza/usbreset
this thing reset the usb bus/port from the host side and enumerate devices.
it resolves the problem.

I'm not sure what works in WIndows, perhaps to disable / enable the device. If you can find a utility or means that does that in Windows do update this thread as well.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: beginner question

Post by GonzoG »

Those boards are badly designed and resetting them into DFU is tricky.
If they reset into DFU you will see "STM32 BOOTLOADER" in Windows's device manager.
Post Reply

Return to “General discussion”