Stm32 G474RE + SimpleFOCShield 3.1 + AS5600 - no reaction

Hi together,

maybe you have an idea whats (not) happening, I´m all out of ideas. As shown in the title I´m running a “normal” setup to drive a BLDC (iPower GBM5108).
Before the Nucleo I used an UNO R3 and everything worked as intended. Just the I2C Pins I switched to the Arduinos SCL/SDA pins, since on A4/A5 the position/velocity is 12.49 0.00 all the time and not changing. But over SCL/SDA it works.

For having more Bytes for code I switched to Nucleo64 G474RE. After changing the VDD solder pad to 3.3V (acc. to Soldering Pads v3.x | Arduino-FOC all the rest is the same) I plugged it in and after upload there was no serial output whatsoever and no reaction of the motor, either.

Baffled, I went to Getting started | Arduino-FOC and tested the sensor. This went fine, connected to SCL/SDA correct values are streaming down (over “A4/A5” again only 12.49 and 0.00).

Step 2 - just the driver: working (I guess). The Driver ready! pops up and there is torque (no motion):
BLDCDriver3PWM(6, 10, 5, 8) delivers some torque, those are the soldered pinouts
BLDCDriver3PWM(9, 10, 11, 8) from the position control example (99% the same setup as mine) delivers a lot of torque. Disregarding wich of both is correct, it works.

Step 3 - open loop (3 PWM BLDC Driver) → big oof
for starters

  if(!motor.init()){
    Serial.println("Motor init failed!");
    return;
  }

leads to

blubb.ino:45:17: error: could not convert 'motor.BLDCMotor::init()' from 'void' to 'bool'
   45 |   if(!motor.init()){
      |       ~~~~~~~~~~^~
      |                 |
      |                 void
blubb.ino:45:17: error: in argument to unary !

exit status 1

Compilation error: could not convert 'motor.BLDCMotor::init()' from 'void' to 'bool'

so I replaced it with motor.init(); and it compiled nicely.

Also, I added Serial.println("Serial online"); after Serial.begin.

But after upload theres nothing. No reaction att all and no serial output whatsoever.
Motor, shield and sensor tested positive and there´s a Driver ready!, so the Nucleo does at least something right.
Also tested positive: commander_extend_example.ino and inline_current_sense_test.ino

I´m out of clues.

tried to run the open loop (3 PWM BLDC Driver) from “Let´s get started” again.
BLDCDriver3PWM driver = BLDCDriver3PWM(5, 10, 6, 8);

if(!motor.init()){ Serial.println("Motor init failed!"); return; }
now compiles without issues. Didn´t change anything.

it runs as intended in Debug mode. Unfortunately I don´t understand enough of the output in the server console to find the problem. Maybe it can´t be found there at all?
It´s exactly the same with the Closed Loop Example (no reaction or Serial after upload, works fine in Debug Mode).

xPack Open On-Chip Debugger 0.12.0+dev-01557-gdd1758272-dirty (2024-04-02-07:27)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V3J9M3 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.291429
Info : [stm32g4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32g4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : [stm32g4x.cpu] Examination succeed
Info : starting gdb server for stm32g4x.cpu on 50000
Info : Listening on port 50000 for gdb connections
[stm32g4x.cpu] halted due to breakpoint, current mode: Thread 
xPSR: 0x21000000 pc: 0x080093b4 msp: 0x2001ff40
Info : accepting 'gdb' connection on tcp/50000
Info : device idcode = 0x20036469 (STM32G47/G48xx - Rev 'unknown' : 0x2003)
Info : RDP level 0 (0xAA)
Info : flash size = 512 KiB
Info : flash mode : dual-bank
Info : device idcode = 0x20036469 (STM32G47/G48xx - Rev 'unknown' : 0x2003)
Info : RDP level 0 (0xAA)
Info : OTP size is 1024 bytes, base address is 0x1fff7000
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08009aac msp: 0x20020000

Serial output

TIM3-CH1 TIM4-CH1 TIM2-CH3 score: 3
TIM3-CH1 TIM8-CH1 TIM2-CH3 score: 3
TIM3-CH1 TIM16-CH1N TIM2-CH3 score: -3
TIM8-CH2N TIM4-CH1 TIM2-CH3 score: -3
TIM8-CH2N TIM8-CH1 TIM2-CH3 score: -3
TIM8-CH2N TIM16-CH1N TIM2-CH3 score: -3
TIM16-CH1 TIM4-CH1 TIM2-CH3 score: 3
TIM16-CH1 TIM8-CH1 TIM2-CH3 score: 3
TIM16-CH1 TIM16-CH1N TIM2-CH3 score: -3
STM32-DRV: best: TIM3-CH1 TIM4-CH1 TIM2-CH3 score: 3
STM32-DRV: Configuring high timer 3
STM32-DRV: Configuring high channel 1
STM32-DRV: Configuring high timer 4
STM32-DRV: Configuring high channel 1
STM32-DRV: Configuring high timer 2
STM32-DRV: Configuring high channel 3
STM32-DRV: Syncronising timers! Timer no. 3
STM32-DRV: Aligning PWM to master timer: 3
STM32-DRV: Restarting timer 3
STM32-DRV: Restarting timer 4
STM32-DRV: Restarting timer 2
MOT: Init
MOT: Enable driver.
Motor ready!
Set target velocity [rad/s]

what am I doing wrong?

I don’t understand, are you saying it works only in debug mode?

yes. It was in Arduino IDE - it compiled and uploaded, but absolutely nothing happened afterwards. Then I pressed Debugging and it worked.
Me being no electronics or IT guy (I´m a mech engineer) obviously act far outside my competence level with this. But I´m learning!

Meanwhile the issue is solved. Arduino IDE seems to be no appropriate tool for Nucleos. I now use PlatformIO and its “working” (sort of… now I have other issues to solve).
Fun Fact: PIO compiles the code I need for UNO <30kB, so buying a Nucleo was kind of “unneccessary”.

G474 cannot be compared with uno, it’s much much better.

Can you share your platformio.ini?

yep, you´re right, and I´ll stick to it since now it´s there! At least during the dev phase of the project I´m on. And I´m still bewildered by the price of that thing.

The “other issues” mentioned above are now solved, too. Adding the lib_archive = false to the platformio.ini did the job.

[env:nucleo_g474re]
platform = ststm32
board = nucleo_g474re
framework = arduino
lib_deps = askuric/Simple FOC@^2.3.4
lib_archive = false
monitor_speed = 115200

ok that’s why I wanted to see the ini file.

After this change I thought lib_archive would be automatically enabled though.

ok, it worked… twice. And then never again.
Before my post 9h ago I tested it with the angle_control example and everything went fine. No issues whatsoever.
Now I´m at a point again where it simply wont work in closed loop. It´s frustrating as hell.

Loading the sensor test is fine, loading the open loop velocity example is fine, loading angle_control…
in closed loop the motor barely moves during initialisation and then it quits.

Closed Loop Velocity example:

TIM3-CH2 TIM3-CH1 TIM2-CH3 score: 2
TIM3-CH2 TIM8-CH2N TIM2-CH3 score: -3
TIM3-CH2 TIM16-CH1 TIM2-CH3 score: 3
TIM8-CH2 TIM3-CH1 TIM2-CH3 score: 3
TIM8-CH2 TIM8-CH2N TIM2-CH3 score: -3
TIM8-CH2 TIM16-CH1 TIM2-CH3 score: 3
STM32-DRV: best: TIM3-CH2 TIM3-CH1 TIM2-CH3 score: 2
STM32-DRV: Configuring high timer 3
STM32-DRV: Configuring high channel 2
STM32-DRV: Configuring high timer 3
STM32-DRV: Configuring high channel 1
STM32-DRV: Configuring high timer 2
STM32-DRV: Configuring high channel 3
STM32-DRV: Syncronising timers! Timer no. 2
STM32-DRV: Aligning PWM to master timer: 3
STM32-DRV: Restarting timer 3
STM32-DRV: Restarting timer 2
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: Failed to notice movement
MOT: Init FOC failed.
Motor ready.
Set the target velocity using serial terminal:

Closed Loop Angle example:

MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 8.33
MOT: Zero elec. angle: 0.71
MOT: No current sense.
MOT: Ready.
Motor ready.

Build is reliably successful.
Upload gives me (all scripts mentioned above, the working open loop, too):

Uploading .pio\build\nucleo_g474re\firmware.elf
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800be30 msp: 0x20020000
** Programming Started **
Warn : Adding extra erase range, 0x08010048 .. 0x080107ff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked

and I can´t find a straw I could grab to work with for a solution. I think I switch back to the UNO. 2 days dumped an not an inch progress.

Meanwhile I tried using the STM32CubeProgrammer to flash the file. Flashing works, behaviour is the same.

Here the Debugger of the angle control example:

Processing nucleo_g474re (platform: ststm32; board: nucleo_g474re; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_g474re.html
PLATFORM: ST STM32 (17.5.0) > Nucleo G474RE
HARDWARE: STM32G474RET6 170MHz, 128KB RAM, 512KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-arduinoststm32 @ 4.20801.240815 (2.8.1)
 - framework-cmsis @ 2.50900.0 (5.9.0)
 - toolchain-gccarmnoneeabi @ 1.120301.0 (12.3.1)
Converting angle_control.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Simple FOC @ 2.3.4
Building in debug mode
Compiling [... so much compiling ...]
Archiving .pio\build\nucleo_g474re\libFrameworkArduino.a
Linking .pio\build\nucleo_g474re\firmware.elf
Checking size .pio\build\nucleo_g474re\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.7% (used 3564 bytes from 131072 bytes)
Flash: [=         ]  14.8% (used 77568 bytes from 524288 bytes)
Building .pio\build\nucleo_g474re\firmware.bin
========================= [SUCCESS] Took 19.24 seconds =========================
Reading symbols from d:\PlatformIO Projekte\sFOC_stm32\.pio\build\nucleo_g474re\firmware.elf...
Warning: 'set target-async', an alias for the command 'set mi-async', is deprecated.
Use 'set mi-async'.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target...
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 2000 kHz
Info : STLINK V3J9M3 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.277932
Info : [stm32g4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32g4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32g4x.cpu on pipe
Info : accepting 'gdb' connection from pipe
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x08007e04 msp: 0x2001ff68
Info : device idcode = 0x20036469 (STM32G47/G48xx - Rev 'unknown' : 0x2003)
Info : RDP level 0 (0xAA)
Info : flash size = 512 KiB
Info : flash mode : dual-bank
Info : device idcode = 0x20036469 (STM32G47/G48xx - Rev 'unknown' : 0x2003)
Info : RDP level 0 (0xAA)
Info : OTP size is 1024 bytes, base address is 0x1fff7000
Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (1036 ms). Workaround: increase "set remotetimeout" in GDB

//vv INTERESTING TIMER.C ISSUE
0x08007e04 in getTimerUpIrq (tim=0x22) at C:\Users\Tyandriel\.platformio\packages\framework-arduinoststm32\libraries\SrcWrapper\src\stm32\timer.c:371
371	    switch ((uint32_t)tim) {
//^^

2
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800bde4 msp: 0x20020000
Loading section .isr_vector, size 0x1d8 lma 0x8000000
Loading section .text, size 0x113b0 lma 0x80001e0
Loading section .rodata, size 0x1764 lma 0x8011590
Loading section .ARM, size 0x8 lma 0x8012cf4
Loading section .init_array, size 0x20 lma 0x8012cfc
Loading section .fini_array, size 0xc lma 0x8012d1c
Loading section .data, size 0x3ec lma 0x8012d28
Info : Padding image section 0 at 0x080001d8 with 8 bytes
Info : Padding image section 1 at 0x08013114 with 4 bytes (bank write end alignment)
2
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800dfc8 msp: 0x20020000
Start address 0x0800dfc8, load size 78092
Transfer rate: 32 KB/sec, 7099 bytes/write.
2
Info : Unable to match requested speed 2000 kHz, using 1000 kHz
2
Unable to match requested speed 2000 kHz, using 1000 kHz
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800dfc8 msp: 0x20020000
[stm32g4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800dfc8 msp: 0x20020000
Temporary breakpoint 1 at 0x800df80: file C:\Users\Tyandriel\.platformio\packages\framework-arduinoststm32\cores\arduino\main.cpp, line 50.
Note: automatically using hardware breakpoints for read-only addresses.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug

Temporary breakpoint 1, main () at C:\Users\Tyandriel\.platformio\packages\framework-arduinoststm32\cores\arduino\main.cpp:50
50	  initVariant();

This is the script it points to

/*
  main.cpp - Main loop for Arduino sketches
  Copyright (c) 2005-2013 Arduino Team.  All right reserved.
[snip]
*/

#define ARDUINO_MAIN
#include "Arduino.h"

// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated objects that need HAL may fail.
__attribute__((constructor(101))) void premain()            // <-- ### THE MENTIONED CONSTRUCTOR ###
{

  // Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html
#ifdef NVIC_PRIORITYGROUP_4
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#endif
#if (__CORTEX_M == 0x07U)
  // Defined in CMSIS core_cm7.h
#ifndef I_CACHE_DISABLED
  SCB_EnableICache();
#endif
#ifndef D_CACHE_DISABLED
  SCB_EnableDCache();
#endif
#endif

  init();
}

/*
 * \brief Main entry point of Arduino application
 */
int main(void)    // <-- ### LINE 50 ###
{
  initVariant();

  setup();

  for (;;) {
#if defined(CORE_CALLBACK)
    CoreCallback();
#endif
    loop();
    serialEventRun();
  }

  return 0;
}

Maybe somebody has an idea, where I could begin poking to find a solution. My patience has run out for now.

Edit:
same behaviour with Arduino UNO. Never thought it could be the shield. Unfortunately, they´re out-of-stock again… postponed.

SOLVED

The issue didn´t let me go, for the good of it. It was the magnet of the sensor being put directly on the shaft of the motor. After fabricating a spacer between magnet and shaft everything is fine.

1 Like