DaleGia/Nano33BLESensor

Nano33BLESensorExample_MicrophoneRMS.ino does not compile with ArduinoCore-mbed

DaleGia opened this issue ยท 11 comments

While the Nano33BLESensorExample_MicrophoneRMS.ino example DOES compile with the ArduinoCore-nRF528x-mbedos core, it has the following compilation error with the ArduinoCore-mbed core:

C:\Users\userx\Documents\Arduino\libraries\Nano33BLESensor-master\src/Nano33BLEMicrophoneRMS.cpp:105: undefined reference to `arm_rms_q15'

arm_math.h and the arm_rms_q15 prototype exists in the ArduinoCore-mbed core, however it appears the implementation cannot be found. Is there a work around for this?

Met the same error

libraries\Nano33BLESensor\Nano33BLEMicrophoneRMS.cpp.o: In function Nano33BLEMicrophoneRMS::read()': C:\Users\Administrator\Documents\Arduino\libraries\Nano33BLESensor\src/Nano33BLEMicrophoneRMS.cpp:105: undefined reference to arm_rms_q15'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano 33 BLE.

When using Nano33BLESensorExample_AllSensors-SerialPlotter.ino (pasted as txt-file)
Nano33BLESensorExample_AllSensors-SerialPlotter.txt

It is still a problem. is anyone able to tell what is actually missing in the "Nano33BLEMicrophoneRMS.cpp"? (pasted as txt-file)
Nano33BLEMicrophoneRMS.txt
libraries/Nano33BLESensor/Nano33BLEMicrophoneRMS.cpp.o: In function `Nano33BLEMicrophoneRMS::read()':
/Users/xxxxxx

Error message:
/Documents/Arduino/libraries/Nano33BLESensor/src/Nano33BLEMicrophoneRMS.cpp:105: undefined reference to `arm_rms_q15'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano 33 BLE.

teohz commented

I will play a necromancer - according to this: arduino/ArduinoAI#3 - using board version 1.1.6 works - I've tried myself and can confirm that it true.

For those stumbling upon this problem: The error appears if the Arduino IDE (and mbed board package version) doesn't use a toolchain which has the libarm_cortexM4l_math.a file in the compiler (usually expected in <compiler path>\arm-none-eabi\lib\libarm_cortexM4l_math.a. The Arduino-mbed core does only contain a header for the ARM math functions, but doesn't contain the implementation, that is expected to be in the compiler and then linked.

If you're using PlatformIO, you can easily fix this error by placing the .a file in the project and modifying the build_flags to do the linkage against the library file. (see here).

If you're using the Arduino IDE, you either have to roll-back to a version where that is working or do a fix yourself - find the file and line https://github.com/arduino/ArduinoCore-mbed/blob/a2c06d768f5ebb6821ae6505b2032ee58f4ef70d/boards.txt#L127 on your local computer and add

"{build.variant.path}/libs/libarm_cortexM4l_math.a"

to it (just as the other flags) and then put the libarm_cortexM4l_math.a file in the folder corresponding to https://github.com/arduino/ArduinoCore-mbed/tree/master/variants/ARDUINO_NANO33BLE/libs in the repo.

(The file is downloadable from https://github.com/ARM-software/CMSIS_5/tree/5.7.0/CMSIS/DSP/Lib/GCC)

For those stumbling upon this problem: The error appears if the Arduino IDE (and mbed board package version) doesn't use a toolchain which has the libarm_cortexM4l_math.a file in the compiler (usually expected in <compiler path>\arm-none-eabi\lib\libarm_cortexM4l_math.a. The Arduino-mbed core does only contain a header for the ARM math functions, but doesn't contain the implementation, that is expected to be in the compiler and then linked.

If you're using PlatformIO, you can easily fix this error by placing the .a file in the project and modifying the build_flags to do the linkage against the library file. (see here).

If you're using the Arduino IDE, you either have to roll-back to a version where that is working or do a fix yourself - find the file and line https://github.com/arduino/ArduinoCore-mbed/blob/a2c06d768f5ebb6821ae6505b2032ee58f4ef70d/boards.txt#L127 on your local computer and add

"{build.variant.path}/libs/libarm_cortexM4l_math.a"

to it (just as the other flags) and then put the libarm_cortexM4l_math.a file in the folder corresponding to https://github.com/arduino/ArduinoCore-mbed/tree/master/variants/ARDUINO_NANO33BLE/libs in the repo.

(The file is downloadable from https://github.com/ARM-software/CMSIS_5/tree/5.7.0/CMSIS/DSP/Lib/GCC)

Wow, thanks for sharing this! I will add these instructions in the readme when I get a chance.

Oh, actually the easier solution might be better. Per this it is already working in the latest Arduino IDE version and board package version. So, the above modification might not be necessary.

Can't test it right now though ๐Ÿ˜…

First, thank you for these examples.

 Total noob here, but this is my comment.  In arduino IDE, when compiling the 

    _Nano33BLESensorExample_proximity.ino_

 (just your text pasted into IDE from github)

 I get the following error:

`Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano 33 BLE"

C:\arduino-1.8.13\portable\sketchbook\nanoBLEsense_proximity\nanoBLEsense_proximity.ino: In function 'void loop()':

nanoBLEsense_proximity:114:63: error: call of overloaded 'writeValue(char [20], int&)' is ambiguous

             proximityBLE.writeValue(bleBuffer, writeLength);

                                                           ^

In file included from C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/BLEService.h:23:0,

from C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/BLEDevice.h:25,
from C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/local/BLELocalDevice.h:23,
from C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/ArduinoBLE.h:23,
from C:\arduino-1.8.13\portable\sketchbook\nanoBLEsense_proximity\nanoBLEsense_proximity.ino:21:

C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/BLECharacteristic.h:72:7: note: candidate: int BLECharacteristic::writeValue(const void*, int, bool)

int writeValue(const void* value, int length, bool withResponse = true);
^~~~~~~~~~

C:\arduino-1.8.13\portable\sketchbook\libraries\ArduinoBLE\src/BLECharacteristic.h:73:7: note: candidate: int BLECharacteristic::writeValue(const char*, bool)

int writeValue(const char* value, bool withResponse = true);
^~~~~~~~~~

exit status 1
call of overloaded 'writeValue(char [20], int&)' is ambiguous
`


The line it doesn't like is:
proximityBLE.writeValue(bleBuffer, writeLength);

I edit it to:
proximityBLE.writeValue(bleBuffer);

Now it compiles and runs well. I get the proximity values in the serial plotter, and I also get the BLE proximity value on my phone (using LightBlue app)

It worked for me with board version 1.3.2 (installed via Arduino IDE as "Arduino mbed OS boards"). When I got a deprecation warning I tried installing the "Arduino mbed-nano OS" board - to no avail. I got the arm_math.h problem again. I ran my project in VSCode and modified c_cpp_properties.json as shown below. Still same error. Had to roll back.

             "compilerPath": "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++",
             "compilerArgs": [
                 "-w",
-                "-nostdlib"
+                "-nostdlib", 
+                "-L. -larm_cortexM4l_math"
             ],
             "intelliSenseMode": "gcc-x64",
             "includePath": [
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/cores/arduino",
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/variants/ARDUINO_NANO33BLE",
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/cores/arduino",
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/variants/ARDUINO_NANO33BLE",
                 "~/Arduino/libraries/Nano33BLESensor/src",
                 "~/Arduino/libraries/ArduinoBLE/src",
                 "~/Arduino/libraries/arduino-timer/src",
                 "~/Arduino/libraries/Arduino_LSM9DS1/src",
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/libraries/Wire",
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/libraries/Wire",
                 "~/Arduino/libraries/Arduino_APDS9960/src",
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/libraries/PDM/src",
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/libraries/PDM/src",
                 "~/Arduino/libraries/Arduino_LPS22HB/src",
                 "~/Arduino/libraries/Arduino_HTS221/src",
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/cores/arduino/api/deprecated",
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/cores/arduino/api/deprecated",
                 "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1",
                 "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/arm-none-eabi",
                 "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/backward",
                 "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/lib/gcc/arm-none-eabi/7.2.1/include",
                 "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/lib/gcc/arm-none-eabi/7.2.1/include-fixed",
-                "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include"
+                "~/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include", 
+                "~/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/**",
+                "~/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Lib/GCC/**",
+                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/cores/arduino/mbed/cmsis/TARGET_CORTEX_M/**"
             ],
             "forcedInclude": [
-                "~/.arduino15/packages/arduino/hardware/mbed/1.3.2/cores/arduino/Arduino.h"
+                "~/.arduino15/packages/arduino/hardware/mbed_nano/2.0.0/cores/arduino/Arduino.h",
+                "~/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Lib/GCC/libarm_cortexM4l_math.a",
+                "~/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/arm_math.h"

Just a bit of an update. I have had success in solving this issue by manually including the related arm core math files in other projects.

Doing this for this library would not be ideal, as it will cause issues if this issue is ever resolved on the Arduino Mbed Core end. However seeing as it looks as if it has not been resolved for over a year now it looks unlikely.

The next release will have these files included in the library and solve this issue for now, so hold tight and wait for the next release.

Just a bit of an update. I have had success in solving this issue by manually including the related arm core math files in other projects.

Doing this for this library would not be ideal, as it will cause issues if this issue is ever resolved on the Arduino Mbed Core end. However seeing as it looks as if it has not been resolved for over a year now it looks unlikely.

The next release will have these files included in the library and solve this issue for now, so hold tight and wait for the next release.

When is the next release coming up? I was wondering if we can make the changes manually as you suggested above?

I have resolved this issue by discontinuing usage of the efficient arm math functions, and moved over to using an inefficient RMS method. I haven't tested it on a board yet as it has been a long time since I had one on hand, I should be able to test it in the next week or so. If it works fine, I will add the changes to a new release.