2026 dongle: LED is PA0, add RX/finder/sweep pin-finding modes to the app

- Confirmed the status LED is on PA0 (active-high). README pin table updated:
  amplifier (AT2401C) control is one of PA1/PB1/PF0/PF1, still to distinguish.
- app.c gains bring-up modes for mapping the amplifier pins:
  - 'x' RX on the hexapod protocol (ch96/250k/HXPD1, 22-byte) + packet counter,
    to find the RX-enable pin by which pin lets the remote's packets arrive;
  - 'f'/'n' carrier-detect (RPD) finder (too noisy alone, kept for reference);
  - 'a' sweep every usable pin HIGH ~3s for LED/scope checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-14 23:39:50 +01:00
1 parent 4fcf9cf3d7
commit 2a4f6335dd
2 files changed
+106 -7

No files matched your search

+9 -5
View File
@@ -29,12 +29,16 @@ Found by probing the board over SWD and confirmed at runtime by our firmware:
| USB serial (USART1) TX / RX | PA9 / PA10 → CH330N | | USB serial (USART1) TX / RX | PA9 / PA10 → CH330N |
| SPI1 SCK / MISO / MOSI | PA5 / PA6 / PA7 → Si24R1 | | SPI1 SCK / MISO / MOSI | PA5 / PA6 / PA7 → Si24R1 |
| nRF CSN / CE / IRQ | PA3 / PA4 / PA2 | | nRF CSN / CE / IRQ | PA3 / PA4 / PA2 |
| free (LED + AT2401C TX/RX enable) | PA0, PA1, PB1, PF0, PF1 — **not yet mapped** | | status LED (active-high) | **PA0** — confirmed by eye |
| AT2401C TX/RX enable + unused | PA1, PB1, PF0, PF1 — **not yet distinguished** |
The LED and the AT2401C control lines are somewhere in those 5 free pins (the PA0 drives the LED (HIGH = on). The AT2401C control lines are among PA1, PB1,
TSSOP-20 has no other GPIO); the app firmware toggles them one at a time so we PF0, PF1 (the TSSOP-20 has no other GPIO). Listening for ambient 2.4 GHz with
can identify them by eye / by a range test. Until the PA control is known the the radio's carrier-detect bit was too noisy to tell them apart, so they need a
radio still works, just at reduced range. real link test (dongle ↔ robot/remote, trying each pin while watching whether
packets get through). The radio still works without driving the amplifier, just
at reduced range. The app firmware can drive any pin (`0`-`4`), sweep them all
(`a`), and run a carrier-detect finder (`f`/`n`).
### Programming header (5 holes next to the CH330N) ### Programming header (5 holes next to the CH330N)
+97 -2
View File
@@ -13,6 +13,7 @@
#define CSN_HI() BSRR(GPIOA) = (1u << 3) #define CSN_HI() BSRR(GPIOA) = (1u << 3)
#define CSN_LO() BSRR(GPIOA) = (1u << (3 + 16)) #define CSN_LO() BSRR(GPIOA) = (1u << (3 + 16))
#define CE_HI() BSRR(GPIOA) = (1u << 4)
#define CE_LO() BSRR(GPIOA) = (1u << (4 + 16)) #define CE_LO() BSRR(GPIOA) = (1u << (4 + 16))
static void spi_init(void) static void spi_init(void)
@@ -45,6 +46,43 @@ static void nrf_write(uint8_t reg, uint8_t val)
{ {
CSN_LO(); spi_xfer(0x20 | (reg & 0x1F)); spi_xfer(val); CSN_HI(); CSN_LO(); spi_xfer(0x20 | (reg & 0x1F)); spi_xfer(val); CSN_HI();
} }
static void nrf_write_buf(uint8_t reg, const uint8_t *d, int n)
{
CSN_LO(); spi_xfer(0x20 | (reg & 0x1F)); while (n--) spi_xfer(*d++); CSN_HI();
}
static void nrf_cmd(uint8_t c) { CSN_LO(); spi_xfer(c); CSN_HI(); }
/* Receive on the hexapod protocol (ch 96, 250 kbps, addr HXPD1, 22-byte). Lets
* us find the AT2401C RX-enable pin: packets only arrive when the LNA/antenna
* path is on. */
static uint8_t rxmode;
static uint16_t rx_count;
static void rx_setup(void)
{
static const uint8_t addr[5] = { 0x48, 0x58, 0x50, 0x44, 0x31 }; /* "HXPD1" */
CE_LO();
nrf_write(0x00, 0x0F); /* CONFIG: PWR_UP, PRIM_RX, EN_CRC, CRCO=16 */
nrf_write(0x01, 0x01); /* EN_AA pipe0 */
nrf_write(0x02, 0x01); /* EN_RXADDR pipe0 */
nrf_write(0x03, 0x03); /* SETUP_AW = 5 bytes */
nrf_write(0x05, 96); /* RF_CH */
nrf_write(0x06, 0x26); /* RF_SETUP: 250 kbps, max power */
nrf_write_buf(0x0A, addr, 5); /* RX_ADDR_P0 */
nrf_write(0x11, 22); /* RX_PW_P0 */
nrf_write(0x07, 0x70); /* clear status flags */
nrf_cmd(0xE2); /* FLUSH_RX */
rx_count = 0;
CE_HI();
}
static void rx_poll(void)
{
if (nrf_read(0x07) & 0x40) { /* RX_DR */
uint8_t buf[22];
CSN_LO(); spi_xfer(0x61); for (int i = 0; i < 22; i++) buf[i] = spi_xfer(0xFF); CSN_HI();
nrf_write(0x07, 0x40); /* clear RX_DR */
rx_count++;
}
}
static const struct { uint32_t port; uint8_t pin; const char *name; } FREE[] = { static const struct { uint32_t port; uint8_t pin; const char *name; } FREE[] = {
{ GPIOA, 0, "PA0" }, { GPIOA, 1, "PA1" }, { GPIOB, 1, "PB1" }, { GPIOA, 0, "PA0" }, { GPIOA, 1, "PA1" }, { GPIOB, 1, "PB1" },
@@ -62,6 +100,32 @@ static void free_init(void)
} }
} }
/* Every usable GPIO on the TSSOP-20 except PA9/PA10 (our serial). Sweep each
* HIGH ~3 s so the user can watch the LED. Disturbs the radio; re-init after. */
static const struct { uint32_t port; uint8_t pin; const char *name; } ALLPINS[] = {
{ GPIOA, 0, "PA0" }, { GPIOA, 1, "PA1" }, { GPIOA, 2, "PA2 IRQ" },
{ GPIOA, 3, "PA3 CSN" }, { GPIOA, 4, "PA4 CE" }, { GPIOA, 5, "PA5 SCK" },
{ GPIOA, 6, "PA6 MISO" }, { GPIOA, 7, "PA7 MOSI" }, { GPIOB, 1, "PB1" },
{ GPIOF, 0, "PF0" }, { GPIOF, 1, "PF1" }, { GPIOA, 13, "PA13 SWDIO" },
{ GPIOA, 14, "PA14 SWCLK" },
};
static void sweep_all(void)
{
uart_puts("sweeping ALL pins, 3 s each (radio will be disturbed):\r\n");
for (unsigned i = 0; i < sizeof(ALLPINS) / sizeof(ALLPINS[0]); i++) {
uint32_t p = ALLPINS[i].port; uint8_t n = ALLPINS[i].pin;
MODER(p) = (MODER(p) & ~(3u << (n * 2))) | (1u << (n * 2)); /* output */
BSRR(p) = (1u << n); /* HIGH */
uart_puts(">>> "); uart_puts(ALLPINS[i].name); uart_puts(" HIGH\r\n");
delay_ms(3000);
BSRR(p) = (1u << (n + 16)); /* LOW */
delay_ms(500);
}
uart_puts("sweep done; restoring radio\r\n");
spi_init();
nrf_write(0, 0x0E);
}
static void hex2(uint8_t b) { const char *h = "0123456789ABCDEF"; uart_putc(h[b >> 4]); uart_putc(h[b & 0xF]); } static void hex2(uint8_t b) { const char *h = "0123456789ABCDEF"; uart_putc(h[b >> 4]); uart_putc(h[b & 0xF]); }
static void banner(void) static void banner(void)
{ {
@@ -76,6 +140,22 @@ static void regdump(void)
for (unsigned i = 0; i < sizeof(rg); i++) { uart_puts(" R"); hex2(rg[i]); uart_putc('='); hex2(nrf_read(rg[i])); } for (unsigned i = 0; i < sizeof(rg); i++) { uart_puts(" R"); hex2(rg[i]); uart_putc('='); hex2(nrf_read(rg[i])); }
uart_puts("\r\n"); uart_puts("\r\n");
} }
/* Pin finder: sit in RX on a WiFi-busy channel and report the carrier-detect
* (RPD) bit. Toggling the real RXEN pin switches the AT2401C LNA on, which lifts
* ambient 2.4 GHz above the -64 dBm detect threshold -> RPD flips to 1. */
static uint8_t finder;
static uint8_t finder_ch = 62; /* 2462 MHz ~ WiFi ch 11 */
static void finder_rx(void)
{
CE_LO();
nrf_write(0x05, finder_ch); /* RF_CH */
nrf_write(0x06, 0x0F); /* RF_SETUP: keep it simple */
nrf_write(0x00, 0x0F); /* CONFIG: PWR_UP, PRIM_RX, CRC16 */
delay_ms(2);
CE_HI(); /* enter RX */
delay_ms(2);
}
static void reflash(void) /* ask safeboot to take over, no wire needed */ static void reflash(void) /* ask safeboot to take over, no wire needed */
{ {
uart_puts("resetting into safeboot flash mode...\r\n"); uart_puts("resetting into safeboot flash mode...\r\n");
@@ -100,13 +180,28 @@ int main(void)
if (c == 'v' || c == 'V') banner(); if (c == 'v' || c == 'V') banner();
else if (c == 'r' || c == 'R') regdump(); else if (c == 'r' || c == 'R') regdump();
else if (c == 'b' || c == 'B') reflash(); else if (c == 'b' || c == 'B') reflash();
else if (c == 'x' || c == 'X') { rxmode = !rxmode; finder = 0; if (rxmode) rx_setup(); else { CE_LO(); nrf_write(0, 0x0E); } uart_puts(rxmode ? "RX mode on (ch96/250k/HXPD1)\r\n" : "RX off\r\n"); }
else if (c == 'a' || c == 'A') sweep_all();
else if (c == 'f' || c == 'F') { finder = !finder; if (finder) finder_rx(); else { CE_LO(); nrf_write(0, 0x0E); } uart_puts(finder ? "finder RX on\r\n" : "finder off\r\n"); }
else if (c == 'n' || c == 'N') { finder_ch = (finder_ch == 62) ? 37 : (finder_ch == 37 ? 12 : 62); if (finder) finder_rx(); uart_puts("ch="); hex2(finder_ch); uart_puts("\r\n"); }
else if (c >= '0' && c <= '4') { else if (c >= '0' && c <= '4') {
int i = c - '0'; int i = c - '0';
fst[i] = !fst[i]; fst[i] = !fst[i];
BSRR(FREE[i].port) = fst[i] ? (1u << FREE[i].pin) : (1u << (FREE[i].pin + 16)); BSRR(FREE[i].port) = fst[i] ? (1u << FREE[i].pin) : (1u << (FREE[i].pin + 16));
uart_puts("pin "); uart_puts(FREE[i].name); uart_puts(fst[i] ? " HIGH\r\n" : " LOW\r\n"); uart_puts("pin "); uart_puts(FREE[i].name); uart_puts(fst[i] ? " HIGH" : " LOW");
if (finder) { delay_ms(2); uart_puts(" RPD="); hex2(nrf_read(9)); }
uart_puts("\r\n");
} }
if (rxmode) rx_poll();
delay_ms(1); delay_ms(1);
if (++t >= 2000) { t = 0; uart_puts("hb STATUS=0x"); hex2(nrf_read(7)); uart_puts("\r\n"); } if (++t >= 1000) {
t = 0;
if (rxmode) { uart_puts("RX pkts="); hex2(rx_count >> 8); hex2(rx_count & 0xFF);
uart_puts(" pins="); for (int i = 0; i < NFREE; i++) uart_putc(fst[i] ? '1' : '0');
uart_puts(" (0=PA0LED,1=PA1,2=PB1,3=PF0,4=PF1)\r\n"); rx_count = 0; }
else if (finder) { uart_puts("finder ch=0x"); hex2(finder_ch); uart_puts(" RPD="); hex2(nrf_read(9));
uart_puts(" pins="); for (int i = 0; i < NFREE; i++) uart_putc(fst[i] ? '1' : '0'); uart_puts("\r\n"); }
else { uart_puts("hb STATUS=0x"); hex2(nrf_read(7)); uart_puts("\r\n"); }
}
} }
} }