PlatformIO Community

STM32F1 Compilation erring upon calling Wire library


#1

I’m working on uploading the MPU6050_tockn library example to my STM32F103C8 Blue Pill board.

Processing genericSTM32F103C8 (platform: ststm32; board: genericSTM32F103C8; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103C8.html
PLATFORM: ST STM32 > STM32F103C8 (20k RAM. 64k Flash)
HARDWARE: STM32F103C8T6 72MHz 20KB RAM (64KB Flash)
DEBUG: CURRENT(blackmagic) EXTERNAL(blackmagic, jlink, stlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 33 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Wire> 1.0
|-- <MPU6050_tockn> 1.4.0
|   |-- <Wire> 1.0
Compiling .pioenvs\genericSTM32F103C8\src\main.cpp.o
Archiving .pioenvs\genericSTM32F103C8\lib017\libWire.a
Compiling .pioenvs\genericSTM32F103C8\lib0d0\MPU6050_tockn_ID2824\MPU6050_tockn.cpp.o
Indexing .pioenvs\genericSTM32F103C8\lib017\libWire.a
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp: In member function 'void MPU6050::calcGyroOffsets(bool)':
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:71:53: error: no matching function for call to 'TwoWire::requestFrom(int, int, int)'
wire->requestFrom((int)MPU6050_ADDR, 14, (int)true);
^
In file included from C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/Wire.h:42:0,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.h:5,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:1:
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate: uint8 WireBase::requestFrom(uint8, int)
uint8 requestFrom(uint8, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note:   candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate: uint8 WireBase::requestFrom(int, int)
uint8 requestFrom(int, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note:   candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:73:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:74:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:75:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:76:21: warning: value computed is not used [-Wunused-value]
wire->read() << 8 | wire->read();
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp: In member function 'void MPU6050::update()':
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:105:52: error: no matching function for call to 'TwoWire::requestFrom(int, int, int)'
wire->requestFrom((int)MPU6050_ADDR, 14, (int)true);
^
In file included from C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/Wire.h:42:0,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.h:5,
from C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:1:
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate: uint8 WireBase::requestFrom(uint8, int)
uint8 requestFrom(uint8, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note:   candidate expects 2 arguments, 3 provided
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate: uint8 WireBase::requestFrom(int, int)
uint8 requestFrom(int, int);
^~~~~~~~~~~
C:\Users\neilb\.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note:   candidate expects 2 arguments, 3 provided
*** [.pioenvs\genericSTM32F103C8\lib0d0\MPU6050_tockn_ID2824\MPU6050_tockn.cpp.o] Error 1

When I look at this, I think the main problem is here:

C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp: In member function 'void MPU6050::calcGyroOffsets(bool)':
C:\Users\neilb\.platformio\lib\MPU6050_tockn_ID2824\src\MPU6050_tockn.cpp:71:53: error: no matching function for call to 'TwoWire::requestFrom(int, int, int)'

But this doesn’t make sense, because when I look at the API calls made and offered by the respective files, both call upon/offer the same exact fingerprint. Something isn’t right, but I’m not able to figure it out.

The same exact example builds perfectly for an AVR plarform like the Uno or Pro Micro.

Any thoughts? Thanks!


#2

It looks like the maple stm32 library doesn’t support the third parameter being used in the requestFrom calls on lines 71 and 105 of MPU6050_tockn.cpp … and there is even a comment in the TwoWire source saying that it’s a todo! :open_mouth: This is why it works with the ‘normal’ Arduino stuff, but not the Maple STM32 core… they didn’t get around to adding it! :wink:

It seems that it should be ok to remove the third parameter - (int)true - from those two calls … so try that and see how you go. The code should compile to completion at least. :slight_smile:

And Ivan, if you’re reading this… dang, this VSCode integration is COOL… being able to just ‘peek’ at the code related to function call! :sunglasses:


#3

In other words, switch from the maple core to the STM32 arduino core. http://docs.platformio.org/en/latest/platforms/ststm32.html#switching-between-arduino-cores

board_build.core = stm32 in your platformio.ini


#4

True… but don’t we then hit the DFU issues again? :laughing:


#5

Ugh right. Dilema. So the path of least resistance is to use a Maple-compatible MPU6050 library (which I hope there is) or fix the lib to work with the TwoWire from maple.


#6

I’ve looked around, and the list of STM32 platform MPU6050 libraries is dry, let alone ones with a specific implementation in mind.

I think a patch is the most likely solution. Is it just what pfeerick said about correcting the API usage?


#7

Basically the code uses true as the last parameter to send a stop condition on the bus. In software it’s implemented as

void SoftWire::i2c_stop() {
    set_sda(LOW);
    set_scl(HIGH);
    set_sda(HIGH);
}

You can also toggle the pins in software using digitalWrite() and a small delay in between. So then

		wire->requestFrom((int)MPU6050_ADDR, 14, (int) true);

becomes

		wire->requestFrom((int)MPU6050_ADDR, 14);
		//code to send stop condition here

#8

General Arduino ones will work as long as they don’t call into functions not implemented by maple. For example, https://github.com/jarzebski/Arduino-MPU6050 works out-of-the box for you.


#9

Hold on a moment… Here’s the definition and implementation in Wire.cpp. They both exist!
image


#10

And even so, the stop condition is set to true even if the (int)true parameter isn’t provided. See the implementation above the highlighted one.


#11

Are you looking at the right Wire implementation? That looks to be the stm32duino core, not the maple one. There are only two parameter function prototypes for the maple core. There is no three parameter overloading (unfortunately).

But there is on the stm32duino core, but then you hit the DFU upload issues…

EDIT: This PR on the stm32duino github suggests Maple style DFU support may be coming soon to their core…


#12

pfeerick, this problem is kinda solved now. It appears that you are correct, but I just solved the problem by removing the third parameter in the library’s source code. The library works great, as the parameter as it was used was extraneous.

I look forward to DFU mode being available on stm32duino!


#13

Beautiful! I couldn’t see any reason from the quick look I had at the code that the parameter was needed in this instance.

Yeah, I also look forward to seeing it… then we should get a more up-to-date arduino core, as well as it being the ‘official’ one! :slight_smile: Not that I’m saying there’s anything wrong with the Roger Clark one… it has served me well the times I have done STM32 arduino stuff! :slight_smile:


#14

pfeerick, thank you so much for your help, on this thread and the others I’ve initiated. You’ve really been a great resource.