RP2040 Connect + PlatformIO + RP2040_RTC build failure

@khoih-prog created a great library for using the RTC in the Arduino RP2040 Connect. It works great when building from the Arduino IDE (1.8), however when I try to build the same example in PlatformIO IDE it fails.

Disclaimer: I am new to PlatformIO, Arduino and the whole world of microcontrollers.

I opened an issue in the GitHub repository as well, however as it seems like a problem with PlatformIO builds probably it’s better to ask here :slight_smile:

I was trying to run the WifiNINA example from the PlatformIO IDE but the build fails like this:

In file included from include/defines.h:69,
                 from src/main.cpp:24:
.pio/libdeps/nanorp2040connect/RP2040_RTC/src/RP2040_RTC.h:48:28: error: 'datetime_t' was not declared in this scope
   48 |   bool rtc_set_datetime   (datetime_t *t);

If I run the exact same code (copying to code from src/main.cpp to the ino file in a new sketch) in the Arduino IDE it works without issues.

datetime_t is definied in the pico-sdk in the types.h header and it seems to be included in a later stage of the build because if I define the struct in my code for testing, the build fails with duplicate definitions.

In file included from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_base/include/pico.h:16,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/objects.h:30,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/device.h:35,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/platform/include/platform/platform.h:28,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/platform/include/platform/FileHandle.h:25,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/macros.h:41,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/variants/NANO_RP2040_CONNECT/pins_arduino.h:2,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/Arduino.h:76,
                 from .pio/libdeps/nanorp2040connect/WiFiNINA_Generic/src/WiFiClient_Generic.h:56,
                 from .pio/libdeps/nanorp2040connect/WiFiNINA_Generic/src/WiFi_Generic.h:76,
                 from .pio/libdeps/nanorp2040connect/WiFiNINA_Generic/src/WiFiNINA_Generic.h:60,
                 from include/defines.h:70,
                 from src/main.cpp:24:
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_base/include/pico/types.h: At global scope:
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_base/include/pico/types.h:77:3: error: conflicting declaration 'typedef struct datetime_t datetime_t'
   77 | } datetime_t;
      |   ^~~~~~~~~~

Steps to reproduce

  1. Create a new project, use the following config:

platformio.ini:

[platformio]
default_envs = nanorp2040connect

[env:nanorp2040connect]
platform = raspberrypi
board = nanorp2040connect
framework = arduino
upload_port = /dev/cu.usbmodem145201 ; change this to yours
lib_ldf_mode = deep+
lib_compat_mode = off ; I had to turn this off to be able to install RP2040_RTC (see platforms in library.json)
lib_deps =
	paulstoffregen/Time@^1.6.1
	khoih-prog/WiFiNINA_Generic@^1.8.13
	khoih-prog/RP2040_RTC@^1.0.5
	khoih-prog/Timezone_Generic@^1.7.1
  1. If dependencies are not installed, run pio lib install.
  2. cp .pio/libdeps/nanorp2040connect/RP2040_RTC/examples/Time/RP2040_RTC_Time_WiFiNINA/RP2040_RTC_Time_WiFiNINA.ino src/main.cpp
  3. cp .pio/libdeps/nanorp2040connect/RP2040_RTC/examples/Time/RP2040_RTC_Time_WiFiNINA/defines.h include/
  4. Modify wifi settings in define.h
  5. pio run --target upload → build will fail

Versions

  • PlatformIO version: 5.2.1 (I tried with 5.2.2a1 as well, same results)
  • RP2040 Core Version: Arduino-mbed 2.4.1
  • RP2040 Board type NANO_RP2040_CONNECT
  • Darwin Viktors-MBP.localdomain 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64

Log output

It is in the GitHub issue (I cannot add more links :frowning:

Many thanks for your help guys! Let me know if I missed something.

No. Doing the .ino.cpp conversion that way was nearly correct by chance (no problems with function forward declarations in that .ino file), but then you’re missing out on the most important thing: #include <Arduino.h> must be the first include in the source file. See documentation.

That way pico/types.h gets pulled in and the 'datetime_t' was not declared error gets resolved.

Sadly the library isn’t written in a correct way. If you look at the header file, it just starts referencing types which it has previously not included, like datetime_t in the main header. The library relies on always being used with the Arduino IDE (which always automatically puts #include <Arduino.h> as the first line and thus saves the library) or the user puts that line there.

That is also part of the problem, I address this in Correct platform name by maxgerhardt · Pull Request #2 · khoih-prog/RP2040_RTC · GitHub.

Getting this library to compile is currently a bit… messy. It has a trillion (conditional) dependencies which PlatformIO can’t quite figure out. lib_ignore helps here.

So, If I follow your reproduction steps but use the platformio.ini with

[env:nanorp2040connect]
platform = raspberrypi
board = nanorp2040connect
framework = arduino
lib_ldf_mode = chain+
lib_compat_mode = strict
lib_deps =
   paulstoffregen/Time@^1.6.1
   khoih-prog/WiFiNINA_Generic@^1.8.13
   https://github.com/maxgerhardt/RP2040_RTC.git#patch-1
   khoih-prog/Timezone_Generic@^1.7.1
   ;khoih-prog/RP2040_RTC@^1.0.5  ; currently not working with lib_compat_mode
lib_ignore =
   WiFi101
   WiFiEspAT
   WiFi
   ESP_AT_Lib
   ESP8266_AT_WebServer
   EthernetENC
   Ethernet2
   Ethernet3
   EthernetLarge
   Ethernet
   WiFiWebServer
   EthernetWebServer

and add #include <Arduino.h> as the first line in the .cpp file, I get

>pio run
Processing nanorp2040connect (platform: raspberrypi; board: nanorp2040connect; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/nanorp2040connect.html
PLATFORM: Raspberry Pi RP2040 (1.3.0+sha.7601172) > Arduino Nano RP2040 Connect
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd)
PACKAGES:
 - framework-arduino-mbed 2.4.1
 - tool-rp2040tools 1.0.2
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain+, Compatibility ~ strict
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Time> 1.6.1
|-- <WiFiNINA_Generic> 1.8.13
|   |-- <SPI>
|-- <RP2040_RTC> 1.0.5+sha.812dde1
|   |-- <Time> 1.6.1
|-- <Timezone_Generic> 1.7.1
|   |-- <Time> 1.6.1
|   |-- <DS323x_Generic> 1.2.2
|   |   |-- <Time> 1.6.1
|   |   |-- <WiFiNINA_Generic> 1.8.13
|   |   |   |-- <SPI>
|   |-- <WiFiNINA_Generic> 1.8.13
|   |   |-- <SPI>
Building in release mode
[...]
Linking .pio\build\nanorp2040connect\firmware.elf
Generating UF2 image
elf2uf2 ".pio\build\nanorp2040connect\firmware.elf" ".pio\build\nanorp2040connect\firmware.uf2"
Checking size .pio\build\nanorp2040connect\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  19.3% (used 52144 bytes from 270336 bytes)
Flash: [          ]   4.8% (used 100812 bytes from 2097152 bytes)
Building .pio\build\nanorp2040connect\firmware.bin
============== [SUCCESS] Took 16.20 seconds ==============

Hi @maxgerhardt,

That is just amazing :slight_smile: Both the result and the level of explanation, hats off, really!

TBH I did not know about lib_ignore until now, it’s really useful.

Thanks again!

Best,
Viktor

Great to hear that it’s working now!

If the library.json and code is correct regarding declaring and including the only-needed dependencies, and the PlatformIO-core correctly filters out the undeclared / unneeded ones, lib_ignore hacks shouldn’t have been needed in the first place – library inclusion should just work. I’ll dig into this later on why PlatformIO has problems there, the problem source must be in one of these three. Related libraries from that author have similiar problems.

1 Like

Yeah, now I’ve read how the LDF works and tries to figure out what dependencies are needed it is much more clear. I still do not get how I missed the #include <Arduino.h> part though :smiley:

Thanks again!

Hi Max, guys,

It was a bit too premature to say it works as the code builds (the new version of the lib fixed the platform naming issue) but it cannot configure the RTC. When I build & upload the code with the Arduino IDE (1.8) it works and the following warnings are not shown (this is the only difference that I found in the outputs:

In file included from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/platform_defs.h:12,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/pico_platform/include/pico/platform.h:12,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_base/include/pico.h:19,
                 from /Users/efpe/.platformio/packages/framework-arduino-mbed/variants/NANO_RP2040_CONNECT/double_tap_usb_boot.cpp:2:
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h: In function 'uint32_t time_us_32()':
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:66:12: note: in expansion of macro 'timer_hw'
   66 |     return timer_hw->timerawl;
      |            ^~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h: In function 'bool time_reached(absolute_time_t)':
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:110:19: note: in expansion of macro 'timer_hw'
  110 |     uint32_t hi = timer_hw->timerawh;
      |                   ^~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/efpe/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:111:33: note: in expansion of macro 'timer_hw'
  111 |     return (hi >= hi_target && (timer_hw->timerawl >= (uint32_t) target || hi != hi_target));
      |                                 ^~~~~~~~

The is the output I get from the serial console when I build with PlatformIO

13:04:31.792 -> Start RP2040_RTC_Time_WiFiNINA on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
13:04:31.792 -> RP2040_RTC v1.0.6
13:04:32.515 -> Please upgrade the firmware
13:04:32.515 -> Connecting to WPA SSID: xxx
13:04:35.829 -> You're connected to the network, IP = xxxxx
13:04:36.829 -> Packet received
13:04:36.829 -> Seconds since Jan 1 1900 = 3844757075
13:04:36.829 -> Unix time = 1635768275
13:04:36.829 -> rtc_set_datetime failed
13:04:37.343 -> rtc_set_datetime failed [repeated multiple times until the loop ends]
13:04:41.835 -> The UTC time is 12:04:35
13:04:41.835 -> ============================
13:04:41.835 -> 00:00:00 Tue 31 Dec 2047 UTC
13:05:42.250 -> ============================

I’ve uploaded the full logs to a gist here: PlatformIO RP2040 RTC build issues · GitHub

I appreciate any help!

Thanks,
Viktor

Very important: Do you use the GitHub - arduino/ArduinoCore-mbed core or GitHub - earlephilhower/arduino-pico: Raspberry Pi Pico Arduino core, for all RP2040 boards as the Arduino core for the Pico?

Thanks for the reply! I use the Arduino Core MBED 2.4.1 (which comes with PlatformIO by default)

[platformio]
default_envs = nanorp2040connect

[env:nanorp2040connect]
platform = raspberrypi
board = nanorp2040connect
framework = arduino
upload_port = /dev/cu.usbmodem145201
lib_ldf_mode = chain+
lib_compat_mode = strict
lib_deps =
   paulstoffregen/Time@^1.6.1
   khoih-prog/WiFiNINA_Generic@^1.8.13
   khoih-prog/RP2040_RTC@^1.0.6
lib_ignore =
   Timezone_Generic
   DS323x_Generic
   WiFi101
   WiFiEspAT
   WiFi
   ESP_AT_Lib
   ESP8266_AT_WebServer
   EthernetENC
   Ethernet2
   Ethernet3
   EthernetLarge
   Ethernet
   EthernetWebServer
   WiFiWebServer

Should I try arduino-pico? :slight_smile:

If it works in ArduinoCore-mbed in the Arduino-IDE it must be able to work the same way in PlatformIO which also uses ArduinoCore-mbebd. I’ll look into it.

Amazing, let me know if I can assist somehow.

In fact, 17 hours ago a new release for platform-raspberrypi was made that pulls-up the ArduinoCore-mbed version to the latest one (2.5.2) (Releases · platformio/platform-raspberrypi · GitHub).

Can you open a CLI, execute pio platform update raspberrypi, then Clean & Upload the project again to see if the behavior is the same?

Which version of ArduinoCore-mbed are you using in the Arduino IDE? (Tools → Boards → Board manager should show this)

Nice catch, I updated but behaviour is the same unfortunately. The build passes, upload works but then the RTC cannot be set.

In the Arduino IDE I use Arduino Mbed OS Nano Boards 2.5.2 (so the same version as what I have in PIO).

Platform raspberrypi
--------
Updating platformio/raspberrypi               1.4.0                              [Up-to-date]

Same warnings:

In file included from /Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/platform_defs.h:12,
                 from /Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/pico_platform/include/pico/platform.h:12,
                 from /Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/common/pico_base/include/pico.h:19,
                 from /Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/variants/NANO_RP2040_CONNECT/double_tap_usb_boot.cpp:2:
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h: In function 'uint32_t time_us_32()':
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:66:12: note: in expansion of macro 'timer_hw'
   66 |     return timer_hw->timerawl;
      |            ^~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h: In function 'bool time_reached(absolute_time_t)':
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:110:19: note: in expansion of macro 'timer_hw'
  110 |     uint32_t hi = timer_hw->timerawh;
      |                   ^~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_regs/include/hardware/regs/addressmap.h:56:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
   56 | #define TIMER_BASE 0x40054000
      |                    ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2040/hardware_structs/include/hardware/structs/timer.h:33:38: note: in expansion of macro 'TIMER_BASE'
   33 | #define timer_hw ((timer_hw_t *const)TIMER_BASE)
      |                                      ^~~~~~~~~~
/Users/viktor.loosz/.platformio/packages/framework-arduino-mbed/cores/arduino/mbed/targets/TARGET_RASPBERRYPI/TARGET_RP2040/pico-sdk/rp2_common/hardware_timer/include/hardware/timer.h:111:33: note: in expansion of macro 'timer_hw'
  111 |     return (hi >= hi_target && (timer_hw->timerawl >= (uint32_t) target || hi != hi_target));
      |                                 ^~~~~~~~
In file included from .pio/libdeps/nanorp2040connect/WiFiNINA_Generic/src/utility/spi_drv.cpp:61:
.pio/libdeps/nanorp2040connect/WiFiNINA_Generic/src/WiFiNINA_Pinout_Generic.h:107:4: warning: #warning Using default WiFiNINA settings [-Wcpp]
  107 |   #warning Using default WiFiNINA settings
      |    ^~~~~~~

Alright, now that PlatformIO and the Arduino-IDE are using the same core version, the error must lie elsewhere. I’ll have a look.

PlatformIO usually throws more warnings than the Arduino IDE because the Arduino IDE just doesn’t include the warning flags (e.g., -Wall) in the compiler invocation. If you go to File → Settings → Compiler-Warnings: All and activate “Verbose Output during: Compilation” the Arduino IDE should give you the same warnings as PlatformIO does by default. This shouldn’t be the result of the error since the base code is the same.

The weird thing is that I already turned on all these settings but no warnings from the Arduino IDE build.

image

Hm, that’s weird. Maybe it still doesn’t give it a particular warning flag.

In any case, since I don’t have a RP2040 Connect all I can test with is a regular Raspberry Pi Pico and the example using the internal RTC.

However, then I’m running into the same problem on both the PlatformIO IDE and the Arduino IDE: It hangs up after after printing

Start RP2040_RTC_Time on MBED RASPBERRY_PI_PICO
RP2040_RTC v1.0.6
Timezone_Generic v1.7.1

with no further output. In fact it seems to crash the Pico and make it lose the USB connection. Debugging the criticial

section shows that it does not survive the new expression. Avoiding the object statically leads to a crash inside mbed-os because the LED blinks in an error pattern.

Seems like this needs more debugging work…

At least my problem is tracked in https://github.com/khoih-prog/RP2040_RTC/issues/3 now, let’s see if the library author can reproduce it.

EDIT: The standard Time example only works with the EarlePhilhower core for me, not ArduinoCore-mbed. :confused:

Oh, right. If you remove the TimeZone references (e.g. only printing the UTC time) the code does work in the IDE. I forgot to mention this little detail (sorry, weird).

In any case, I don’t think my particular error on the Pico has much to do with your actual error.
The crucial part is

The function rtc_set_datetime can return only false if…

with

So when the sketch does

It calls rtc_set_datetime() through an overload,

Can you add in the defines.h (this file is part of the example) the line

#define RTC_DEBUG 1

and re-upload your sketch? It should make those debug statements appear so that the sub-fields are printed and thus it may be clear why setting the RTC time fails.

Unfortunately, I tried this before without much luck, the output is not very useful:

Seconds since Jan 1 1900 = 3844770413
Unix time = 1635781613
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
Year = 2021, Mo = 11, day = 1, hour = 15, min = 46, sec = 53
rtc_set_datetime failed
The UTC time is 15:46:53
============================
00:00:00 Tue 31 Dec 2047 UTC

Just to avoid more confusion from my side, I’ve added the code to the previously mentioned gist: PlatformIO RP2040 RTC build issues · GitHub

Thanks for all the effort :slight_smile:

PS: To clarify the Arduino RP2040 Connect also crashes when the TZ lib is included

That’s good info because we now we know that every single value but one is correct.

The datastructure has a dotw field that is not initialized in the code

since the variable is allocated on the stack, it likely has a random value and fails the >= 0 && <= 6 check.

Per

the “dotw” means “Day of the Week”, so 0 would be monday and 6 would be sunday I think.

Can you do the following small library modifications. Assuming you’re using the Arduino IDE (PlatformIO or Arduino IDE doesn’t matter), find where the library is installed (.pio\libdeps\nanorp2040connect\RP2040_RTC\src for PIO, C:\Users\<user>\Documents\Arduino\libraries\RP2040_RTC for Arduino IDE) and find the file DateTime_Generic.h.

Change the mentioned function to

  bool rtc_set_datetime(DateTime dt) 
  {
    datetime_t tm;
    
    tm.year   = dt.year();       
    tm.month  = dt.month();
    tm.day    = dt.day();
    tm.hour   = dt.hour();
    tm.min    = dt.minute();
    tm.sec    = dt.second();
    tm.dotw = 0; //monday (dirty fix)

#if RTC_DEBUG    
    Serial.print("Year = "); Serial.print(tm.year);
    Serial.print(", Mo = "); Serial.print(tm.month);
    Serial.print(", day = "); Serial.print(tm.day);
    Serial.print(", hour = "); Serial.print(tm.hour);
    Serial.print(", min = "); Serial.print(tm.min);
    Serial.print(", sec = "); Serial.println(tm.sec);
#endif   
    
    return (rtc_set_datetime(&tm));
  }

and retry.

1 Like