Problem with programming stspin32g4

Hello! I need help with programing stspin32g4 (stm32g431)
I’m basing on GitHub - runger1101001/simplefoc_funqi_example project
I’m using nucleo l476RG as stlink (connection i guess it’s ok, because STM32CubeProgrammer detects my stm)
when im trying to upload my code i got error:

No DFU capable USB device available
*** [upload] Error 74

i also tried to change upload_protocol = dfu to upload_protocol = stlink
then i get
image

my stlink works property, because if i open project with nucleo there is no problem to upload any sketch i want, please help me :slight_smile:

Any reason you are not using a standalone stlink? The clones on ebay cost £4.

On your nucleo there is usually a jumper that you have to add or remove if you want to use the innovate stlink to program a different target

When you say you have no problems uploading any sketch to nucleo, do you mean using platformio?

Maybe you can show us your platformio.ini for working nucleo and not working stspin32

This can happen if another software opened a connection to the stlink.

Yes, I know about those jumpers

Yes I’m using platformio to program nucleo with standard platformio.ini settings for that nucleo (jumpers on)

[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = arduino

and for sts (jumpers off, connected TCK TMS GND)

[env:genericSTM32G431VB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
board_build.ldscript = ./variant/ldscript.ld
upload_protocol = dfu
;upload_protocol = stlink
;debug_tool=stlink
lib_archive = false

monitor_speed = 115200
monitor_eol = LF

build_unflags = -Os
build_flags = 
    -Ofast
	-DSIMPLEFOC_STM32_DEBUG
	-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -DUSBD_USE_CDC
    -DUSBCON
    -DHAL_CORDIC_MODULE_ENABLED

lib_deps =
    adafruit/Adafruit NeoPixel@^1.11.0

it is wrong to use nucleo as stlink? i have been using this to program stspin32g4 via stm32cubeide


at 3rd “upload” it says “succes” XD
but actually it doesn’t work

void setup() {
    pinMode(PC1, OUTPUT);
}



void loop(){
    digitalWrite(PC1, 1);
    delay(100);
    digitalWrite(PC1,0);
    delay(100);
}

when i do same on stm32ide it blinks, so connections are good

it’s clear it’s not trying to use the STlink… sorry, too quick to write…

The error in your first post is an issue with libusb. Are you on an M1 mac? I had (a similar) issue and can help you fix it if so.

Are you trying to program a STSPING4 nucleo, or are you meaning you’re using a nucleo as an stlink, connected to a different MCU? Have you broken it off or are you just hanging wires off the jumpers?

i’m using windows 10, what was your problem?

I have stspin32g4 on it’s board and using nucleo as stlink (jumpers taken off) without breaking :slight_smile:

Using a nucleo is fine, but I have never tried it personally.

I take it you are using a custom board. If you were using one of the eval board (EVSPIN32G4NH or EVSPIN32G4-DUAL), they have an onboard stlink so you wouldn’t need the nucleo.

Which board are you using?

projected by me, based on EVSPIN32G4, just without programmer

It may be that the ST tools are smart enough to check for every device on the SWD chain, but that whatever PIO is doing does not check for multiple devices on chain. IN that case, you may be getting responses from the nucleo mixed in with responses from your intended board. I think if you want to use the STlink from the nucleo, you need to break it off to run the headers to your stsping4 board.

if i take off jumpers i leave nucleo’s stm32l476 disconnected

Below is my platfformio.ini for a cust stm32g431 (not stspin32g4 but similar). You might get some inspiration from it.

[env:stm32g4env]
platform = ststm32
framework = arduino
board_build.variants_dir = firmware/variants
board_build.variant = DRIVA_BOARD
board_build.hse = 8000000L
board = DRIVA_BOARD
upload_protocol = stlink
lib_archive = false
monitor_speed = 230400
monitor_eol = LF
debug_tool = stlink
debug_init_break = tbreak setup
build_flags = 
	-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
	-D HAL_FDCAN_MODULE_ENABLED
	-D CAN_DEBUG
	-D SERIAL_TX_BUFFER_SIZE=256 
    -D PIN_CAN0_RX=PA_ lib11
    -D PIN_CAN0_TX=PA_12
	-D PIN_CAN0_SHDN=PB_4
    -D CAN_HOWMANY=1

Note the lack of usb build flags. I’m using a seperate usb/fdti for serial. Perhaps the upload part can work with nucleo but the serial bit is not working.

Also I’ve specified HSE - oscillator speed. If you are using runger’s clock.c - I think it is for a 24MHz clock, whereas I’m using an 8MHz (with different clock config). I presume you are using 24Mhz so might not need it.

I’m programming it with an stlink clone (looks like this one), which can also provide power to the board. I typically connect gnd, swdio, swdclk and 3.3v).

Hey,

The problem here is that the Nucleo USB is connected to an on-board ST-Link.

So the correct setting is:
upload_protocol = stlink

You can’t use DFU to flash the chip on the Nucleo because the USB is not connected directly to the MCU.

i resolded IC and bought stlink, now it programms everytime stm32cubeide and platformIO :slight_smile:

but when I upload via platformIO it looks like code is not executed - led is not blinking, using STM32CubeProgrammer i see there is some code uploaded, when i set breakpoint, it doesn’t stop

doing same in stm32cubeIDE it ends with 100% succes

#include <Arduino.h>
// #include "SimpleFOC.h"
// #include "SimpleFOCDrivers.h"
// #include "drivers/stspin32g4/STSPIN32G4.h"


// STSPIN32G4 driver = STSPIN32G4();
// BLDCMotor motor = BLDCMotor(7);

void setup() {
    // driver.voltage_power_supply = 12.0f;
    // driver.init();
    // motor.voltage_limit = driver.voltage_limit / 2.0f;
    // motor.controller = MotionControlType::velocity_openloop;
    // motor.linkDriver(&driver);
    // motor.init();


    pinMode(PC2, OUTPUT);
    
}

void loop(){
    digitalWrite(PC2, 1);
    delay(500);
    digitalWrite(PC2, 0);
    delay(500);
    // motor.move(5.0f); // 5 rad/s open loop
    // delayMicroseconds(100); // STM32G4 is very fast, add a delay in open loop if we do nothing else
}

[image]

where should I look for the fault?

Assuming you’re using the same platformio.ini as earlier, have you tried adding
-D ARDUINO_GENERIC_G431VBTX to your build flags?

I dont’ see genericSTM32G431VB in the STSTM repo… are you using a boards.json?

i’m using genericSTM32G431VB.json https://github.com/runger1101001/simplefoc_funqi_example/tree/main/boards

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:genericSTM32G431VB]
platform = ststm32
board = genericSTM32G431VB
framework = arduino
board_build.ldscript = ./variant/ldscript.ld
upload_protocol = stlink


lib_archive = false

monitor_speed = 115200
monitor_eol = LF

build_unflags = -Os
build_flags = 
    -Ofast
	-DSIMPLEFOC_STM32_DEBUG
	-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -DUSBD_USE_CDC
    -DUSBCON
    -DHAL_CORDIC_MODULE_ENABLED
    -DHAL_LPTIM_MODULE_ENABLED
    -D ARDUINO_GENERIC_G431VBTX

lib_deps =
    adafruit/Adafruit NeoPixel@^1.11.0
    

added that build flag with no result

Huh, that is strange.

If it’s working in STM32CubeIDE this is a good sign! :slight_smile:

I can’t say why its not working for you - your hardware is probably different from the “Field Stack” board I was testing it on.

One thing to check is the clock setup. Did you make your own? The setup I created is for the field stack board, and enables the HSE (external oscillator) with the configuration that is right for that board. Depending on your board’s oscillator, you’d need a different clock setup function?

exactly, added crystal solved problem

2 Likes