The modem's UART heard from boot, and the Stamp-C3 under the sky
The module turned the modem UART's receive interrupt off whenever the library was closed. With the power pins wired, the modem sends about 500 bytes of boot lines as it comes up, to nobody; on the M5Stamp-C3 they overflowed the UART's 128-byte FIFO, after which begin heard only repeated fragments of old lines and failed with -EIO, and a second begin crashed the board in the library's line parser (docs/JSPR.md, section 8, item 2). The interrupt is now on from boot: bytes heard while the library is closed are 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, where 1 of 6 and none had worked. The fake modem's raw and before commands write any bytes, now or just ahead of its next reply, and test_a_boot_burst_while_closed sends a 680-byte boot burst before begin: that overflow on a board through the rig, a check that it does no harm on native_sim. docs/boards/stamp_c3.md records the first run under open sky: the constellation visible and 3 to 5 bars within seconds of begin. It also records what is open: on the Stamp's 5V the modem stopped answering 2 to 5 minutes after each begin, four times, indoors and out, most likely its supply; not yet measured, and the tests that would settle it are listed there. Not yet provisioned, and no message sent.
This commit is contained in:
1 parent
4f5834a467
commit
0cda7335d6
9 files changed
+169
-10
No files matched your search
@@ -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);
|
||||
|
||||
+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 */
|
||||
|
||||
@@ -609,6 +609,9 @@ static void worker(void *a, void *b, void *c)
|
||||
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