0.3.0: provisioning and messages to Cloudloop work, and P_EN is active low

The M5Stamp-C3 under open sky, driven over WiFi from its shell, found
the modem provisioned with topics 244 and 313 to 317 and sent two
messages on topic 244, 16 and 17 bytes. Each was with the network 6 to
10 s after the modem took it, and both arrived in Cloudloop whole.
docs/CLOUDLOOP.md, "What has run", records how Cloudloop shows one: the
same bytes in Base64 and in hex.

P_EN is the RockBLOCK's supercapacitor charge enable, header pin 6, and
it is active low. 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, four times indoors and out. The overlays, the README
and the binding now say GPIO_ACTIVE_LOW. With P_EN wired again on the
new firmware the modem stayed up past every earlier drop and sent the
second message.

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. P_EN is driven
only while the modem runs and released to an input while it is off.

docs/boards/stamp_c3.md has the header's pin numbers, V_IN+ against
V_BATT, and P_EN as the cause of the drops. The module, the sample and
the Python tools are 0.3.0.
This commit is contained in:
scottp committed 2026-10-25 22:48:11 +11:00
1 parent 0cda7335d6
commit a70e933b71
17 files changed
+265 -140

No files matched your search

+85 -45
View File
@@ -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;
+1 -1
View File
@@ -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),
+1 -1
View File
@@ -603,7 +603,7 @@ 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");