Skip to content

Conversation

@maribu
Copy link
Member

@maribu maribu commented Nov 21, 2025

Contribution description

  • split out the detection logic into a static helper function
  • replace a forgotten debug printf() with DEBUG()
  • add a LOG_ERROR() to when no device is detect to ease diagnosis of a failing SPI bus / incorrect wiring / broken chip
  • use a bullet-proof test:
    • First set the modulation type to LoRa
    • Then get the modulation type and expect it to be LoRa

Even if the reset of the devices fails (e.g. because the reset signal
is not connected) and the modulation would be different from LoRa, this
now should reliably detect the chip.

Testing procedure

This should 100% detect when hardware is present, and 99.99% detect when hardware is not present.

Issues/PRs references

None

@maribu maribu requested a review from fabian18 November 21, 2025 12:45
@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 21, 2025
@github-actions github-actions bot added Area: drivers Area: Device drivers Area: LoRa Area: LoRa radio support labels Nov 21, 2025
@maribu maribu force-pushed the drivers/sx126x/fix-hardware-detection branch from 49a1ac5 to aaaae2c Compare November 21, 2025 12:45
@riot-ci
Copy link

riot-ci commented Nov 21, 2025

Murdock results

✔️ PASSED

fba614b drivers/sx126x: improve hardware detection

Success Failures Total Runtime
10932 0 10932 14m:04s

Artifacts

@maribu maribu force-pushed the drivers/sx126x/fix-hardware-detection branch from aaaae2c to a8aaafc Compare November 22, 2025 08:13
@maribu maribu marked this pull request as draft November 22, 2025 08:14
@maribu
Copy link
Member Author

maribu commented Nov 22, 2025

I have one very cursed setup where setting the packet type (modulation type) to LoRa then reading it back looks like this:

first_attempt

On the second attempt it looks like this:

second_attempt

I updated this PR to do three attempts at the detection, as I believe this might make the cursed hardware work. Testing will have to wait until Monday. I'll keep this as a draft until it is tested.

Some context: The expected transfer is:

  1. Writing packet type Lora
    1. Sending 0x8a (CMD "set packet type), 0x01 (data "packet type LoRa")
  2. Reading packet type
    1. Sending 0x11 (CMD "get packet type), 0x00 (data "don't care")
    2. Reading 0x01 ("packet type Lora")

At the first attempt the devices keeps MISO just high, as if it is completely unresponsive. The packet type is then read as 0xff as consequence. On the the second attempt it works as expected.

- split out the detection logic into a static helper function
- replace a forgotten debug `printf()` with `DEBUG()`
- add a `LOG_ERROR()` to when no device is detect to ease diagnosis of
  a failing SPI bus / incorrect wiring / broken chip
- use a bullet-proof test:
    - First set the modulation type to LoRa
    - Then get the modulation type and expect it to be LoRa

Even if the reset of the devices fails (e.g. because the reset signal
is not connected) and the modulation would be different from LoRa, this
now should reliably detect the chip.
@maribu maribu force-pushed the drivers/sx126x/fix-hardware-detection branch from a8aaafc to fba614b Compare November 25, 2025 22:45
@maribu maribu marked this pull request as ready for review November 25, 2025 22:46
@maribu
Copy link
Member Author

maribu commented Nov 25, 2025

I updated the PR to no longer try three times. After the power sequencing code of the cursed board was fixed, the board was less cursed and the chips reliably come up on the first try.

I don't have a reason to believe that there is a benefit in retrying the detection, hence I removed this.

@maribu maribu enabled auto-merge November 25, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Area: LoRa Area: LoRa radio support CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants