Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a70e933b71 | ||
|
|
0cda7335d6 |
No files matched your search
@@ -1,5 +1,47 @@
|
||||
# Changes
|
||||
|
||||
## 0.3.0, 2026-10-25
|
||||
|
||||
- Provisioning and MO messages to Cloudloop work: the M5Stamp-C3 under
|
||||
open sky, provisioned with topics 244 and 313 to 317, sent two
|
||||
messages on topic 244 from its shell over WiFi, 16 and 17 bytes, and
|
||||
both arrived in Cloudloop whole. The second ran on the reworked
|
||||
control pins below, with P_EN wired and active low, and the modem
|
||||
stayed up past every earlier drop. `docs/CLOUDLOOP.md`, "What has
|
||||
run", records how Cloudloop shows a message.
|
||||
|
||||
- P_EN is active low. On the RockBLOCK it is the supercapacitor charge
|
||||
enable ("Cap Charge Enable Signal (ACTIVE LOW)", header pin 6), and the
|
||||
sample's overlays had it `GPIO_ACTIVE_HIGH`, so every `begin` switched
|
||||
the charger off: the modem ran down and went silent 2 to 5 minutes
|
||||
later, as it did on the M5Stamp-C3 indoors and out. The overlays, the
|
||||
README and the binding now say `GPIO_ACTIVE_LOW`, and the module drives
|
||||
P_EN only while the modem runs, releasing it to an input while it is
|
||||
off, where the board's pull-down keeps the charger on.
|
||||
- The control pins follow Ground Control's start-up and shutdown
|
||||
sequence. I_EN starts and stops the modem, and is what makes the pins
|
||||
present (`CONFIG_RB9704_POWER` follows `iridium-enable-gpios`); P_EN
|
||||
and I_BTD are optional beside it. Shutdown drives I_EN low and waits
|
||||
for I_BTD to go low before anything else, as start-up waits for it to
|
||||
go high, so I_EN never moves back before I_BTD has followed, which the
|
||||
page warns may damage the module. Before, `power off` dropped the pins
|
||||
and returned at once.
|
||||
|
||||
- The modem's UART is listened to from boot, not only while the library
|
||||
is open. With the power pins wired, `rb9704 power on` or a modem left
|
||||
talking after `rb9704 end` sent its boot lines to nobody; they
|
||||
overflowed the M5Stamp-C3's 128-byte UART FIFO, after which `begin`
|
||||
heard only repeated fragments of old lines and failed with `-EIO` (1 in
|
||||
6 after a power cycle, none at all after a pause), and a second `begin`
|
||||
crashed the board in the library's line parser. Bytes heard while the
|
||||
library is closed are now thrown away, and when it opens part-way
|
||||
through a line the rest of that line is too. On the Stamp: 8 of 8 power
|
||||
cycles, and 12 of 12 with 0 to 5 s between power on and `begin`.
|
||||
- The fake modem's `raw` and `before` write any bytes, now or just ahead
|
||||
of its next reply. `test_a_boot_burst_while_closed` sends a 680-byte
|
||||
boot burst before `begin`: the overflow above on a board through the
|
||||
rig, a check that it does no harm on native_sim.
|
||||
|
||||
## 0.2.0, 2026-10-25
|
||||
|
||||
- The shell sample over WiFi: `overlay-wifi.conf` puts the shell on
|
||||
|
||||
@@ -30,12 +30,13 @@ DT_COMPAT_ROCK7_ROCKBLOCK_9704 := rock7,rockblock-9704
|
||||
|
||||
config RB9704_POWER
|
||||
bool "Drive the power pins from devicetree"
|
||||
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_ROCK7_ROCKBLOCK_9704),power-gpios)
|
||||
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_ROCK7_ROCKBLOCK_9704),iridium-enable-gpios)
|
||||
select GPIO
|
||||
help
|
||||
P_EN, I_EN and I_BTD as the devicetree node gives them. Without
|
||||
them the modem is taken to be powered, as the board is with the pins
|
||||
left open.
|
||||
I_EN, I_BTD and P_EN as the devicetree node gives them, in Ground
|
||||
Control's start-up and shutdown sequence. I_EN is the one that
|
||||
switches the modem; without it the modem is taken to be powered, as
|
||||
the board is with the pins left open.
|
||||
|
||||
config RB9704_WORKER_STACK_SIZE
|
||||
int "Worker thread stack size"
|
||||
|
||||
@@ -62,11 +62,19 @@ The library's source shows several things a caller has to work around;
|
||||
asks the modem to abandon it. `rbBegin` empties the queue but not the
|
||||
count of it, which would make every send after a stuck one queue
|
||||
without transmitting; `rb9704_begin` zeroes the count.
|
||||
- **A line with no status code reads past the library's buffer**, and on
|
||||
a board it crashed. A modem talks before `rb9704_begin` opens the
|
||||
library: its boot lines, once its power pins bring it up. The module
|
||||
listens on the UART from boot and throws those bytes away, so a small
|
||||
hardware FIFO never overflows into fragments of old lines, and when the
|
||||
library opens part-way through a line the rest of that line is thrown
|
||||
away too.
|
||||
|
||||
Others are for upstream to fix, and are listed in `docs/JSPR.md` for that:
|
||||
`setState` waits for a misspelt target, a line with no status code reads
|
||||
past its buffer, MT segment data is cut at 1446 characters, and the
|
||||
Python binding never releases the GIL.
|
||||
past its buffer (the module keeps the causes it knows of away from it),
|
||||
MT segment data is cut at 1446 characters, and the Python binding never
|
||||
releases the GIL.
|
||||
|
||||
## Using it
|
||||
|
||||
@@ -76,7 +84,7 @@ library, pinned, at the path the module looks in, and nothing else:
|
||||
```yaml
|
||||
- name: rockblock9704-zephyr
|
||||
url: https://github.com/SH3D/rockblock9704-zephyr
|
||||
revision: v0.2.0
|
||||
revision: v0.3.0
|
||||
path: modules/lib/rockblock9704-zephyr
|
||||
import:
|
||||
name-allowlist:
|
||||
@@ -84,7 +92,9 @@ library, pinned, at the path the module looks in, and nothing else:
|
||||
```
|
||||
|
||||
In the board overlay, a node on the modem's UART. The pins are optional;
|
||||
without them the modem is taken to be powered:
|
||||
without them the modem is taken to be powered. I_EN starts and stops the
|
||||
modem; P_EN is the supercapacitor charge enable and is active low, so
|
||||
`GPIO_ACTIVE_LOW`, and it can be left unconnected:
|
||||
|
||||
```dts
|
||||
&usart3 {
|
||||
@@ -93,7 +103,7 @@ without them the modem is taken to be powered:
|
||||
|
||||
rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>; /* P_EN */
|
||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||
};
|
||||
@@ -142,7 +152,7 @@ system: the library keeps global state.
|
||||
| `CONFIG_RB9704_WORKER_STACK_SIZE` | 8192 | measured: the library parks 1.5 kB on the stack in `rbPoll()` |
|
||||
| `CONFIG_RB9704_WORKER_PRIORITY` | 8 | |
|
||||
| `CONFIG_RB9704_RX_RING_SIZE` | 8192 | the library's longest JSPR line |
|
||||
| `CONFIG_RB9704_POWER` | with `power-gpios` | drive the pins |
|
||||
| `CONFIG_RB9704_POWER` | with `iridium-enable-gpios` | drive the pins |
|
||||
| `CONFIG_RB9704_SHELL` | with `CONFIG_SHELL` | `rb9704` on the shell |
|
||||
| `CONFIG_RB9704_UPSTREAM_DIR` | empty | where Ground Control's library is, if not where `west.yml` puts it |
|
||||
|
||||
@@ -194,7 +204,7 @@ sample has overlays for:
|
||||
| `native_sim` | the host (x86-64) | yes |
|
||||
| NUCLEO-U575ZI-Q | STM32U5, Arm Cortex-M33 | yes |
|
||||
| Seeed XIAO ESP32S3 | ESP32-S3, Xtensa | yes |
|
||||
| M5Stamp-C3 | ESP32-C3, RISC-V | yes, a real 9704 on TX and RX; `docs/boards/stamp_c3.md` |
|
||||
| M5Stamp-C3 | ESP32-C3, RISC-V | yes, a real 9704 under the sky: provisioned, a message sent to Cloudloop; `docs/boards/stamp_c3.md` |
|
||||
| ESP32-S3-DevKitC | ESP32-S3, Xtensa | builds |
|
||||
| ESP32 DevKitC | ESP32, Xtensa | builds |
|
||||
| LilyGO T3-S3 | ESP32-S3, Xtensa | builds; an out-of-tree board in OGLAST2, with its `-DBOARD_ROOT` |
|
||||
|
||||
+26
-2
@@ -7,8 +7,10 @@ command line in `python/` (`python/README.md` has every verb).
|
||||
|
||||
Written 2026-10-09 from Ground Control's and Cloudloop's documentation
|
||||
and the library's source. `rb9704 info` and the free JSPR verbs have run
|
||||
against a real 9704 since; the account, provisioning and airtime steps
|
||||
have not been tried yet.
|
||||
against a real 9704 since. Provisioning and MO messages to Cloudloop work
|
||||
(2026-10-25), from the Zephyr module on an M5Stamp-C3 rather than from
|
||||
this command line; "What has run" at the end says how. MT has not been
|
||||
tried yet.
|
||||
|
||||
## What there is
|
||||
|
||||
@@ -197,3 +199,25 @@ version, SIM, operational state). In order of likelihood:
|
||||
'GET simStatus {}'` shows the modem's own answers; a 4xx code names
|
||||
the problem (`409` unauthorized, `410` SIM not configured, `418` not
|
||||
provisioned).
|
||||
|
||||
## What has run
|
||||
|
||||
On 2026-10-25, a RockBLOCK 9704 (firmware v1.5.14) on the header pins of
|
||||
an M5Stamp-C3 running the shell sample, under open sky, driven over WiFi
|
||||
by `rb9704 send` in the Zephyr shell (`boards/stamp_c3.md`):
|
||||
|
||||
- **Provisioning.** Already done when first asked: topics 244 (RAW) and
|
||||
313 to 317, the Cloudloop colours. The library only asks the modem
|
||||
when it is about to send, so the first send is when the module, and
|
||||
`rb9704 status`, learn the topics.
|
||||
- **MO.** Two messages on topic 244, `Stamp-C3 says hi` (16 bytes) and
|
||||
`Stamp-C3 P_EN low` (17 bytes). Each was with the network 6 to 10 s
|
||||
after the modem took it, with 3 to 4 bars, and each arrived in
|
||||
Cloudloop whole.
|
||||
- **How Cloudloop shows a message.** The same bytes twice: the message
|
||||
data in Base64 (`U3RhbXAtQzMgUF9FTiBsb3c`, the padding `=` left off)
|
||||
and the payload in hex (`5374616D702D433320505F454E206C6F77`). The
|
||||
CRC the library adds on the way out is checked and gone.
|
||||
|
||||
Not yet: MT, a session, and this command line's own `provision` and
|
||||
`send` against a real modem.
|
||||
@@ -723,6 +723,10 @@ Everything else is ignored.
|
||||
the end of the line through the zeroed buffer, then `memmove` with a
|
||||
negative length cast to `size_t` (`src/jspr.c:89-113`). Expect a crash.
|
||||
Never send banners, prompts or blank-ish lines of 9 bytes or more.
|
||||
On an M5Stamp-C3 it did crash (2026-10-25), when the UART's FIFO had
|
||||
overflowed and handed over fragments of old lines. rockblock9704-zephyr
|
||||
now keeps the FIFO empty from boot and gives the library no line it
|
||||
opened in the middle of (`src/rb9704_serial.c`).
|
||||
3. **`resultCodeIndexStart` is not reset** after a line is discarded for the
|
||||
wrong target (`src/jspr.c:48,133-136`): if that line had leading junk,
|
||||
the next line is read from the same offset. Do not send leading junk.
|
||||
|
||||
+29
-17
@@ -126,23 +126,28 @@ and the WiFi commands.
|
||||
|
||||
The board overlays for the M5Stamp-C3, ESP32-S3-DevKitC, ESP32 DevKitC
|
||||
and NUCLEO-U575ZI-Q wire all three control lines, so `rb9704 begin`
|
||||
powers the modem up in order and waits for it to say it has booted.
|
||||
starts the modem through I_EN and waits for I_BTD to say it has booted,
|
||||
and `rb9704 power off` waits for I_BTD to say it has shut down.
|
||||
|
||||
| 9704 | M5Stamp-C3 | ESP32-S3-DevKitC | ESP32 DevKitC | NUCLEO-U575ZI-Q |
|
||||
| 9704 header | M5Stamp-C3 | ESP32-S3-DevKitC | ESP32 DevKitC | NUCLEO-U575ZI-Q |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| RX (board TX) | GPIO4 | GPIO17 | GPIO17 | PD8 |
|
||||
| TX (board RX) | GPIO5 | GPIO18 | GPIO16 | PD9 |
|
||||
| P_EN | GPIO10 | GPIO6 | GPIO27 | PF15 (D2) |
|
||||
| I_EN | GPIO6 | GPIO4 | GPIO25 | PF14 (D4) |
|
||||
| I_BTD | GPIO7 | GPIO5 | GPIO26 | PF13 (D7) |
|
||||
| GND | GND | GND | GND | GND |
|
||||
| 14, RXD (board TX) | GPIO4 | GPIO17 | GPIO17 | PD8 |
|
||||
| 13, TXD (board RX) | GPIO5 | GPIO18 | GPIO16 | PD9 |
|
||||
| 3, I_EN | GPIO6 | GPIO4 | GPIO25 | PF14 (D4) |
|
||||
| 7, I_BTD | GPIO7 | GPIO5 | GPIO26 | PF13 (D7) |
|
||||
| 6, P̅_E̅N̅, active low, optional | GPIO10 | GPIO6 | GPIO27 | PF15 (D2) |
|
||||
| 1, 4 or 10, GND | GND | GND | GND | GND |
|
||||
|
||||
The modem's supply is its own, at the voltage and peak current Ground
|
||||
Control's manual gives, not the board's 3.3 V regulator. With `booted-gpios` in the overlay,
|
||||
`rb9704 begin` waits up to 30 s for I_BTD. A fake modem on a USB-serial
|
||||
adapter in place of the 9704 has no I_BTD, so tie the board's I_BTD pin
|
||||
to 3.3 V for those runs, or build with the rig overlays, which have no
|
||||
control lines.
|
||||
The modem's supply goes to V_IN+ and V_IN- (pins 15 and 16), 4.0 to
|
||||
5.3 V at up to 500 mA, not the board's 3.3 V regulator; V_BATT (pin 12)
|
||||
is for a lithium cell, never 5 V. P_EN is the supercapacitor charge
|
||||
enable and is active low: driven high it switches the charger off, and
|
||||
the modem runs down within minutes. Leaving it unconnected is fine.
|
||||
|
||||
A fake modem on a USB-serial adapter in place of the 9704 has no I_BTD:
|
||||
build with `no-control-pins.overlay`, below, or with the rig overlays,
|
||||
which have no control lines. Tying I_BTD to 3.3 V gets `begin` going, but
|
||||
`power off` then waits 30 s for it to fall and fails.
|
||||
|
||||
For a modem on TX and RX alone, `samples/shell/no-control-pins.overlay`
|
||||
takes the three lines out of any board's overlay at build time:
|
||||
@@ -166,6 +171,13 @@ WiFi, and a real 9704 on its header pins, TX and RX only, powered from
|
||||
the Stamp's 5V: `begin`, `info` and `signal` all answer, nothing dropped
|
||||
(`boards/stamp_c3.md`).
|
||||
|
||||
Not yet: a message through a real modem and satellite, which costs
|
||||
airtime and needs the sky (`CLOUDLOOP.md`, "The order to test in"), and
|
||||
the power pins on a board that has them wired.
|
||||
Later the same day, under open sky with P_EN unconnected: provisioned
|
||||
with topics 244 and 313 to 317, and one message, 16 bytes on topic 244,
|
||||
sent from the Stamp's shell over telnet and received in Cloudloop. The
|
||||
first message through a real modem and satellite.
|
||||
|
||||
Then the reworked control pins outside, P_EN wired and active low: up
|
||||
over 6 minutes, past every earlier drop, and a second message, 17 bytes
|
||||
on topic 244, received in Cloudloop.
|
||||
|
||||
Not yet: an MT message down to the board.
|
||||
+63
-31
@@ -12,23 +12,23 @@ The overlay is `samples/shell/boards/stamp_c3.overlay`, with
|
||||
|
||||
## Pins
|
||||
|
||||
| Stamp-C3 | Signal | Notes |
|
||||
| Stamp-C3 | 9704 header | Notes |
|
||||
| --- | --- | --- |
|
||||
| GPIO4 | `uart1` TX → 9704 RX | 230400 8N1 |
|
||||
| GPIO5 | `uart1` RX ← 9704 TX | |
|
||||
| GPIO10 | P_EN | the supply; without it the module drives none of the three |
|
||||
| GPIO6 | I_EN | the modem enable, 10 ms after P_EN |
|
||||
| GPIO7 | I_BTD | `rb9704 begin` waits up to 30 s for it to go high |
|
||||
| GND | GND | |
|
||||
| 5V | the 9704's supply in | the Stamp's USB-C supply, passed through |
|
||||
| GPIO2 | the RGB LED, an SK6812 | on the board |
|
||||
| GPIO4, `uart1` TX | 14, RXD | 230400 8N1 |
|
||||
| GPIO5, `uart1` RX | 13, TXD | |
|
||||
| GPIO6 | 3, I_EN | starts and stops the modem |
|
||||
| GPIO7 | 7, I_BTD | high once booted, low once shut down; waited on both ways |
|
||||
| GPIO10 | 6, P̅_E̅N̅ | the supercapacitor charge enable, **active low**; optional |
|
||||
| GND | 1, 4 or 10, GND | signal ground |
|
||||
| | 15, V_IN+ and 16, V_IN- | 4.0 to 5.3 V, 500 mA: see Power |
|
||||
| GPIO2 | | the RGB LED, an SK6812, on the board |
|
||||
| GPIO3 | the button | on the board |
|
||||
| GPIO20, GPIO21 | `uart0`, the console | through the USB-C bridge |
|
||||
|
||||
Kept clear: GPIO8 and GPIO9 (strapping pins, and the board's I2C) and
|
||||
GPIO18 and GPIO19 (USB).
|
||||
|
||||
## Power: the Stamp's 5V, and the 9704's USB-C unplugged
|
||||
## Power: V_IN+, and the 9704's USB-C unplugged
|
||||
|
||||
The 9704's header UART and its USB-C port are the same serial lines. With
|
||||
USB-C plugged in, the 9704's FTDI chip is powered and drives the modem's
|
||||
@@ -36,27 +36,32 @@ RX, and a board on the header cannot talk over it: the modem answers
|
||||
nobody, the computer on USB included. Its TX still reaches the header, so
|
||||
a board can listen alongside USB, but not send.
|
||||
|
||||
So the 9704 is powered from the header with its USB-C unplugged. The
|
||||
Stamp's 5V pin does it: the modem draws a few hundred mA, and its
|
||||
supercapacitor charges slowly, about 40 s to the green RDY LED. Both
|
||||
boards then run from the Stamp's USB-C; on a laptop's 500 mA port a
|
||||
Stamp that resets by itself while the 9704 charges is the supply sagging,
|
||||
and a charger or a powered hub gives the margin.
|
||||
So the 9704 is powered from the header with its USB-C unplugged, on
|
||||
V_IN+ (pin 15) and V_IN- (pin 16): 4.0 to 5.3 V, and the board limits
|
||||
itself to about 460 mA while its supercapacitor charges, about 40 s to
|
||||
the green RDY LED. A USB supply of its own is best, with its ground
|
||||
joined to the Stamp's; the Stamp's 5V pin works too, sharing the Stamp's
|
||||
USB-C. V_BATT (pin 12) is for a single lithium cell, 3.6 to 4.5 V, with
|
||||
no reverse-polarity protection and no charger on the board: never 5 V
|
||||
there. Ground Control recommends one input, not both.
|
||||
|
||||
The control lines are optional. With fewer wired, take the matching lines
|
||||
out of the overlay's `rockblock` node, or `rb9704 begin` waits on a pin
|
||||
that is not there:
|
||||
|
||||
- None: four wires, and the modem is taken to be powered. No edit
|
||||
needed: `-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay` takes all
|
||||
three out at build time (below).
|
||||
- P_EN only: `rb9704 power off` and `power on` over telnet restart a
|
||||
modem that has hung, with nobody walking out to it. The one most worth
|
||||
wiring.
|
||||
- I_BTD as well: a slow or failed boot is a clear timeout, not JSPR
|
||||
errors after a fixed 4 s (`boot-delay-ms`).
|
||||
- I_EN adds little here. The ESP32-C3's ROM prints at reset on GPIO21,
|
||||
the console, so nothing reaches the modem's pins before Zephyr runs.
|
||||
- None: four wires, and the modem is taken to be powered: I_EN has a
|
||||
pull-up and P_EN a pull-down, so it boots and charges when power comes.
|
||||
No edit needed: `-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay`
|
||||
takes all three out at build time (below).
|
||||
- I_EN: `rb9704 power off` and `begin` over telnet restart a modem that
|
||||
has hung, with nobody walking out to it. The one most worth wiring.
|
||||
- I_BTD as well: start-up and shutdown wait for the modem to say it has
|
||||
followed I_EN, as Ground Control's page asks, not a fixed 4 s
|
||||
(`boot-delay-ms`). Moving I_EN back before I_BTD has followed "may
|
||||
result in damage to the 9704 module".
|
||||
- P_EN adds nothing for a modem on V_IN+: left open, the board's
|
||||
pull-down keeps the charger on. Wired, it must be `GPIO_ACTIVE_LOW`;
|
||||
driven high it switches the charger off.
|
||||
|
||||
## Build and flash
|
||||
|
||||
@@ -77,7 +82,7 @@ west build -b stamp_c3 samples/shell -- -DEXTRA_CONF_FILE=overlay-wifi.conf \
|
||||
-DEXTRA_DTC_OVERLAY_FILE=no-control-pins.overlay
|
||||
```
|
||||
|
||||
With no P_EN, the long press on the button ends without turning anything
|
||||
With no I_EN, the long press on the button ends without turning anything
|
||||
off, and `rb9704 power` answers `-ENOTSUP`.
|
||||
|
||||
## WiFi
|
||||
@@ -147,7 +152,7 @@ airtime: use it on a network you trust.
|
||||
| Button | |
|
||||
| --- | --- |
|
||||
| short press | not begun: `rb9704 begin`. Begun: ask for the signal |
|
||||
| 2 s or more | end, and the supply off when P_EN is wired |
|
||||
| 2 s or more | end, and the modem off when I_EN is wired |
|
||||
|
||||
Nothing on the button costs airtime. The LED runs at 24 of 255
|
||||
(`LEVEL` in `indicator.c`).
|
||||
@@ -170,7 +175,34 @@ has no I_BTD: tie GPIO7 to 3.3 V for those runs.
|
||||
| | |
|
||||
| --- | --- |
|
||||
| WiFi, the stored network, telnet | works (2026-10-24) |
|
||||
| a real 9704 on TX and RX, powered from the Stamp's 5V: `begin`, `info`, `signal` | works (2026-10-25) |
|
||||
| a real 9704 on TX and RX, on V_IN+ from the Stamp's 5V: `begin`, `info`, `signal` | works (2026-10-25) |
|
||||
| the same with the 9704's USB-C plugged in | fails: the FTDI holds the modem's RX |
|
||||
| the LED and button | built, not yet run |
|
||||
| P_EN, I_EN, I_BTD | not yet wired |
|
||||
| P_EN, I_EN, I_BTD: `begin` powers it up in about 2 s, `power off`, `begin` again | works (2026-10-25), 8 of 8 cycles, and 12 of 12 with up to 5 s between `power on` and `begin` |
|
||||
| under open sky: the constellation visible and 3 to 5 bars within seconds of `begin` | works (2026-10-25) |
|
||||
| staying up while active | failed with P_EN driven the wrong way: see below; with P_EN unconnected, up and answering throughout (2026-10-25) |
|
||||
| provisioning, and a message sent | works (2026-10-25): provisioned with 244 and 313 to 317, and "Stamp-C3 says hi", 16 bytes on topic 244, sent in 10 s with 3 to 4 bars and received in Cloudloop |
|
||||
| the reworked control pins outside: I_EN and I_BTD in Ground Control's sequence, P_EN wired and `GPIO_ACTIVE_LOW` | works (2026-10-25): up over 6 minutes under the sky, past every drop with P_EN the wrong way, and "Stamp-C3 P_EN low", 17 bytes on topic 244, sent in 6 s and received in Cloudloop |
|
||||
| an MT message down to the board | not yet |
|
||||
| the LED and button | the button's short press works; the busy colour reads orange, not white, at this brightness |
|
||||
|
||||
### The modem stopped answering after a few minutes: P_EN
|
||||
|
||||
On 2026-10-25 the modem stopped answering 2 to 5 minutes after each
|
||||
`begin`, four times: once indoors, three times under open sky. Every
|
||||
request then got `-EIO`, its signal reports stopped, and it stayed silent
|
||||
until the control lines were cycled. Indoors the RDY LED went off.
|
||||
|
||||
The overlay had P_EN as `GPIO_ACTIVE_HIGH`. P_EN is active low (Ground
|
||||
Control's hardware page, pin 6, "Cap Charge Enable Signal (ACTIVE LOW)"),
|
||||
so every `begin` drove it high and switched the supercapacitor charger
|
||||
off: the modem ran on what the supercapacitor held until it was flat.
|
||||
The TX and RX test without control lines, where the pull-down keeps the
|
||||
charger on, did not stop. With P_EN taken off the header, the same
|
||||
firmware stayed up and sent its first message. The overlay now has
|
||||
`GPIO_ACTIVE_LOW`, and the module releases P_EN while the modem is off;
|
||||
with P_EN wired again on that firmware, the modem stayed up past every
|
||||
earlier drop and sent a second message.
|
||||
|
||||
The module also now shuts down as the page sets out: I_EN low, then wait
|
||||
for I_BTD to go low before anything else, and the same wait on the way
|
||||
up. Before, `power off` dropped the pins and returned at once.
|
||||
@@ -7,7 +7,10 @@ description: |
|
||||
no AT mode. One per system: the library underneath keeps global state.
|
||||
|
||||
The control pins are optional. With none, the modem is assumed powered and
|
||||
enabled, which is how the board behaves with the pins left open.
|
||||
enabled, which is how the board behaves with the pins left open: I_EN
|
||||
has a pull-up and P_EN a pull-down. I_EN is what switches the modem, so
|
||||
power control needs iridium-enable-gpios; booted-gpios and power-gpios
|
||||
are each optional beside it.
|
||||
|
||||
compatible: "rock7,rockblock-9704"
|
||||
|
||||
@@ -18,25 +21,32 @@ properties:
|
||||
power-gpios:
|
||||
type: phandle-array
|
||||
description: |
|
||||
P_EN, the supply enable. Driven active to power the board.
|
||||
P_EN, header pin 6: the supercapacitor charge enable. It is active
|
||||
low on the board, so give GPIO_ACTIVE_LOW. Driven active (charging
|
||||
on) while the modem runs, and released to an input while it is off,
|
||||
where the board's pull-down keeps the charger on. Leaving it
|
||||
unconnected is fine.
|
||||
|
||||
iridium-enable-gpios:
|
||||
type: phandle-array
|
||||
description: |
|
||||
I_EN, the modem enable. Driven active once the supply is up.
|
||||
I_EN, header pin 3: starts and stops the modem. Driven high to
|
||||
start it and low to stop it, and never moved back until I_BTD has
|
||||
followed.
|
||||
|
||||
booted-gpios:
|
||||
type: phandle-array
|
||||
description: |
|
||||
I_BTD, the modem's booted signal. When present, power-up waits for it
|
||||
instead of a fixed delay.
|
||||
I_BTD, header pin 7: high once the modem has booted, low once it has
|
||||
shut down. When present, start-up and shutdown wait for it instead
|
||||
of a fixed delay.
|
||||
|
||||
boot-delay-ms:
|
||||
type: int
|
||||
default: 4000
|
||||
description: |
|
||||
How long to wait after enabling the modem before talking to it, when
|
||||
there is no booted-gpios to wait on.
|
||||
How long to wait after moving I_EN, either way, when there is no
|
||||
booted-gpios to wait on.
|
||||
|
||||
examples:
|
||||
- |
|
||||
@@ -46,7 +56,7 @@ examples:
|
||||
|
||||
modem: rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>;
|
||||
power-gpios = <&gpiob 0 GPIO_ACTIVE_LOW>;
|
||||
iridium-enable-gpios = <&gpiob 1 GPIO_ACTIVE_HIGH>;
|
||||
booted-gpios = <&gpiob 2 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
|
||||
@@ -117,9 +117,10 @@ struct rb9704_callbacks {
|
||||
/* Replace the application's callbacks; NULL clears them. */
|
||||
void rb9704_set_callbacks(const struct rb9704_callbacks *cb);
|
||||
|
||||
/* Switch the board's supply and modem enable, when the devicetree gives the
|
||||
* pins. Waits for the booted pin or boot-delay-ms on the way up. -ENOTSUP
|
||||
* with no power pin. rb9704_end first if it was begun. */
|
||||
/* Start or stop the modem through I_EN, when the devicetree gives it, in
|
||||
* Ground Control's sequence: each way waits for I_BTD to follow, or
|
||||
* boot-delay-ms without it. -ENOTSUP with no I_EN. rb9704_end first if it
|
||||
* was begun. */
|
||||
int rb9704_power(bool on);
|
||||
|
||||
/* Open the serial port and bring the library up: API version, SIM
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "rockblock9704-tools"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
description = "Host tools for the RockBLOCK 9704: a command line for the modem and Cloudloop, and a fake modem for testing"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||
"""Host tools for the RockBLOCK 9704."""
|
||||
|
||||
__version__ = "0.2.0"
|
||||
__version__ = "0.3.0"
|
||||
@@ -29,6 +29,9 @@ Control is one command per line on stdin, events one per line on stdout:
|
||||
mo-release send the withheld final status
|
||||
segment <n> ask for MO segments of n bytes (default 1446)
|
||||
state <state> the operationalState from now on
|
||||
raw <text> write text as it is, \r for CR: a line's
|
||||
tail, junk, a line cut short
|
||||
before <text> write text just before the next reply
|
||||
quit
|
||||
|
||||
READY <port>
|
||||
@@ -95,6 +98,7 @@ class FakeModem:
|
||||
self.mo_refuse = False
|
||||
self.mo_hold = False # the next MO's final status waits for mo-release
|
||||
self.held = None # (topic, id, status) withheld
|
||||
self.before = b"" # written ahead of the next reply
|
||||
self.imei = "300434030000000"
|
||||
self.serial = "123456"
|
||||
self.iccid = "8988169712345678901"
|
||||
@@ -123,6 +127,9 @@ class FakeModem:
|
||||
|
||||
def request(self, line):
|
||||
self.events("RX " + line)
|
||||
if self.before:
|
||||
self.write(self.before)
|
||||
self.before = b""
|
||||
parts = line.split(" ", 2)
|
||||
if len(parts) < 2:
|
||||
return
|
||||
@@ -324,6 +331,15 @@ class FakeModem:
|
||||
self.segment = max(1, min(MO_SEGMENT_MAX, int(w[1])))
|
||||
elif cmd == "state":
|
||||
self.state = w[1]
|
||||
elif cmd in ("raw", "before"):
|
||||
text = line.split(" ", 1)[1] if " " in line else ""
|
||||
data = text.encode().decode("unicode_escape").encode("latin-1")
|
||||
with self.lock:
|
||||
if cmd == "raw":
|
||||
self.write(data)
|
||||
else:
|
||||
self.before = data
|
||||
self.events("%s %s" % (cmd.upper(), text))
|
||||
elif cmd == "quit":
|
||||
return False
|
||||
elif cmd:
|
||||
|
||||
@@ -5,6 +5,7 @@ Zephyr, through the shell sample, against the fake modem: on native_sim
|
||||
with --zephyr-exe, on a board with --board-console and --board-modem.
|
||||
"""
|
||||
|
||||
import time
|
||||
import zlib
|
||||
|
||||
import pytest
|
||||
@@ -102,6 +103,37 @@ def test_cancel_a_send_the_modem_sits_on(zephyr):
|
||||
c.out.expect(r"result 0")
|
||||
|
||||
|
||||
def test_a_boot_burst_while_closed(zephyr):
|
||||
"""A modem powered up before begin talks to nobody: its boot lines,
|
||||
over 600 bytes here, end part-way through one, finished just before
|
||||
the first reply. On the M5Stamp-C3 such a burst overflowed the UART's
|
||||
128-byte FIFO while the module was not listening, and begin then heard
|
||||
only repeated fragments of old lines; given one, the library read past
|
||||
its buffer and the board crashed (2026-10-25). The module now empties
|
||||
the FIFO from boot and skips the rest of a line it opened in.
|
||||
|
||||
On a board through the rig this is that overflow. native_sim has no
|
||||
FIFO to overflow: there it checks that the burst does no harm."""
|
||||
c, f = zephyr
|
||||
boot = ('\\x11\\x11299 bootInfo {"image_type":"production","version":{"major":1,'
|
||||
'"minor":5,"patch":14,"build_info":"SX-250613-A3E9C3E3-P1-P3142-1194848-'
|
||||
'12516979"},"boot_source":"primary"}\\r')
|
||||
lines = (boot
|
||||
+ '299 simStatus {"card_present":true,"sim_connected":true,'
|
||||
'"iccid":"8988169712345678901"}\\r'
|
||||
+ '299 operationalState {"state":"inactive","reason":0}\\r' * 4
|
||||
+ '299 constellationState {"constellation_visible":false,"signal_bars":0}\\r' * 2
|
||||
+ '299 bootInfo {"image_type":"prod')
|
||||
f.cmd("raw " + lines)
|
||||
f.out.expect(r"^RAW ")
|
||||
time.sleep(0.5)
|
||||
f.cmd('before uction"}\\r')
|
||||
f.out.expect(r"^BEFORE ")
|
||||
begin(zephyr)
|
||||
c.sh("rb9704 info")
|
||||
c.out.expect(r"imei\s+300434030000000")
|
||||
|
||||
|
||||
def test_topic_below_64_is_refused_here(zephyr):
|
||||
c, f = zephyr
|
||||
begin(zephyr)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
rb9704: rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpio0 27 GPIO_ACTIVE_HIGH>; /* P_EN */
|
||||
power-gpios = <&gpio0 27 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||
iridium-enable-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||
booted-gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
rb9704: rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>; /* P_EN */
|
||||
power-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||
iridium-enable-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||
booted-gpios = <&gpio0 5 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
rb9704: rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpiof 15 GPIO_ACTIVE_HIGH>; /* P_EN */
|
||||
power-gpios = <&gpiof 15 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||
iridium-enable-gpios = <&gpiof 14 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||
booted-gpios = <&gpiof 13 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
rb9704: rockblock {
|
||||
compatible = "rock7,rockblock-9704";
|
||||
power-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>; /* P_EN */
|
||||
power-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>; /* P_EN, active low */
|
||||
iridium-enable-gpios = <&gpio0 6 GPIO_ACTIVE_HIGH>; /* I_EN */
|
||||
booted-gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>; /* I_BTD */
|
||||
};
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#define RB9704_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(rock7_rockblock_9704)
|
||||
|
||||
/* rb9704_serial.c */
|
||||
/* The receive interrupt, on from boot (rb9704_serial.c says why). */
|
||||
int rb9704_serial_start(void);
|
||||
int rb9704_serial_available(void);
|
||||
uint32_t rb9704_serial_dropped(void);
|
||||
void rb9704_serial_spy(bool on);
|
||||
|
||||
+85
-45
@@ -1,14 +1,31 @@
|
||||
/* SPDX-License-Identifier: MIT
|
||||
* Copyright (c) 2026 Scott Penrose <scottp@dd.com.au>
|
||||
*
|
||||
* rb9704_power.c - the board's control pins, as the devicetree gives them.
|
||||
* rb9704_power.c - the board's control pins, as the devicetree gives them,
|
||||
* in the sequence Ground Control's hardware page sets out
|
||||
* (docs.groundcontrol.com/iot/rockblock-9704/hardware):
|
||||
*
|
||||
* power-gpios P_EN, the supply
|
||||
* iridium-enable-gpios I_EN, the modem, once the supply is up
|
||||
* booted-gpios I_BTD, the modem saying it has booted
|
||||
* iridium-enable-gpios I_EN, pin 3: starts and stops the modem
|
||||
* booted-gpios I_BTD, pin 7: high once booted, low once shut down
|
||||
* power-gpios P_EN, pin 6: the supercapacitor charge enable,
|
||||
* active low on the board, so GPIO_ACTIVE_LOW
|
||||
*
|
||||
* Up: supply, a moment, enable, then the booted pin or boot-delay-ms.
|
||||
* Down: enable, then supply. Called on the worker thread only.
|
||||
* Up: charging on, I_EN high, then I_BTD high (or boot-delay-ms).
|
||||
* Down: I_EN low, then I_BTD low (or boot-delay-ms), then P_EN released.
|
||||
*
|
||||
* Once I_EN has moved, it must not move back until I_BTD has followed; the
|
||||
* page warns that doing so "may result in damage to the 9704 module". Both
|
||||
* directions wait for I_BTD here, and a request to go the other way waits
|
||||
* its turn on the worker thread. While I_BTD is low no input other than
|
||||
* I_EN should be driven, so P_EN is an input while the modem is off; the
|
||||
* board's pull-down on P_EN keeps the charger on then.
|
||||
*
|
||||
* P_EN was GPIO_ACTIVE_HIGH in this module's overlays until 2026-10-25,
|
||||
* which switched the charger off at every begin: the modem ran on its
|
||||
* supercapacitor and went silent 2 to 5 minutes later.
|
||||
*
|
||||
* I_EN is what switches the modem, so it alone makes the pins present;
|
||||
* P_EN and I_BTD are each optional. Called on the worker thread only.
|
||||
*/
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
@@ -20,7 +37,7 @@
|
||||
|
||||
LOG_MODULE_DECLARE(rb9704, CONFIG_RB9704_LOG_LEVEL);
|
||||
|
||||
#define BOOT_TIMEOUT_MS 30000
|
||||
#define BTD_TIMEOUT_MS 30000
|
||||
|
||||
static const struct gpio_dt_spec pwr = GPIO_DT_SPEC_GET_OR(RB9704_NODE, power_gpios, {0});
|
||||
static const struct gpio_dt_spec en = GPIO_DT_SPEC_GET_OR(RB9704_NODE, iridium_enable_gpios, {0});
|
||||
@@ -30,7 +47,7 @@ static bool on;
|
||||
|
||||
bool rb9704_power_present(void)
|
||||
{
|
||||
return pwr.port != NULL;
|
||||
return en.port != NULL;
|
||||
}
|
||||
|
||||
bool rb9704_power_on(void)
|
||||
@@ -38,62 +55,85 @@ bool rb9704_power_on(void)
|
||||
return on;
|
||||
}
|
||||
|
||||
/* P_EN released: an input, so nothing drives the modem's pin. */
|
||||
static void charge_release(void)
|
||||
{
|
||||
if (pwr.port != NULL) {
|
||||
(void)gpio_pin_configure_dt(&pwr, GPIO_INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for I_BTD to read `level`; without I_BTD, wait boot-delay-ms. */
|
||||
static int wait_booted(int level)
|
||||
{
|
||||
if (btd.port == NULL) {
|
||||
k_msleep(DT_PROP(RB9704_NODE, boot_delay_ms));
|
||||
return 0;
|
||||
}
|
||||
int64_t until = k_uptime_get() + BTD_TIMEOUT_MS;
|
||||
|
||||
while (gpio_pin_get_dt(&btd) != level) {
|
||||
if (k_uptime_get() > until) {
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
k_msleep(50);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rb9704_power_init(void)
|
||||
{
|
||||
if (pwr.port == NULL) {
|
||||
if (en.port == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
if (!gpio_is_ready_dt(&pwr) || gpio_pin_configure_dt(&pwr, GPIO_OUTPUT_INACTIVE) != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
if (en.port != NULL &&
|
||||
(!gpio_is_ready_dt(&en) || gpio_pin_configure_dt(&en, GPIO_OUTPUT_INACTIVE) != 0)) {
|
||||
/* Off at boot: I_EN low. The modem may have been running from before
|
||||
* a reset, so wait for it to finish shutting down. */
|
||||
if (!gpio_is_ready_dt(&en) || gpio_pin_configure_dt(&en, GPIO_OUTPUT_INACTIVE) != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
if (btd.port != NULL && (!gpio_is_ready_dt(&btd) || gpio_pin_configure_dt(&btd, GPIO_INPUT) != 0)) {
|
||||
return -EIO;
|
||||
}
|
||||
if (pwr.port != NULL && !gpio_is_ready_dt(&pwr)) {
|
||||
return -EIO;
|
||||
}
|
||||
if (wait_booted(0) != 0) {
|
||||
LOG_WRN("modem still signals booted after I_EN went low");
|
||||
}
|
||||
charge_release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rb9704_power_set(bool want)
|
||||
{
|
||||
if (pwr.port == NULL) {
|
||||
if (en.port == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
if (want == on) {
|
||||
return 0;
|
||||
}
|
||||
if (!want) {
|
||||
if (en.port != NULL) {
|
||||
(void)gpio_pin_set_dt(&en, 0);
|
||||
}
|
||||
(void)gpio_pin_set_dt(&pwr, 0);
|
||||
(void)gpio_pin_set_dt(&en, 0);
|
||||
on = false;
|
||||
return 0;
|
||||
}
|
||||
if (on) {
|
||||
return 0;
|
||||
}
|
||||
(void)gpio_pin_set_dt(&pwr, 1);
|
||||
k_msleep(10);
|
||||
if (en.port != NULL) {
|
||||
(void)gpio_pin_set_dt(&en, 1);
|
||||
}
|
||||
if (btd.port != NULL) {
|
||||
int64_t until = k_uptime_get() + BOOT_TIMEOUT_MS;
|
||||
|
||||
while (gpio_pin_get_dt(&btd) != 1) {
|
||||
if (k_uptime_get() > until) {
|
||||
LOG_ERR("modem did not signal booted in %d ms", BOOT_TIMEOUT_MS);
|
||||
/* Back down, so the next attempt starts from off. */
|
||||
if (en.port != NULL) {
|
||||
(void)gpio_pin_set_dt(&en, 0);
|
||||
}
|
||||
(void)gpio_pin_set_dt(&pwr, 0);
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
k_msleep(50);
|
||||
if (wait_booted(0) != 0) {
|
||||
LOG_ERR("modem did not signal shut down in %d ms", BTD_TIMEOUT_MS);
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
} else {
|
||||
k_msleep(DT_PROP(RB9704_NODE, boot_delay_ms));
|
||||
charge_release();
|
||||
return 0;
|
||||
}
|
||||
if (pwr.port != NULL) {
|
||||
(void)gpio_pin_configure_dt(&pwr, GPIO_OUTPUT_ACTIVE); /* charging on */
|
||||
}
|
||||
(void)gpio_pin_set_dt(&en, 1);
|
||||
if (wait_booted(1) != 0) {
|
||||
LOG_ERR("modem did not signal booted in %d ms", BTD_TIMEOUT_MS);
|
||||
/* I_EN has to come down again for the next attempt to start
|
||||
* from off, though I_BTD never followed it up. */
|
||||
(void)gpio_pin_set_dt(&en, 0);
|
||||
(void)wait_booted(0);
|
||||
charge_release();
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
on = true;
|
||||
return 0;
|
||||
|
||||
+61
-6
@@ -12,6 +12,17 @@
|
||||
* bytes one at a time from receiveJspr(). TX is polled: a worst-case 2 kB
|
||||
* command is about 90 ms at 230400, and only the worker thread ever writes.
|
||||
*
|
||||
* The receive interrupt is on from boot, not only while the library is
|
||||
* open. A modem powered up by `rb9704 power on`, or left talking after
|
||||
* rbEnd(), sends lines nobody is reading; with the interrupt off they
|
||||
* overflowed the UART's hardware FIFO, 128 bytes on the ESP32-C3, and the
|
||||
* UART then gave back repeated fragments of old lines and never the
|
||||
* replies (2026-10-25, M5Stamp-C3). Now the ISR always empties the FIFO
|
||||
* and throws the bytes away while the library is closed. When it opens
|
||||
* part-way through a line, the rest of that line is thrown away too: a
|
||||
* line with no status code at its front makes the library read past its
|
||||
* buffer (docs/JSPR.md, section 8, item 2), and that crashed the board.
|
||||
*
|
||||
* The spy (rb9704_spy): JSPR is printable JSON lines, so the spy reassembles
|
||||
* the lines in each direction and printk()s them. Do not use the library's
|
||||
* own -DDEBUG for this: its TX debug path truncates the caller's buffer in
|
||||
@@ -24,6 +35,8 @@
|
||||
#include <zephyr/sys/atomic.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "rb9704_glue.h"
|
||||
#include "rb9704_internal.h"
|
||||
#include "serial.h" /* the library's serialContext */
|
||||
@@ -38,6 +51,15 @@ static K_SEM_DEFINE(rb9704_rx_sem, 0, 1);
|
||||
static atomic_t rx_dropped;
|
||||
static atomic_t spy_on;
|
||||
|
||||
/* Whether the library is open, so received bytes are for it. */
|
||||
static atomic_t listening;
|
||||
/* ISR only: the last byte heard ended a line, or there was none yet.
|
||||
* Non-printable bytes do not count: the modem sends a few at boot, and the
|
||||
* library already skips junk in front of a status code. */
|
||||
static bool mid_line;
|
||||
/* Set as the library opens mid-line: drop bytes up to the next CR. */
|
||||
static atomic_t skip_to_cr;
|
||||
|
||||
/* Per-byte RX timeout. receiveJspr() treats a 0-return mid-line as
|
||||
* end-of-data and discards the partial line, so this must comfortably
|
||||
* exceed any inter-byte gap the modem produces (gaps at 230400 are
|
||||
@@ -99,14 +121,34 @@ static void modem_uart_isr(const struct device *dev, void *user_data)
|
||||
while (uart_irq_update(dev) && uart_irq_rx_ready(dev)) {
|
||||
uint8_t tmp[64];
|
||||
int n = uart_fifo_read(dev, tmp, sizeof(tmp));
|
||||
int keep = 0;
|
||||
|
||||
if (n <= 0) {
|
||||
break;
|
||||
}
|
||||
uint32_t put = ring_buf_put(&rb9704_rx_ring, tmp, n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint8_t c = tmp[i];
|
||||
bool skip = !atomic_get(&listening) || atomic_get(&skip_to_cr);
|
||||
|
||||
if (put < (uint32_t)n) {
|
||||
atomic_add(&rx_dropped, n - put);
|
||||
if (c == '\r') {
|
||||
mid_line = false;
|
||||
if (atomic_get(&skip_to_cr)) {
|
||||
atomic_clear(&skip_to_cr);
|
||||
}
|
||||
} else if (c >= 0x20 && c < 0x7f) {
|
||||
mid_line = true;
|
||||
}
|
||||
if (!skip) {
|
||||
tmp[keep++] = c;
|
||||
}
|
||||
}
|
||||
if (keep == 0) {
|
||||
continue;
|
||||
}
|
||||
uint32_t put = ring_buf_put(&rb9704_rx_ring, tmp, keep);
|
||||
|
||||
if (put < (uint32_t)keep) {
|
||||
atomic_add(&rx_dropped, keep - put);
|
||||
}
|
||||
k_sem_give(&rb9704_rx_sem);
|
||||
rb9704_worker_rx();
|
||||
@@ -121,16 +163,19 @@ static bool ser_init(void)
|
||||
printk("rb9704: UART %s not ready\n", modem_uart->name);
|
||||
return false;
|
||||
}
|
||||
/* The ISR does not touch the ring while not listening, so the reset
|
||||
* needs no lock. */
|
||||
ring_buf_reset(&rb9704_rx_ring);
|
||||
k_sem_reset(&rb9704_rx_sem);
|
||||
uart_irq_callback_user_data_set(modem_uart, modem_uart_isr, NULL);
|
||||
uart_irq_rx_enable(modem_uart);
|
||||
atomic_set(&skip_to_cr, mid_line ? 1 : 0);
|
||||
atomic_set(&listening, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ser_deinit(void)
|
||||
{
|
||||
uart_irq_rx_disable(modem_uart);
|
||||
/* The interrupt stays on, emptying the FIFO into nothing. */
|
||||
atomic_clear(&listening);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -175,6 +220,16 @@ static int ser_peek(void)
|
||||
|
||||
/* --- setup + worker-facing helpers -------------------------------------- */
|
||||
|
||||
int rb9704_serial_start(void)
|
||||
{
|
||||
if (!device_is_ready(modem_uart)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
uart_irq_callback_user_data_set(modem_uart, modem_uart_isr, NULL);
|
||||
uart_irq_rx_enable(modem_uart);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool rb9704_serial_set_context(const char *port, uint32_t baud)
|
||||
{
|
||||
ARG_UNUSED(port); /* the UART is the devicetree node's bus */
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ static int cmd_spy(const struct shell *sh, size_t argc, char **argv)
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(rb9704_cmds,
|
||||
SHELL_CMD(begin, NULL, "open the port and bring the library up", cmd_begin),
|
||||
SHELL_CMD(end, NULL, "close it down", cmd_end),
|
||||
SHELL_CMD_ARG(power, NULL, "power on|off: the board's supply, if wired", cmd_power, 2, 0),
|
||||
SHELL_CMD_ARG(power, NULL, "power on|off: the modem, through I_EN, if wired", cmd_power, 2, 0),
|
||||
SHELL_CMD(status, NULL, "what is known, without asking the modem", cmd_status),
|
||||
SHELL_CMD(info, NULL, "IMEI, serial, versions, ICCID, SIM, temperature", cmd_info),
|
||||
SHELL_CMD(signal, NULL, "signal bars now", cmd_signal),
|
||||
|
||||
+4
-1
@@ -603,12 +603,15 @@ static void worker(void *a, void *b, void *c)
|
||||
ARG_UNUSED(a); ARG_UNUSED(b); ARG_UNUSED(c);
|
||||
|
||||
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
||||
/* No pins: the board is powered whenever this runs. */
|
||||
/* No I_EN: the board is powered whenever this runs. */
|
||||
st.powered = !rb9704_power_present();
|
||||
if (rb9704_power_present() && rb9704_power_init() != 0) {
|
||||
LOG_ERR("power pins not ready");
|
||||
}
|
||||
k_mutex_unlock(&rb9704_st_lock);
|
||||
if (rb9704_serial_start() != 0) {
|
||||
LOG_ERR("modem UART not ready");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
uint32_t ev = k_event_wait(&rb9704_ev, EV_REQ | EV_RX, false, K_FOREVER);
|
||||
|
||||
Reference in new issue
Block a user