dbrgn / shtcx-rs

Platform agnostic Rust driver for the Sensirion SHTCx temperature/humidity sensors.
Apache License 2.0
13 stars 4 forks source link

Using shtcx-rs with esp rust board: Error linking with 'rust-lld' failed #41

Closed jubeormk1 closed 3 months ago

jubeormk1 commented 3 months ago

Hello!

Does your crate support no_std?

I am testing your driver with the board esp-rust-board in a public repository

The board that I am using has a esp32-c3 and the project was made using the no-std esp-template

Apart from that in the entry function I have created a delay instance, an embedded_hal I2C device and a ShtCx (shtcx::shtc3) following your example on shtc3.

When I compile I am receiving the next output where it looks like Looks like _defmt_timestamp, _defmt_write, _defmt_release, and _defmt_acquire are not defined:

$ i2c-playground$ cargo build -r

   Compiling i2c-playground v0.1.0 (/home/jubeor/repos/esp32/i2c-playground)
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jubeor/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/bin/remote-cli:/home/jubeor/.local/bin:/home/jubeor/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Python312/Scripts/:/mnt/c/Python312/:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/usbipd-win/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/CMake/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Nordic Semiconductor/nrf-command-line-tools/bin/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Users/julio/.cargo/bin:/mnt/c/Users/julio/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/julio/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/julio/AppData/Local/GitHubDesktop/bin:/mnt/c/Program Files/7-Zip:/snap/bin" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/tmp/rustcAS1JuY/symbols.o" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o" "--as-needed" "-L" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps" "-L" "/home/jubeor/repos/esp32/i2c-playground/target/release/deps" "-L" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/build/defmt-cdbaabff50e00dda/out" "-L" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/build/esp-hal-a32f964e66e5afab/out" "-L" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/build/esp32c3-fc84e1c9f68b6962/out" "-L" "/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib" "-Bstatic" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/libcompiler_builtins-6283647fa719c848.rlib" "-Bdynamic" "-z" "noexecstack" "-L" "/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib" "-o" "/home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5" "--gc-sections" "-Tlinkall.x"
  = note: rust-lld: error: undefined symbol: _defmt_acquire
          >>> referenced by bit.rs:790 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:790)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by bit.rs:790 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:790)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by bit.rs:790 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:790)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced 4 more times

          rust-lld: error: undefined symbol: _defmt_release
          >>> referenced by bit.rs:790 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:790)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by bit.rs:790 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/bit.rs:790)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by mod.rs:1785 (/home/jubeor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1785)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced 4 more times

          rust-lld: error: undefined symbol: _defmt_write
          >>> referenced by mod.rs:54 (/home/jubeor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.17.0/src/rom/mod.rs:54)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by mod.rs:54 (/home/jubeor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.17.0/src/rom/mod.rs:54)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced by mod.rs:54 (/home/jubeor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.17.0/src/rom/mod.rs:54)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(main)
          >>> referenced 2 more times

          rust-lld: error: undefined symbol: _defmt_timestamp
          >>> referenced by mod.rs:85 (src/export/mod.rs:85)
          >>>               /home/jubeor/repos/esp32/i2c-playground/target/riscv32imc-unknown-none-elf/release/deps/i2c_playground-0095ce173ac13dc5.i2c_playground.5a238fac89fffd17-cgu.0.rcgu.o:(defmt::export::header::he9e354b212ebc8cf)

error: could not compile `i2c-playground` (bin "i2c-playground") due to 1 previous error

Any ideas?

jubeormk1 commented 3 months ago

Allow me to answer myself. I should check the dfmt::println. That is where the problem came from. Replacing the println by a log::info compiles and run on the target.

My code is still incorrect since I obtain no response. I must be initialising wrongly by I2C device.

jubeormk1 commented 3 months ago

The pin assignment was wrong, once corrected thinks works almost as expected. In this port with extra verbosity we can see correct ID and readings in normal mode and low power. After the sleep instruction there is no way to measure again:

$ cargo run -r
   Compiling i2c-playground v0.1.0 (/home/jubeor/repos/esp32/i2c-playground)
    Finished `release` profile [optimized + debuginfo] target(s) in 1.25s
     Running `espflash flash --monitor target/riscv32imc-unknown-none-elf/release/i2c-playground`
[2024-06-06T11:10:25Z INFO ] 🚀 A new version of espflash is available: v3.1.0
[2024-06-06T11:10:25Z INFO ] Serial port: '/dev/ttyACM0'
[2024-06-06T11:10:25Z INFO ] Connecting...
[2024-06-06T11:10:25Z INFO ] Using flash stub
Chip type:         esp32c3 (revision v0.4)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BLE
MAC address:       40:4c:ca:8c:e9:7c
App/part. size:    98,704/4,128,768 bytes, 2.39%
[2024-06-06T11:10:25Z INFO ] Segment at address '0x0' has not changed, skipping write
[2024-06-06T11:10:25Z INFO ] Segment at address '0x8000' has not changed, skipping write
[00:00:00] [========================================]      28/28      0x10000                                                                                                                                     [2024-06-06T11:10:27Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380630
0x40380630 - esp_hal::interrupt::riscv::vectored::get_configured_interrupts
    at /home/jubeor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.17.0/src/interrupt/riscv.rs:363
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd5820,len:0x1714
load:0x403cc710,len:0x968
load:0x403ce710,len:0x2f9c
entry 0x403cc710
I (24) boot: ESP-IDF v5.1.2-342-gbcf1645e44 2nd stage bootloader
I (24) boot: compile time Dec 12 2023 10:50:58
I (25) boot: chip revision: v0.4
I (29) boot.esp32c3: SPI Speed      : 40MHz
I (34) boot.esp32c3: SPI Mode       : DIO
I (38) boot.esp32c3: SPI Flash Size : 4MB
I (43) boot: Enabling RNG early entropy source...
I (48) boot: Partition Table:
I (52) boot: ## Label            Usage          Type ST Offset   Length
I (59) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (67) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (74) boot:  2 factory          factory app      00 00 00010000 003f0000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=00010020 vaddr=3c010020 size=024cch (  9420) map
I (96) esp_image: segment 1: paddr=000124f4 vaddr=3fc80e20 size=00004h (     4) load
I (103) esp_image: segment 2: paddr=00012500 vaddr=40380000 size=00e20h (  3616) load
I (112) esp_image: segment 3: paddr=00013328 vaddr=00000000 size=0ccf0h ( 52464) 
I (131) esp_image: segment 4: paddr=00020020 vaddr=42000020 size=0814ch ( 33100) map
I (139) boot: Loaded app from partition at offset 0x10000
I (139) boot: Disabling RNG early entropy source...
INFO - Starting SHTC3 tests.
INFO - Waking up sensor.
INFO - 
INFO - Device identifier: 0x47
INFO - Raw ID register: 0b0000100010000111
INFO - 
Normal mode measurements:
INFO -   23.68 °C | 46.10 %RH
INFO -   23.65 °C | 46.10 %RH
INFO -   23.71 °C | 46.00 %RH
INFO -   23.67 °C | 46.06 %RH
INFO -   23.72 °C | 46.07 %RH
INFO -   23.70 °C | 46.07 %RH
INFO -   23.75 °C | 46.11 %RH
INFO -   23.71 °C | 46.09 %RH
INFO -   23.67 °C | 46.09 %RH
INFO -   23.75 °C | 46.09 %RH
INFO - 
Low power mode measurements:
INFO -   24.21 °C | 46.28 %RH
INFO -   23.98 °C | 46.23 %RH
INFO -   23.99 °C | 45.99 %RH
INFO -   23.94 °C | 45.99 %RH
INFO -   24.08 °C | 46.22 %RH
INFO -   24.21 °C | 46.37 %RH
INFO -   24.03 °C | 46.45 %RH
INFO -   23.98 °C | 46.32 %RH
INFO -   24.21 °C | 46.53 %RH
INFO -   24.08 °C | 46.12 %RH
INFO - 
Testing power management:
INFO - -> Measure: 
INFO - Success: 23.76 °C
INFO - -> Sleep
INFO - Sleep command succeeded
INFO - -> Measure: 
ERROR - Error: I2c(AckCheckFailed)
INFO - -> Wakeup
ERROR - Wakeup command failed: I2c(AckCheckFailed)
INFO - -> Measure: 
ERROR - Error: I2c(AckCheckFailed)
INFO - -> Soft reset
ERROR - Reset command failed: I2c(AckCheckFailed)
INFO - -> Measure: 
ERROR - Error: I2c(AckCheckFailed)

I will take a look at the datasheet but I should say that this issue is closed. There was nothing wrong with the crate which is working on no_std, in particular esp32-c3 with rust core library.

dbrgn commented 3 months ago

Good to see that you found the issue :)