---
title: "Console shell"
description: "The console shell is an on-target interactive shell that ships as SDK"
source: https://docs.alplab.ai/sdk/tools/console
---

# The `alp` console shell

The **console shell** is an on-target interactive shell that ships as SDK
infrastructure. Setting `CONFIG_ALP_SDK_CONSOLE=y` registers the whole `alp`
command tree on the Zephyr shell **at link time**, so an application gets a
Linux-like diagnostic console on the SoM's UART — `board`, `gpio`, `i2c`,
`adc`, `pwm`, `mem`, `clk`, `reboot`, and `companion` — without registering a
single command itself.

:::note[Board shell vs host CLI]
This is **not** the [`tan` host CLI](https://docs.alplab.ai/sdk/tools/cli). That one runs on your
developer machine (`tan build` / `tan flash` / `tan run`). This one runs **on
the board**, typed into the serial console after boot (`uart:~$ alp board`) —
the console `tan monitor --port <port>` opens for you. Two surfaces, same
philosophy — one front door per surface — living on opposite ends of the cable.
:::

## Enabling it

```ini
# prj.conf
CONFIG_ALP_SDK_CONSOLE=y
```

The command tree is registered from `src/zephyr/console/alp_console.c` when the
symbol is on; `main()` does nothing to opt in. Read-only by default — the
write-capable verbs (`mem wr`, `gpio write`, `companion gpio write`) are gated
behind a separate switch:

```ini
CONFIG_ALP_SDK_CONSOLE_UNSAFE=y   # unlocks write verbs — leave OFF in field builds
```

## Command tree

Type `alp` and press **Tab** to explore. The core commands are backed by the
same portable SDK surfaces the C API uses:

| Command | Does | Backed by |
|---|---|---|
| `alp board` | SoM identity (rev, serial, part) | `<alp/hw_info.h>` + on-module EEPROM |
| `alp gpio …` | read / (unsafe) write pins | `<alp/peripheral.h>` GPIO |
| `alp i2c …` | probe / read I²C devices | `<alp/peripheral.h>` I²C |
| `alp adc …` | sample a channel | `<alp/adc.h>` |
| `alp pwm …` | drive a channel | `<alp/pwm.h>` |
| `alp mem …` | read / (unsafe) write memory | direct MMIO |
| `alp clk` | clock-tree summary | SoC clock control |
| `alp reboot` | reset the SoM | sys reboot |
| `alp companion …` | talk to the companion coprocessor | see below |

## `alp companion` — the coprocessor bridge

Every Alp SoM pairs the main SoC with a companion coprocessor; `alp companion`
is the console door to it. What the sub-commands are depends on the SoM:

| SoM | Companion | Sub-commands |
|---|---|---|
| E1M-AEN801 (Alif E8) | CC3501E Wi-Fi/BLE | `ver`, `ping`, `wifi …` (`scan`, `connect`, `disconnect`, `ap`, `ap-stop`, `status`), `ble …`, `sock …`, `diag …`, `recover`, `linklog`, `spi1 …` |
| E1M-X V2N | GD32 supervisor MCU | `ver`, `ping`, `gpio …` |

```
uart:~$ alp companion wifi scan
5 AP(s):
  MyNetwork                        ch5    -43 dBm  wpa3
  Guest-2.4GHz                     ch3    -59 dBm  wpa2
  IoT-Hub                          ch6    -84 dBm  open
uart:~$ alp companion wifi connect "MyNetwork" hunter2 wpa3
connecting to "MyNetwork" (wpa3)...
connected  rssi=-44 dBm
ip 192.0.2.74

uart:~$ alp companion ble enable
BLE controller + NimBLE host up
uart:~$ alp companion ble scan
10 device(s):
  66:c6:d2:91:31:26   -91 dBm  ET-2870 Series
  26:2a:8d:21:9d:4d   -50 dBm  (no name)
```

`wifi connect` takes an SSID plus an optional passphrase (no passphrase ⇒ open;
a trailing `wpa3` token forces WPA3-SAE) and prints the post-join RSSI and DHCP
IP. `wifi scan` decodes each AP's security (`open` / `wpa2` / `wpa3`) from the
CC3501E `SecurityInfo`.

**Changed in alp-sdk v0.17.0:**

- `wifi connect` waits up to **75 s** for the association (was 50 s). When an
  attempt fails or times out and the firmware's status latch confirms a failed
  attempt, the line now carries the firmware's reason code —
  `wifi connect to "<ssid>": timed out  reason: <n>` or
  `wifi connect to "<ssid>" failed (<err>)  reason: <n>` — and `wifi status`
  prints a `reason: <n>` line when one is latched.
- `alp companion ver` leads with the **firmware release version** and shows the
  wire-protocol version second — `fw 0.<minor>.<patch>  (wire <major>.<minor>)`,
  then `caps 0x<capabilities>` — instead of the old `CC3501E protocol v<n>`.
  The release version is the one to quote in a support request; if it cannot be
  read the line falls back to `wire <major>.<minor>  (release version unavailable)`.
- The console's event handler is now **added alongside** the application's own
  CC3501E event callback instead of replacing it. Before, binding the console
  silently swallowed every companion event an application had registered for.

### Argument checking, tightened in alp-sdk v0.16.0

`wifi connect` and `wifi ap` now validate the token shape as their **first act**, before
any state check — so a usage error is no longer misreported as "companion not
registered". Two guards were added, and both closed a *silent* misconfiguration:

- **An unrecognised 4th token is refused.** It used to be compared against `wpa3` and
  otherwise **ignored**, so `wifi ap myssid mypass wpa3x` silently started the soft-AP as
  **WPA2-PSK instead of WPA3-SAE**, and an unquoted SSID containing a space
  (`wifi ap my ssid secret`) silently split across the arguments — pushing the real
  passphrase into the 4th slot where it was dropped without a word, leaving an AP up on an
  SSID *fragment* with that fragment as its PSK. You now get:

  ```
  unrecognised argument "wpa3x" -- the only optional 4th token is "wpa3".
  an SSID or passphrase containing spaces must be quoted: wifi ap "my ssid" "my pass" [wpa3]
  ```

- **`wpa3` with an empty passphrase is refused.** The empty passphrase selected open, then
  the token overwrote it with WPA3-SAE-and-no-PSK — a combination that does not exist,
  since SAE has no open mode. Bench-measured as accepted on an E1M-AEN801 before the fix.

  ```
  "wpa3" requires a passphrase -- WPA3-SAE has no open mode.
  for an open soft-AP drop the token: wifi ap "my ssid"
  ```

`alp companion ble connect` got the same treatment: its 2nd token must now be `"random"`
or the command is refused, instead of any non-`"random"` value silently meaning public.

### RSSI is a live read now, and it is not free

The `rssi_dbm` byte in the CC3501E's Wi-Fi status latch is **decoded faithfully but is not
a measurement** — the firmware never populates it, so it always reads `0`, which is itself
a legal RSSI value a caller cannot distinguish from a real one. Both commands therefore
issue a separate live `WIFI_GET_RSSI` and say so when it fails:

- `wifi connect` prints `wifi connected "<ssid>"  rssi=<n> dBm` only when that read
  succeeds, and `wifi connected "<ssid>"  rssi=unavailable (<err>)` otherwise. Previously a
  discarded failure rendered as a plausible-looking `rssi=0 dBm` on **any** successful
  connect.
- `wifi status` no longer prints the latch byte at all. It prints `rssi:  <n> dBm` or
  `rssi:  unavailable (<err>)`, and gained an `ip:    unavailable (<err>)` branch.

:::caution[`wifi status` can block the shell thread for ~10 s — or ~20 s on a wedged bridge]
`WIFI_GET_RSSI` is worker-routed and floors its budget to `CC3501E_WIFI_DOWN_WINDOW_MS`
(**10 s**), because a fresh request lazy-starts the radio. On a wedged transport this
command's worst case is roughly **~20.1 s**, up from ~10.1 s — and it runs **on the shell
thread**, so the console is unresponsive for the duration. Its own help string says as
much: *"show connection state + rssi + ip (rssi is a live read, can take ~10s)"*.

If `alp companion ver` (a plain, non-worker, short-timeout request) also fails, the
transport is broken rather than mid-radio-op — the retry re-issues an identical SPI
transaction with no resync, no CS recovery and no reset, so it **cannot** recover a
genuinely wedged bridge.
:::

### The soft-AP: start is now confirmed, stop still is not

As of alp-sdk **v0.17.0**, `wifi ap` **confirms** the soft-AP: `cc3501e_wifi_ap_start()`
submits the start exactly once and then waits for the firmware's independent
`GET_DIAG_INFO` role field to report the AP role. Success prints
`ap "<ssid>" up (open|wpa2|wpa3)`; no confirmation within the 75 s budget prints
`ap start "<ssid>" failed (<err>) (not confirmed within the budget)`. The old
`ap start … unconfirmed … no AP status latch` message is gone.

`alp companion sock serve <port> [seconds]` (new in v0.17.0) listens on the
soft-AP and answers HTTP for the given time (default 60 s, at most 3600 s). It
prints the AP-side IP to aim a client at first, or warns
`ap ip: unavailable (<err>) -- is the AP started?` when the AP role is not up.

:::danger[`wifi ap-stop` is still inconclusive]
- **`wifi ap-stop` is conclusive only when there was nothing to stop.** Bench-measured on
  E1M-AEN801 (2026-08-18), reproducibly: no soft-AP running ⇒ `ALP_OK`; a soft-AP
  *actually running* ⇒ `ALP_ERR_TIMEOUT` **every time**, because teardown takes the bridge
  through the radio-down window and the ack is not observed across it. The shell prints
  `ap stop unconfirmed (<err>) -- firmware v4 has no AP-stop acknowledgement (#1553, same gap as #1385); confirm the SSID is gone out of band`,
  and `ap stopped` now appears only for the conclusive no-AP case.

**Hardware hazard:** an `ap start` followed by `ap-stop` is a reliable way to **wedge the
transport** — it has left the bridge returning `ALP_ERR_IO` to every subsequent request
until it was reset.

**Known defect (#1562), recorded against alp-sdk v0.16.0:** `wifi ap` brought up a soft-AP
that advertised for roughly **100 s and then stopped**. Confirm an AP stays up out of band
before relying on it.
:::

`alp companion diag info` gained a `wifievt:<n>` line carrying the **last Wi-Fi event ID**
— the cheap single-radio signal for #1562. A `0` after an `ap start` means **no WLAN event
ever fired**, which separates "the radio never got going" from "it came up and stopped"
without needing a second radio to watch for the SSID.

:::caution[Bench ordering]
On real silicon, run `ble enable` from a clean boot (or before a `wifi scan`).
A Wi-Fi scan immediately followed by `ble enable` can return `-4` — two
back-to-back heavy radio ops desync the CS-less inter-chip bridge. A firmware
fix is tracked.
:::

### Link recovery and diagnostics (new in alp-sdk v0.17.0)

Three more `alp companion` verbs on the CC3501E SoMs:

| Command | Does |
|---|---|
| `alp companion recover` | Warm-reset the inter-chip bridge link on demand and print `recover OK (<n> recovery(s) so far)`. During an OTA/update session it refuses with `recover refused: an OTA/update session is active`; while another recovery is already running it fails with `recover failed (<err>)` |
| `alp companion linklog` | Dump the link-failure ring, oldest entry first, with a one-line legend (timestamp, opcode, failing phase, status, flags, header bytes) |
| `alp companion spi1 configure <freq_hz> <mode 0..3> <cs 0\|1>` · `xfer <hexbytes> [hold] [norx]` · `read <len> [hold] [<fill>]` · `release` | Host passthrough to the CC3501E's **SPI1** controller, which serves the E1M connector's SPI1 on these SoMs: acquire the bus and print the **actual** SCK rate, run full-duplex transfers and print the received bytes, then release it. Meant for bench validation of a carrier SPI device; bulk transfers belong in an application |

The driver also recovers the link **automatically** after repeated failures. When it does,
the console prints the link-failure ring, then
`cc3501e: recovery probe: <n> PING(s) failed before the reset`, then
`cc3501e: link recovered by warm reset (#<n>)`. This notice is registered when you call
`alp_console_companion_set()`; an application that registers its own recovery callback
afterwards replaces it.

## Binding the companion from your app

On the Alif SoMs there is no companion singleton, so the application opens its
CC3501E and registers the handle once — that is the sole app-facing hook in
`<alp/console.h>`:

```c
#include <alp/console.h>

cc3501e_t *cc = /* your cc3501e_init(...) handle */;
alp_console_companion_set(cc);   // now `alp companion …` reaches Wi-Fi/BLE
```

On the V2N family the GD32 supervisor is a managed singleton inside the SDK, so
this call is a no-op — `alp companion` reaches the GD32 automatically. Passing
`NULL` unbinds. `alp_console_companion_set` is `[ABI-EXPERIMENTAL]` (new in
v0.9.0), tracking the experimental CC3501E companion surface it depends on.

## Reference example

`examples/peripheral-io/alp-console` is a single slot0 application that brings
the console up on the UART, binds the companion, and breathes an RGB status LED
in a background thread — one app demonstrating a Linux-like shell, live
Wi-Fi/BLE, and a "board is alive" indicator. `main()` registers no commands; it
only binds the companion and spawns the LED thread. It builds and runs
everywhere, including `native_sim` (no companion — the non-companion commands
still work).
