Error uploading to stm32f303k8 with mbed

Hi, I’m having similar problems as a couple of other new posts, but maybe different enough to warrant a new thread. I’m using an stm32f303k8 board (stm32 in nano format) and Linux KDE Neon. I set up a project with the mbed led blink example from PlatformIO and tried to compile, but got this error message:

Error: Please specify upload_port for environment or use global --upload-port option.

I added “upload_port = /dev/ttyACM0” to my platformio.ini" as this was the device displayed when I entered a “pio device list” command. Now I get a different error. This is the last few lines:

Configuring upload protocol...
AVAILABLE: blackmagic, jlink, mbed, stlink
CURRENT: upload_protocol = mbed
Looking for upload disk...
Use manually specified: /dev/ttyACM0
Uploading .pioenvs/nucleo_f303k8/firmware.bin
*** [upload] /dev/ttyACM0/firmware.bin: Not a directory

I tried deleting the .pioenvs directory, but still got the same error message. Here is my platformio.ini

[env:nucleo_f303k8]
platform = ststm32
board = nucleo_f303k8
framework = mbed
upload_port = /dev/ttyACM0

and here is the program, unchanged from the example:

/*

*/
#include “mbed.h”

DigitalOut myled(LED1);

int main() {
while(1) {
myled = 1;
wait(1);
myled = 0;
wait(0.5);
}
}

All advice gratefully received.
Ian

PS not sure if it’s just me but I can’t see a preview of my post, so not sure if I’ve done the quotes correctly, apologies if they are wrong.

The upload protocol it’s trying to use is mbed. On these boards (e.g., Nucleo L476RG), the ST-Link V2 chip exposes the underlying µC’s flash a “USB thumb drive”. You can drag&drop firmware binaries on this “file system” to flash the µC.

So how do you flash the board? Does it expose a file system like that? If yes, then upload_port needs to be set to the path to the flash drive, e.g. /media/user/<some name>.

If you are flashing via a custom ST-Link probe or some external debugger, adapt upload_protocol appropiately, to e.g. stlink.

Refer to Redirecting...

2 Likes

Thank you Max, your solution worked. I looked in file explorer and, under “removable drives”, there was a folder called NODE_F303K8. I checked under /media/ian and the same folder was there, so I put that into the upload_port and it worked perfectly!
I’m very new to mbed (never tried it before) so still feeling my way. It seems to be much more C++ oriented than any of the Arduino boards, so I’m struggling a bit as I don’t know C++ at all, but that’s half the fun.
Thanks again,
Ian

Good to know that it works.

Actually there is a simpler way without having to specifiy upload_port. The problem is very likely that the “flash drive” was not mounted in your filesystem. In your file explorer, just click on the “NODE_F303K8” once to open it, that mounts the device. PlatformIO should then be able to flash it automatically.

Note that /dev/ttyACM0 is still important. It’s the USB-UART virtual serial device opened by the ST-Link v2. I.e., if you printf() something in your firmware, by default it sends it to the ST-Link v2 via UART, which in turn exposes it to you via /dev/ttyACM0 on 115200 baud. You can use e.g. miniterm.py /dev/ttyACM0 115200 to see the output. Cheers!

Hi Max,

Thanks for the tips, no doubt many fruitless hours saved by knowing this stuff!

But now I have another problem. After I’ve uploaded my program a few times (trying different stuff) I get an error message saying “*** [upload] No space left on device”. If I unplug the board then plug it in again, I can keep uploading, but after maybe 6 or 7 goes I get the message again. It’s as if the flash is not being erased before the program is uploaded. Do I have to do something else to make this happen? Or do I just have to unplug my board every time?..

Thanks, Ian

This exact thing happens to me all the time with every Nucleo board. I have no idea what goes wrong with the board / flasher chip… I found refreshing the board’s folder in the explorer helps (or is a placebo). Re-plugging in the board always solves the problem.

Bit of a pain in the fundamental orifice. Maybe the inestimable Mr. Kravets has a solution…

Could you try to add these lines to platformio.ini?

[env:myenv]
board = ...
upload_protocol = stlink
debug_tool = stlink

Please remove upload_port from config if you declared it before. That mbed DAPLink is so buggy.

Thanks Ivan, that worked, for the first upload anyway. Got a LOT more information messages (mostly about being unable to match requested speed), but I’ll see how I go and report back.

:wink: Ian

I think we should set stlink as default upload protocol for all STM boards not matter if they support mbed.