Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions FprimeZephyrReference/project/config/LoRaCfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

#include <zephyr/drivers/lora.h>
namespace LoRaConfig {
const U32 DEFAULT_FREQ = 437400000; //!< LoRa frequency in Hz
lora_signal_bandwidth BANDWIDTH = BW_125_KHZ; //!< LoRa bandwidth
const I8 TX_POWER = 23; //!< LoRa transmission power in dBm
const U16 PREAMBLE_LENGTH = 8; //!< LoRa preamble length
U8 HEADER[0] = {}; //!< No LoRa payload header
const U32 DEFAULT_FREQ = 437400000; //!< LoRa frequency in Hz
const lora_signal_bandwidth BANDWIDTH = BW_125_KHZ; //!< LoRa bandwidth
const I8 TX_POWER = 23; //!< LoRa transmission power in dBm
const U16 PREAMBLE_LENGTH = 8; //!< LoRa preamble length
const U8 HEADER[] = {
0, 0, 0,
0}; //!< LoRa payload header — size must match flight LoRaCfg::HEADER (flight strips sizeof(HEADER) bytes on RX)
} // namespace LoRaConfig
#endif // LORA_CFG_HPP
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ and change:
+BOARD=proves_flight_control_board_v5/rp2350a/m33
```

Use `proves_flight_control_board_v5e/rp2350a/m33` for the v5e board, which
carries an SX1262-based E22-400M30S LoRa module instead of the v5's SX1276.
The right LoRa driver is picked automatically from the board devicetree.
After changing boards, regenerate with `make generate-force` before building.

The v5e additionally needs the SX126x wake-up fix from `patches/` applied to
the Zephyr submodule (see `patches/README.md`); without it, `SET_FREQ`
intermittently fails to retune the radio in release builds.

### Workflow

Most important operations in this repo have a Make helper.
Expand Down
4 changes: 4 additions & 0 deletions boards/proves/proves_flight_control_board_v5e/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

config BOARD_PROVES_FLIGHT_CONTROL_BOARD_V5E
select SOC_RP2350A_M33 if BOARD_PROVES_FLIGHT_CONTROL_BOARD_V5E_RP2350A_M33
10 changes: 10 additions & 0 deletions boards/proves/proves_flight_control_board_v5e/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
#
# PROVES Flight Control Board v5e — DTS = upstream Pico 2 base + proves_flight_control_board_v5e_hardware.dtsi.

board:
name: proves_flight_control_board_v5e
full_name: PROVES Flight Control Board v5e
vendor: PROVES
socs:
- name: rp2350a
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Project-specific hardware for PROVES Flight Control Board v5e.
* Same wiring intent as the v5 port, but the v5e carries an SX126x-based
* LoRa module (E22-400M30S) instead of the v5's SX1276.
*/

#include <zephyr/dt-bindings/lora/sx126x.h>

&zephyr_udc0 {
/* Control port */
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
/* Data port */
cdc_acm_uart1: cdc_acm_uart1 {
compatible = "zephyr,cdc-acm-uart";
};
};

&pinctrl {
spi1_default: spi1_default {
group1 {
pinmux = <SPI1_SCK_P10>, <SPI1_TX_P11>;
};

group2 {
pinmux = <SPI1_RX_P12>;
input-enable;
};
};
};

&spi1 {
status = "okay";
cs-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
pinctrl-0 = <&spi1_default>;
pinctrl-names = "default";

lora0: sx1262@0 {
compatible = "semtech,sx1262";
reg = <0>;
spi-max-frequency = <125000>;
reset-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
busy-gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
dio1-gpios = <&gpio0 14 GPIO_ACTIVE_HIGH>;
tx-enable-gpios = <&gpio0 21 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
rx-enable-gpios = <&gpio0 22 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
dio3-tcxo-voltage = <SX126X_DIO3_TCXO_1V8>;
tcxo-power-startup-delay-ms = <10>;
rx-boosted;
label = "E22-400M30S";
};
};

/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};

fstab {
compatible = "zephyr,fstab";
ffs1: ffs1 {
compatible = "zephyr,fstab,fatfs";
disk-access;
automount;
mount-point = "/";
};
};

ramdisk0 {
compatible = "zephyr,ram-disk";
disk-name = "RAM";
sector-size = <512>;
sector-count = <128>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Same composition as Zephyr upstream rpi_pico2_rp2350a_m33.dts, plus
* proves_flight_control_board_v5e_hardware.dtsi (project-specific nodes only).
*/

/dts-v1/;

#include <raspberrypi/rpi_pico/rp2350a.dtsi>
#include <raspberrypi/rpi_pico/m33.dtsi>
#include <../boards/raspberrypi/rpi_pico2/rpi_pico2.dtsi>
#include <../boards/raspberrypi/common/rpi_pico-led.dtsi>
#include "proves_flight_control_board_v5e_hardware.dtsi"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
identifier: proves_flight_control_board_v5e/rp2350a/m33
name: PROVES Flight Control Board v5e (RP2350, Cortex-M33)
type: mcu
arch: arm
flash: 4096
ram: 520
toolchain:
- zephyr
- gnuarmemb
supported:
- adc
- clock
- counter
- dma
- gpio
- hwinfo
- i2c
- pwm
- spi
- uart
- usbd
- watchdog
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
# Minimal defaults — same baseline as upstream rpi_pico2_rp2350a_m33_defconfig.
# Application merges prj.conf on top.

CONFIG_BUILD_OUTPUT_HEX=y
CONFIG_BUILD_OUTPUT_UF2=y
CONFIG_CLOCK_CONTROL=y
CONFIG_CONSOLE=y
CONFIG_GPIO=y
CONFIG_RESET=y
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_USE_DT_CODE_PARTITION=y
32 changes: 32 additions & 0 deletions patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Patches

Local patches for submodules that cannot carry the change directly (the
`lib/zephyr-workspace/zephyr` submodule points at upstream
`zephyrproject-rtos/zephyr`).

## zephyr-sx126x-wakeup-busy-delay.patch

**Required for SX126x-based boards (`proves_flight_control_board_v5e`).**

The Zephyr SX126x driver polls the BUSY line immediately after the wake-up
SPI transaction. The chip needs up to ~340us (datasheet warm-start time)
after the wake-up NSS edge before it is ready, and there is a window where
BUSY has not yet been asserted. When the poll wins that race, the next SPI
command is clocked into a chip that is still starting up and is silently
ignored. Since the driver re-enters sleep after every operation and the
first command after wake is always `SetRfFrequency`, the practical symptom
is that `SET_FREQ` intermittently does not retune the radio (~40% of
attempts measured on a Flight Control Board v5e in release builds; debug
builds mask the race because logging adds delay).

Apply with:

```
cd lib/zephyr-workspace/zephyr
git apply ../../../patches/zephyr-sx126x-wakeup-busy-delay.patch
```
Comment on lines +24 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Label the shell command block.

Line 24 should use ```bash so Markdown linting can identify the command language.

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 24-24: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@patches/README.md` around lines 24 - 27, Label the shell command code block
containing the git apply command with the bash language identifier by changing
its opening fence to ```bash.

Source: Linters/SAST tools


This should be submitted to upstream Zephyr; the patch can be dropped once
the submodule advances past a release containing the fix. SX127x-based
boards (`ground_radio_controller`, v5) do not compile this file and are
unaffected.
19 changes: 19 additions & 0 deletions patches/zephyr-sx126x-wakeup-busy-delay.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/drivers/lora/loramac_node/sx126x.c b/drivers/lora/loramac_node/sx126x.c
index 6221943f5..d4ac247b9 100644
--- a/drivers/lora/loramac_node/sx126x.c
+++ b/drivers/lora/loramac_node/sx126x.c
@@ -394,6 +394,14 @@ void SX126xWakeup(void)
return;
}

+ /* The chip takes up to ~340us (datasheet t_woff, warm start) after
+ * the wake-up NSS edge before it is ready. Polling BUSY immediately
+ * can sample it before the chip has asserted it, in which case the
+ * next command is clocked into a device still starting up and is
+ * silently ignored. Wait out the startup window before polling.
+ */
+ k_busy_wait(500);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused about this patch. We're not sleeping the radio as far as I know. And in any case the datasheet doesn't say "wait after wake" to send commands, it says "wait after sleep".

It is possible the delay just changed the timing of things so as to disguise a race condition causing the intermittent SET_FREQ failures the new README mentions.

+
LOG_DBG("Waiting for device...");
SX126xWaitOnBusy();
LOG_DBG("Device ready");
7 changes: 4 additions & 3 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ CONFIG_I2C=n
CONFIG_SPI=y
# Enable SPI, used by LoRa radio
CONFIG_LORA=y
# Enable LoRa driver support
CONFIG_LORA_SX127X=y
# Enable Semtech SX127x LoRa driver
# Enable LoRa driver support. The modem driver is selected by the board
# devicetree: LORA_SX127X defaults on for boards with an sx1276 node
# (ground_radio_controller, v5) and LORA_SX126X for boards with an sx1262
# node (v5e). Hard-setting either here breaks boards with the other radio.
CONFIG_PINCTRL=y
# Enable pin control.

Expand Down
3 changes: 2 additions & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF
BOARD_ROOT=.
BOARD=ground_radio_controller/rp2350a/m33

# BOARD=proves_flight_control_board_v5/rp2350a/m33
# BOARD=proves_flight_control_board_v5/rp2350a/m33
# BOARD=proves_flight_control_board_v5e/rp2350a/m33