The `ArduinoIoTCloud-Basic` sample fails to build for Portenta C33

I will start by saying, I am able to compile, flash and successfully debug the most basic blink sketch on the Portenta C33, so I know my platform is configured correctly.

However, once I include the ArduinoIoTCloud library from Arduino. PlatformIO fails to compile the basic sample provided by the library. To confirm the sketch does not have a syntax error, I compiled the basic sample on both the Arduino IDE 2.x and the Arduino Cloud Create IDE.

When I attempt to compile the basic sample on PlatformIO, it fails to find files for compilation:

Processing portenta_c33 (platform: renesas-ra; board: portenta_c33; framework: arduino)
----------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/renesas-ra/portenta_c33.html
PLATFORM: Renesas RA (1.3.0) > Arduino Portenta C33
HARDWARE: R7FA6M5BH2CBG 200MHz, 511.35KB RAM, 2MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinorenesas-portenta @ 1.0.5 
 - tool-dfuutil-arduino @ 1.11.0 
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
Converting ArduinoIoTCloud_Basic.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 38 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoIoTCloud @ 1.13.0
|-- Arduino_ConnectionHandler @ 0.8.1
Building in release mode
Compiling .pio/build/portenta_c33/src/ArduinoIoTCloud_Basic.ino.cpp.o
Compiling .pio/build/portenta_c33/lib114/ESPhost/CEspControl.cpp.o
In file included from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/ESPhost/src/CEspControl.h:38:0,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/ESPhost/src/CEspControl.cpp:21:
/home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/lwIpWrapper/src/CNetIf.h:13:10: fatal error: EthernetDriver.h: No such file or directory

************************************************************************
* Looking for EthernetDriver.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EthernetDriver.h"
* Web  > https://registry.platformio.org/search?q=header:EthernetDriver.h
*
************************************************************************

 #include "EthernetDriver.h"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pio/build/portenta_c33/lib9b3/Ethernet/Ethernet.cpp.o
Compiling .pio/build/portenta_c33/lib9b3/Ethernet/EthernetSSLClient.cpp.o
Archiving .pio/build/portenta_c33/lib433/liblwIpWrapper.a
Archiving .pio/build/portenta_c33/libbb9/libWiFi.a
Indexing .pio/build/portenta_c33/lib433/liblwIpWrapper.a
Indexing .pio/build/portenta_c33/libbb9/libWiFi.a
In file included from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/lwIpWrapper/src/lwipClient.h:5:0,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/EthernetClient.h:5,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/EthernetC33.h:14,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/Ethernet.cpp:1:
/home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/lwIpWrapper/src/CNetIf.h:10:10: fatal error: CCtrlWrapper.h: No such file or directory

**********************************************************************
* Looking for CCtrlWrapper.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:CCtrlWrapper.h"
* Web  > https://registry.platformio.org/search?q=header:CCtrlWrapper.h
*
**********************************************************************

 #include "CCtrlWrapper.h"
          ^~~~~~~~~~~~~~~~
compilation terminated.
In file included from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/lwIpWrapper/src/lwipClient.h:5:0,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/EthernetClient.h:5,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/EthernetSSLClient.h:4,
                 from /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src/EthernetSSLClient.cpp:1:
/home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/lwIpWrapper/src/CNetIf.h:10:10: fatal error: CCtrlWrapper.h: No such file or directory

**********************************************************************
* Looking for CCtrlWrapper.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:CCtrlWrapper.h"
* Web  > https://registry.platformio.org/search?q=header:CCtrlWrapper.h
*
**********************************************************************

 #include "CCtrlWrapper.h"
          ^~~~~~~~~~~~~~~~
compilation terminated.
Compiling .pio/build/portenta_c33/lib2fb/Arduino_ConnectionHandler/Arduino_LoRaConnectionHandler.cpp.o
Compiling .pio/build/portenta_c33/lib2fb/Arduino_ConnectionHandler/Arduino_NBConnectionHandler.cpp.o
Compiling .pio/build/portenta_c33/lib2fb/Arduino_ConnectionHandler/Arduino_WiFiConnectionHandler.cpp.o
Compiling .pio/build/portenta_c33/lib964/RTC/RTC.cpp.o
Compiling .pio/build/portenta_c33/lib3eb/ArduinoMqttClient/MqttClient.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/ArduinoIoTCloud.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/ArduinoIoTCloudLPWAN.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/ArduinoIoTCloudTCP.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/CBORDecoder.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/CBOREncoder.cpp.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/lib/tinycbor/src/cborencoder.c.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/lib/tinycbor/src/cborencoder_close_container_checked.c.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/lib/tinycbor/src/cborerrorstrings.c.o
Compiling .pio/build/portenta_c33/lib607/ArduinoIoTCloud/cbor/lib/tinycbor/src/cborparser.c.o
*** [.pio/build/portenta_c33/lib114/ESPhost/CEspControl.cpp.o] Error 1
*** [.pio/build/portenta_c33/lib9b3/Ethernet/Ethernet.cpp.o] Error 1
*** [.pio/build/portenta_c33/lib9b3/Ethernet/EthernetSSLClient.cpp.o] Error 1
===================== [FAILED] Took 4.37 seconds =====================

 *  The terminal process "platformio 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

I looked at .vscode/c_cpp_properties.json and I can see entries in the include path for the folders containing the “missing” files. Interestingly, if I included them manually in the platformio.ini file, then it was able to complete the build. Unfortunately, the next problem becomes linker errors.

...
Archiving .pio/build/portenta_c33/lib607/libArduinoIoTCloud.a
Indexing .pio/build/portenta_c33/lib607/libArduinoIoTCloud.a
Archiving .pio/build/portenta_c33/libFrameworkArduino.a
Indexing .pio/build/portenta_c33/libFrameworkArduino.a
Linking .pio/build/portenta_c33/firmware.elf
.pio/build/portenta_c33/libbf8/libStorage.a(storage_retarget.cpp.o): In function `_close':
storage_retarget.cpp:(.text._close+0x0): multiple definition of `_close'
/home/zak/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v8-m.main/fpv5-sp/hard/libnosys.a(close.o):close.c:(.text._close+0x0): first defined here
.pio/build/portenta_c33/libbf8/libStorage.a(storage_retarget.cpp.o): In function `_write':
storage_retarget.cpp:(.text._write+0x0): multiple definition of `_write'
/home/zak/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v8-m.main/fpv5-sp/hard/libnosys.a(write.o):write.c:(.text._write+0x0): first defined here
.pio/build/portenta_c33/libbf8/libStorage.a(storage_retarget.cpp.o): In function `_read':
storage_retarget.cpp:(.text._read+0x0): multiple definition of `_read'
/home/zak/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v8-m.main/fpv5-sp/hard/libnosys.a(read.o):read.c:(.text._read+0x0): first defined here
.pio/build/portenta_c33/libbf8/libStorage.a(storage_retarget.cpp.o): In function `_lseek':
storage_retarget.cpp:(.text._lseek+0x0): multiple definition of `_lseek'
/home/zak/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v8-m.main/fpv5-sp/hard/libnosys.a(lseek.o):lseek.c:(.text._lseek+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/portenta_c33/firmware.elf] Error 1
===================== [FAILED] Took 9.21 seconds =====================

 *  The terminal process "platformio 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

Instead of slogging through it on my own, I thought it was best to report here and get advice from the experts.

Cheers,
Zak

NOTE: In case it helps, here is the compile command from the build log of the Arduino IDE 2.x, so you can compare and contrast which build flags and defines it is using to compile.

/home/zak/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -c -Wall -Wextra -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD -nostdlib -DF_CPU=200000000 -MMD -std=gnu++17 -mcpu=cortex-m33 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -DARDUINO=10607 "-DPROJECT_NAME=\"/tmp/arduino/sketches/1BA883498A5D9CC7DF51698757F9B440/ArduinoIoTCloud_Basic.ino\"" -DARDUINO_PORTENTA_C33 -DARDUINO_ARCH_RENESAS_PORTENTA -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE=700 -mthumb @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/defines.txt -DLWIP_DNS=1 -DCFG_TUSB_MCU=OPT_MCU_RAXXX -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/tinyusb -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino/api/deprecated-avr-comp -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/cores/arduino -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33 -I/home/zak/Development/Arduino/libraries/ArduinoIoTCloud/src -I/home/zak/Development/Arduino/libraries/Arduino_ConnectionHandler/src -I/home/zak/Development/Arduino/libraries/Arduino_DebugUtils/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/WiFi/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/lwIpWrapper/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/ESPhost/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/Ethernet/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/SE05X/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/SSLClient/src -I/home/zak/Development/Arduino/libraries/ArduinoMqttClient/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/RTC/src -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/Wire -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/BlockDevices -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/FATFilesystem -I/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/Storage -iprefix/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5 @/home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/variants/PORTENTA_C33/includes.txt /home/zak/.arduino15/packages/arduino/hardware/renesas_portenta/1.0.5/libraries/ESPhost/src/CEspControl.cpp -o /tmp/arduino/sketches/1BA883498A5D9CC7DF51698757F9B440/libraries/ESPhost/CEspControl.cpp.o

From a quick scan of the compilerArgs in c_cpp_properties.json, PlatformIO appears to be missing the following flags:

           "-fno-use-cxa-atexit",
           "-fno-rtti",
           "-fno-exceptions",
           "-MMD",
           "-nostdlib",
           "-std=gnu17",
           "-fsigned-char",
           "-ffunction-sections",
           "-fdata-sections",
           "-fmessage-length=0",
           "-fno-builtin",

PlatformIO correctly includes this per this. The rest is auto-included from the cflags.txt, cxxflags.txt etc files per code in the same file.

Cna you show your current platformio.ini?

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

[env:portenta_c33]
platform = renesas-ra
board = portenta_c33
framework = arduino

; Build Options
build_flags =
	-Wall
	-Wextra
	; -Wpedantic
	; -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
	; -D RELEASE
	; -O3
	; hack
	; -I /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/ESPhost/src
	; -I /home/zak/.platformio/packages/framework-arduinorenesas-portenta/libraries/Ethernet/src
	-Og
lib_deps =
	ArduinoIoTCloud

; Upload Options
	upload_protocol = jlink

; Debug Options
	; https://community.platformio.org/t/arduino-portenta-c33-jlink-flash-problem/37346
	; correct microcontroller (r7fa6m5bh)
	debug_tool = jlink
	debug_init_break = tbreak setup

Sublibraries of ArduinoIoT are correctly found if the LDF search mode is set appropriately.

[env:portenta_c33]
platform = renesas-ra
board = portenta_c33
framework = arduino
lib_ldf_mode = deep+
lib_deps =
	arduino-libraries/ArduinoIoTCloud@^1.13.0

but indeed the linking errors remain, libnosys with its stub implementation of the syscalls conflicts with the Storage library which want to give it an actual implementation. Let’s see how the Arduino IDE does it…

1 Like

Thanks @maxgerhardt!

If you would, can you please explain a little more about lib_ldf_mode = deep+, as well as why I would not always want that flag in my .ini file?

Cheers,
Zak

The docs will do a better job than me in explaining that, I’ve linked them above.

The linking issue seems to be a bit more involved though. I’ve opened issue https://github.com/platformio/platform-renesas-ra/issues/20 for that.

1 Like

Apparently the issue was just newlib and -nostdlib and it was fixed in the latest version.

Can you crosscheck with the platformio.ini

[env:portenta_c33]
platform = https://github.com/platformio/platform-renesas-ra.git#7e1a2b53e3d648341b4309aaa8db31b10523093d
board = portenta_c33
framework = arduino
lib_ldf_mode = deep+
lib_deps =
	arduino-libraries/ArduinoIoTCloud@^1.13.0

? If this works, you also don’t need modifciations regarding JLink device name, since that commit has that fixed too.

The platform URL works perfectly. Thanks for all the help!