B-G431B-ESC1: Beginner guide + I2C guide

Hey Dirk,

Really not sure what is going there… I am looking into it.

I have duplicated your project setup here on my Mac, and can confirm that I get the same compilation issues.


It seems you have found a bug in the current sensing code. I’m currently not sure if it only happens in platformio, or generally for people using the STM32G4xx MCUs.

I am opening an issue in our GitHub. I’ve already made a fix.

To get around the issue, I’m afraid you either have to wait for the next SimpleFOC library release, or use the source code version of the library. I shall post some instructions how to do this in a moment, after I have uploaded my fix.

Dear Dirk,

I have merged the fix into the dev branch of the SimpleFOC library. You will either have to wait for the next release of the library, and then update your dependency, but I am not sure when the next release will be.

Or you can continue by using the source code version of the library from GitHub.

If you’ve used git before, this should not be difficult - if you’re new to git, it might be a bit of learning experience.

You will have to “clone” the simplefoc library to your local PC, and switch to the “dev” branch. Using the git command line tools for windows, you would do the following inside the “lib” folder of your project.

git clone https://github.com/simplefoc/Arduino-FOC.git
cd Arduino-FOC
git checkout dev

which will create a folder Arduino-FOC, and switch it to the dev branch. Since it is in your project’s lib folder, it will be used as a library.

Then, in platformio you would remove this line (the library dependency):

lib_deps = askuric/Simple FOC@^2.2

from the platformio.ini file, and do a “Clean” and “Build” and things should work.

One more thing:

Please also add the line

lib_archive = false

to your platformio.ini file. It is an option required for platformio, stm32 and simplefoc.

I always appreciate to learn ;-).
First, thank you for your patience and assistance. I’m glad that I could contribute unexpected to the library.
So i try to follow your instructions, and switched to the ‘dev’ branch:Bild_2021-11-01_133240

Currently I’m not really sure, what I’ve done (even if you explained very well), but I can’t see any mistakes so far.
Then I modified as advised my platformio.ini to:

[env:disco_b_g431b_esc1]

platform = ststm32

board = disco_b_g431b_esc1

framework = arduino

monitor_speed = 115200

build_flags =

-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC

-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF

lib_archive = false

I pressed the bin-Button (PlatformIO:Clean) and tried a PlatformIO:Build after.

Unfortunately still same errors as reported :crazy_face:

It’s not urgent for me, and I’m really glad to go ahead with the SimpleFOCShield and have good results and success there. :v:
So I’ll wait for the next release of the library and will give the ESC1 board then a second chance.

Enjoy your holiday!

Best regards,

Dirk

I recently updated platformio and ststm32 versions and I’m having similar compilation issues.

Compiling with -D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE no longer works, this results in the compilation error "This board does not support USB High Speed! Select 'Full Speed' in the 'Tools->USB interface' menu" Removing this define fixes the compilation. I wasn’t able to find the cause of this breakage, the specific code that throws this error has been unchanged since 2018.

Uploading the binary also ceased working. This was fixed by installing the st-link driver (STSW-LINK009). Before updating platformio/ststm32 everything worked without the driver.

Now I have some issues with serial. printf() works and spits out data at a baud rate of 9600. getchar() does not work, neither does Serial.printf(). Serial.begin(115200) also has no effect. Serial.flush() finishes in constant time, regardless of the amount of bytes placed into the send buffer. Serial.begin() takes exactly 10 milliseconds to finish, it might hit a timeout somewhere…

Can someone with a working setup copy/paste the first 20 lines of their compile output so I can see exactly which package versions are used?

Edit: I was able to upload a sketch with arduino IDE that has functional serial, with the latest package versions (framework-arduinoststm32 2.1).

Edit: I found the problem. Compiling with the flag PIO_FRAMEWORK_ARDUINO_ENABLE_CDC. silently breaks the serial terminal. Do not use this flag.

Hi, I had similar problem as you with the `-D
IO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE which I removed. The Serial.println() etc was solved by #define Serial Serial2 and keeping the PIO_FRAMEWORK_ARDUINO_ENABLE_CDC.

Have you noticed any problem with the channel 2 PWM output? Se my thread B-G431B-ESC1 is missing one PWM output signal

Regards
Anders

I did not notice any problems with the pwm output, motor/current control was working as expected.

This is my config:

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 115200
upload_protocol = stlink
lib_archive = false 

build_flags =
    -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
    -D HAL_OPAMP_MODULE_ENABLED
    -D HAL_TIM_MODULE_ENABLED

lib_deps = path to local simplefoc checkout

I’m using the latest release version (as of yesterday) of platformio, arduino, stm32. And the latest dev of simpleFOC.

1 Like

Hi everyone,

I’ve been trying to get a sensorless BLDC motor running with the B-G431B-ESC1 and have run into some issues. For reference, I’m following @Valentine’s code (Apr 19) to control the motor via the inbuilt potentiometer and have set up the environment according to @Wittecactus’s Arduino IDE guide (Mar 12).

The issue seems to be with the Opamps. I’m not connecting any sensors to the ESC for now. Here is the script of the errors:

In file included from C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:2:
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:21: error: variable or field ‘MX_OPAMP1_Init’ declared void
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
In file included from C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:7:
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:21: error: variable or field ‘MX_OPAMP1_Init’ declared void
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:42: error: ‘hopamp’ was not declared in this scope
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:21: error: variable or field ‘MX_OPAMP2_Init’ declared void
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:9:42: error: ‘hopamp’ was not declared in this scope
9 | void MX_OPAMP1_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:21: error: variable or field ‘MX_OPAMP2_Init’ declared void
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:42: error: ‘hopamp’ was not declared in this scope
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:21: error: variable or field ‘MX_OPAMP3_Init’ declared void
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:10:42: error: ‘hopamp’ was not declared in this scope
10 | void MX_OPAMP2_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:21: error: variable or field ‘MX_OPAMP3_Init’ declared void
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:42: error: ‘hopamp’ was not declared in this scope
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:21: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.h:11:42: error: ‘hopamp’ was not declared in this scope
11 | void MX_OPAMP3_Init(OPAMP_HandleTypeDef* hopamp);
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:202:24: error: variable or field ‘HAL_OPAMP_MspInit’ declared void
202 | void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:12:8: error: ‘OPAMP_HandleTypeDef’ does not name a type; did you mean ‘UART_HandleTypeDef’?
12 | static OPAMP_HandleTypeDef hopamp1;
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:202:24: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
202 | void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:202:45: error: ‘hopamp’ was not declared in this scope
202 | void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:277:26: error: variable or field ‘HAL_OPAMP_MspDeInit’ declared void
277 | void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:13:8: error: ‘OPAMP_HandleTypeDef’ does not name a type; did you mean ‘UART_HandleTypeDef’?
13 | static OPAMP_HandleTypeDef hopamp2;
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:277:26: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
277 | void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_hal.cpp:277:47: error: ‘hopamp’ was not declared in this scope
277 | void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:14:8: error: ‘OPAMP_HandleTypeDef’ does not name a type; did you mean ‘UART_HandleTypeDef’?
14 | static OPAMP_HandleTypeDef hopamp3;
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:42:22: error: variable or field ‘_configureOPAMP’ declared void
42 | void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:42:22: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
42 | void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:42:43: error: ‘hopamp’ was not declared in this scope
42 | void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef OPAMPx_Def){
| ^~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:42:65: error: expected primary-expression before '
’ token
42 | void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
| ^
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:42:66: error: ‘OPAMPx_Def’ was not declared in this scope; did you mean ‘OPAMP_TypeDef’?
42 | void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
| ^~~~~~~~~~
| OPAMP_TypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:23: error: variable or field ‘_configureOPAMPs’ declared void
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:23: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:44: error: ‘OPAMPA’ was not declared in this scope; did you mean ‘OPAMP’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~
| OPAMP
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:52: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:73: error: ‘OPAMPB’ was not declared in this scope; did you mean ‘OPAMP’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~
| OPAMP
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:81: error: ‘OPAMP_HandleTypeDef’ was not declared in this scope; did you mean ‘UART_HandleTypeDef’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~~~~~~~~~~~~~~
| UART_HandleTypeDef
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:58:102: error: ‘OPAMPC’ was not declared in this scope; did you mean ‘OPAMP’?
58 | void _configureOPAMPs(OPAMP_HandleTypeDef *OPAMPA, OPAMP_HandleTypeDef *OPAMPB, OPAMP_HandleTypeDef *OPAMPC){
| ^~~~~~
| OPAMP
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp: In function ‘void _configureADCInline(int, int, int)’:
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:87:21: error: ‘hopamp1’ was not declared in this scope
87 | _configureOPAMPs(&hopamp1, &hopamp3, &hopamp2);
| ^~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:87:31: error: ‘hopamp3’ was not declared in this scope
87 | _configureOPAMPs(&hopamp1, &hopamp3, &hopamp2);
| ^~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:87:41: error: ‘hopamp2’ was not declared in this scope
87 | _configureOPAMPs(&hopamp1, &hopamp3, &hopamp2);
| ^~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:87:3: error: ‘_configureOPAMPs’ was not declared in this scope
87 | _configureOPAMPs(&hopamp1, &hopamp3, &hopamp2);
| ^~~~~~~~~~~~~~~~
C:\Users\kevin\Documents\Arduino\libraries\Simple_FOC\src\current_sense\hardware_specific\stm32g4_mcu.cpp:103:2: error: ‘HAL_OPAMP_Start’ was not declared in this scope; did you mean ‘HAL_DAC_Start’?
103 | HAL_OPAMP_Start(&hopamp1);
| ^~~~~~~~~~~~~~~
| HAL_DAC_Start
exit status 1
Error compiling for board Discovery.

Thanks everyone, and apologies for any inconvenience caused.

Hi @Kevin_George ,

Which version of the STM32 platform are you running? There have been several updates recently…

At one point at least setting this build option helped things:
-D HAL_OPAMP_MODULE_ENABLED
but not 100% sure where this goes in Arduino IDE, maybe in platform.local.txt ?

I have tried so many things to fix the same problem, but this fixed it. How did you figure out that this line was the problem and where do you get these commands from?

Welcome @Thijs_Lenssen !

I’m really glad it helped! :slight_smile:

I can’t say there is one source - sometimes one finds things in other forum posts out there in the internet, sometimes (rarely :wink: ) there’s actually some documentation somewhere, and often its just by reading the framework code. In this case, if you follow the code you’ll find the functions and definitions needed are masked out unless that define is set.
Finding the framework code is much easier in environments like PlatformIO, where you can click on functions and jump to their definitions, than in ArduinoIDE, which hides all this code from you to keep things simple.

1 Like

Cool I am going to try and find it myself, thanks a lot!

Edit: I think I found it, but how is it possible that other header files are included while you didn’t define it? For example, the i2c header.

Edit2: I have a new fix by adding the following lines to the stm32g4xx_hal_conf.h file:

#if !defined(HAL_OPAMP_MODULE_DISABLED)
  #define HAL_OPAMP_MODULE_ENABLED
#else
  #undef HAL_OPAMP_MODULE_ENABLED
#endif

Ah, that is because these defines can come from many places…

one is your platformio.ini build_flags section, but other places include:

  • the board definition file, which may activate some options as appropriate for the board
  • the framework header files (so in the code itself) which may set some defaults for the board or MCU
  • the Arduino scripts that put everything together
  • and probably many more other places

So in this case someone decided, probably correctly, that very many users need I2C, and very many other libraries depend on it, and so this option was activated by default somewhere. And for the op-amp, they decided that hardly anyone is using it, and so it is disabled by default (to save program space and speed up compile times).

It all makes sense, it would just be great if it were better documented somewhere…

1 Like

Well they have made the following comments in the configuration file(stm32g4xx_hal_conf.h), but it’s quite hard to find:

/*

 * Optional HAL modules, can be enabled/disabled using

 * variant.h, build_opt.h or hal_conf_extra.h

 */

/*

Hi there,
I have run into the next barrier when uploading regarding OpenOCD and it is kind of similar to the one that dirk also had. Mine gives a success message instead of failed, but nothing seems to happen on the serial monitor after the uploading is finished. I have tried all my USB ports, but no success.

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_b_g431b_esc1.html
PLATFORM: ST STM32 (15.1.0) > ST B-G431B-ESC1 Discovery
HARDWARE: STM32G431CBU6 170MHz, 32KB RAM, 128KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-arduinoststm32 4.20100.211028 (2.1.0)
 - framework-cmsis 2.50700.210515 (5.7.0)
 - tool-dfuutil 1.9.200310
 - tool-openocd 2.1100.211028 (11.0)
 - tool-stm32duino 1.0.2
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Simple FOC> 2.2.0+sha.ed90016
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <SPI> 1.0
|-- <Wire> 1.0
Building in release mode
Checking size .pio\build\disco_b_g431b_esc1\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  16.4% (used 5372 bytes from 32768 bytes)
Flash: [=====     ]  52.2% (used 68480 bytes from 131072 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
Uploading .pio\build\disco_b_g431b_esc1\firmware.elf
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800a35c msp: 0x20008000
** Programming Started **
Warn : Adding extra erase range, 0x08010d90 .. 0x08010fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
========================================================================================= [SUCCESS] Took 6.88 seconds

This is my platformio.ini file:

[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
upload_protocol = stlink
build_flags =
    -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
    -D HAL_OPAMP_MODULE_ENABLED
    -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
lib_deps=
    https://github.com/simplefoc/Arduino-FOC
    SPI
    Wire
lib_archive = false

and my device manager:
image

Edit: I have no troubles uploading through arduino IDE

Hey, do you know which UART is connected to the ST-Link? Often it is UART2, in which case a

build_flags =
  -D SERIAL_UART_INSTANCE=2

would maybe help.

Hi ! I have the same problem … Have you found any solution ?
Thank you

No, I have not. I am currently using the arduino ide to upload code.

It is not working for me neither … It is said that PHASE_UL and all the other 5 phases are not declared in this scope. I don’t know if somebody already had this problem … (I don’t have this error on PlatformIo as I said just before, just like @Thijs_Lenssen describe earlier).

Ah ok, try putting ‘A_’ in front of the phases. Like A_PHASE_UL.