Skip to content

drivers/sx126x: fix hardware detection on init#21850

Merged
maribu merged 2 commits intoRIOT-OS:masterfrom
maribu:drivers/sx126x/fix-hardware-detection
Nov 7, 2025
Merged

drivers/sx126x: fix hardware detection on init#21850
maribu merged 2 commits intoRIOT-OS:masterfrom
maribu:drivers/sx126x/fix-hardware-detection

Conversation

@maribu
Copy link
Copy Markdown
Member

@maribu maribu commented Nov 6, 2025

Contribution description

When the CIPO line is pulled high, the driver will initialize even when
no chip is connected. This adds a read of the configured modulation,
which should be LoRa after a reset (even when configured to e.g. GFSK
prior). The packet type contains both one and zero bits, so chance
to read the only accepted byte from a floating SPI bus is relatively
low.

Testing procedure

  1. The driver should still work when the hardware is present
  2. The driver should fail gracefully when the radio is not connected, instead of running into a blown assertion

Issues/PRs references

None

@maribu maribu requested a review from fabian18 November 6, 2025 09:22
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 6, 2025
@github-actions github-actions bot added Area: drivers Area: Device drivers Area: LoRa Area: LoRa radio support labels Nov 6, 2025
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

Note: I have not yet tested the change, so please wait for hitting the green button

@riot-ci
Copy link
Copy Markdown

riot-ci commented Nov 6, 2025

Murdock results

✔️ PASSED

f16ceb3 drivers/sx126x: always report back that netdev is LoRa

Success Failures Total Runtime
10913 0 10915 09m:53s

Artifacts

@fabian18
Copy link
Copy Markdown
Contributor

fabian18 commented Nov 6, 2025

The driver should still work when the hardware is present

USEMODULE+="shield_sx1262" BOARD=adafruit-metro-m4-express DEVELHELP=1 make flash term PORT=/dev/ttyACM1

2025-11-06 12:59:31,521 # ifconfig
2025-11-06 12:59:31,523 # Iface  4  HWaddr: AA:AA:AA:AA  Frequency: 868300000Hz  RSSI: -128  BW: 125kHz  SF: 7  CR: 4/5  Link: down 
2025-11-06 12:59:31,524 #            State: STANDBY  Demod margin.: 0  Num gateways.: 0 
2025-11-06 12:59:31,524 #           OTAA  
2025-11-06 12:59:31,524 #           Link type: wireless

Yes.

The driver should fail gracefully when the radio is not connected, instead of running into a blown assertion

Also yes, when I dont have the shield connected.

But also that is the bahavior for me on master. Did you get the assert trigger?
Or is the change required in case another SPI device was connected?

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

But also that is the bahavior for me on master. Did you get the assert trigger?

Yes, in the DFT Communication board when no Antenna Board is connected. There seems to be something slightly pulling up the CIPO (aka MISO) line. You should be able to reproduce by adding 100 K resistor between VCC and CIPO.

The assert is quite late in the boot: The init worked just fine without the LoRa chip connected, but GNRC than triggered an assertion because the netdev type was reported as unknown, which was not explicitly handled in a switch () over the device type and the default: just had an assert(0);.

@fabian18
Copy link
Copy Markdown
Contributor

fabian18 commented Nov 6, 2025

Ok, when it fixes it in the com board. CI no longer accepts the commits from the "Commit suggestion" button.

@crasbe crasbe added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Nov 6, 2025
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

Let's not hit merge just yet. I was too busy with the other project to confirm it does fix the issue just yet.

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

I can confirm that the device presence test now works. The issue is also not specific to one instance of the DFT communication board, but happens reliable on two instances. So I'd say it is an issue we might see on other hardware as well.

@maribu maribu force-pushed the drivers/sx126x/fix-hardware-detection branch from 2c2c6a8 to 64b307e Compare November 6, 2025 16:03
@maribu maribu enabled auto-merge November 6, 2025 16:23
@maribu maribu disabled auto-merge November 6, 2025 16:24
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

Oh, shit. It appears that the LoRa chips on the antenna boards default to GFSK and not to LoRa after reset :/

@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 6, 2025

With this test it now works reliably for me. Better would be if there would be some vendor ID or device ID in the register map that we could read out and check. But I couldn't find something like that in the data sheet.

@fabian18
Copy link
Copy Markdown
Contributor

fabian18 commented Nov 6, 2025

Better would be if there would be some vendor ID or device ID

I have been looking for this before. Because I could not find it, the current state was good enough for me since it worked on the board I tested.

If the default was GFSK, why did it show up for me on the adafruit board which has the same LoRa chip?

typedef enum sx126x_pkt_types_e
{
    SX126X_PKT_TYPE_GFSK    = 0x00,
    SX126X_PKT_TYPE_LORA    = 0x01,
    SX126X_PKT_TYPE_BPSK    = 0x02,
    SX126X_PKT_TYPE_LR_FHSS = 0x03,
} sx126x_pkt_type_t;

Anyway ... anything > SX126X_PKT_TYPE_LR_FHSS is invalid so it is fine.

maribu and others added 2 commits November 7, 2025 10:26
When the CIPO line is pulled high, the driver will initialize even when
no chip is connected. This adds a read of the configured modulation,
which should be LoRa after a reset (even when configured to e.g. GFSK
prior). The packet type contains both one and zero bits, so chance
to read the only accepted byte from a floating SPI bus is relatively
low.

Co-authored-by: crasbe <[email protected]>
No network stack in RIOT is prepared for hardware to change its
device type at runtime. Especially the unknown network device is just
not handled and causes assertions to blow.

Instead, the driver now just returns to be a LoRa radio regardless of
configured modulation.
@maribu maribu force-pushed the drivers/sx126x/fix-hardware-detection branch from 23faf47 to f16ceb3 Compare November 7, 2025 09:26
@maribu
Copy link
Copy Markdown
Member Author

maribu commented Nov 7, 2025

Anyway ... anything > SX126X_PKT_TYPE_LR_FHSS is invalid so it is fine.

OK, then let's go with that. It did work reliably for me on two different systems.

@maribu maribu enabled auto-merge November 7, 2025 09:31
@maribu maribu added this pull request to the merge queue Nov 7, 2025
Merged via the queue into RIOT-OS:master with commit d3a0be4 Nov 7, 2025
25 checks passed
@maribu maribu deleted the drivers/sx126x/fix-hardware-detection branch November 10, 2025 09:05
@leandrolanzieri leandrolanzieri added this to the Release 2026.01 milestone Jan 13, 2026
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.

5 participants