Skip to content

Commit 7fcc728

Browse files
projectgusdpgeorge
authored andcommitted
lora/sx126x: Fix busy timeout handling.
- If no reset pin was set, calling standby() in the constructor would enable the TCXO (XOSC) before the timeout was correctly set. - This manifested as a BUSY timeout on the STM32WL5, first time after power on reset. - Clean up the general handling of BUSY timeouts, but also add some safety margin to the base timeout just in case (not an issue, is only a stop-gap to prevent the modem blocking indefinitely.) Signed-off-by: Angus Gratton <[email protected]>
1 parent 0bdecbc commit 7fcc728

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

micropython/lora/lora-stm32wl5/lora/stm32wl5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
DIO1(),
6666
False, # dio2_rf_sw
6767
tcxo_millivolts, # dio3_tcxo_millivolts
68-
1000, # dio3_tcxo_start_time_us
68+
10_000, # dio3_tcxo_start_time_us, first time after POR is quite long
6969
None, # reset
7070
lora_cfg,
7171
ant_sw,

micropython/lora/lora-sx126x/lora/sx126x.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
# In any case, timeouts here are to catch broken/bad hardware or massive driver
100100
# bugs rather than commonplace issues.
101101
#
102-
_CMD_BUSY_TIMEOUT_BASE_US = const(3000)
102+
_CMD_BUSY_TIMEOUT_BASE_US = const(7000)
103103

104104
# Datasheet says 3.5ms needed to run a full Calibrate command (all blocks),
105105
# however testing shows it can be as much as as 18ms.
@@ -148,7 +148,9 @@ def __init__(
148148
if hasattr(dio1, "init"):
149149
dio1.init(Pin.IN)
150150

151-
self._busy_timeout = _CMD_BUSY_TIMEOUT_BASE_US
151+
self._busy_timeout = _CMD_BUSY_TIMEOUT_BASE_US + (
152+
dio3_tcxo_start_time_us if dio3_tcxo_millivolts else 0
153+
)
152154

153155
self._buf = bytearray(9) # shared buffer for commands
154156

@@ -168,7 +170,8 @@ def __init__(
168170
reset(1)
169171
time.sleep_ms(5)
170172
else:
171-
self.standby() # Otherwise, at least put the radio to a known state
173+
# Otherwise, at least put the radio to a known state
174+
self._cmd("BB", _CMD_SET_STANDBY, 0) # STDBY_RC mode, not ready for TCXO yet
172175

173176
status = self._get_status()
174177
if (status[0] != _STATUS_MODE_STANDBY_RC and status[0] != _STATUS_MODE_STANDBY_HSE32) or (
@@ -187,7 +190,6 @@ def __init__(
187190
#
188191
# timeout register is set in units of 15.625us each, use integer math
189192
# to calculate and round up:
190-
self._busy_timeout = (_CMD_BUSY_TIMEOUT_BASE_US + dio3_tcxo_start_time_us) * 2
191193
timeout = (dio3_tcxo_start_time_us * 1000 + 15624) // 15625
192194
if timeout < 0 or timeout > 1 << 24:
193195
raise ValueError("{} out of range".format("dio3_tcxo_start_time_us"))
@@ -668,7 +670,7 @@ def _wait_not_busy(self, timeout_us):
668670
while self._busy():
669671
ticks_diff = time.ticks_diff(time.ticks_us(), start)
670672
if ticks_diff > timeout_us:
671-
raise RuntimeError("BUSY timeout")
673+
raise RuntimeError("BUSY timeout", timeout_us)
672674
time.sleep_us(1)
673675
if _DEBUG and ticks_diff > 105:
674676
# By default, debug log any busy time that takes longer than the

0 commit comments

Comments
 (0)