diff --git a/FprimeZephyrReference/project/config/LoRaCfg.hpp b/FprimeZephyrReference/project/config/LoRaCfg.hpp index a2404a2..5b3097d 100644 --- a/FprimeZephyrReference/project/config/LoRaCfg.hpp +++ b/FprimeZephyrReference/project/config/LoRaCfg.hpp @@ -4,10 +4,12 @@ #include 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 diff --git a/README.md b/README.md index 2415fed..1310be6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/boards/proves/proves_flight_control_board_v5e/Kconfig b/boards/proves/proves_flight_control_board_v5e/Kconfig new file mode 100644 index 0000000..640c9e1 --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/Kconfig @@ -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 diff --git a/boards/proves/proves_flight_control_board_v5e/board.yml b/boards/proves/proves_flight_control_board_v5e/board.yml new file mode 100644 index 0000000..e71e059 --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/board.yml @@ -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 diff --git a/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_hardware.dtsi b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_hardware.dtsi new file mode 100644 index 0000000..4996cdd --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_hardware.dtsi @@ -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_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 = , ; + }; + + group2 { + pinmux = ; + 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 = ; + 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>; + }; +}; diff --git a/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.dts b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.dts new file mode 100644 index 0000000..b209548 --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.dts @@ -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 +#include +#include <../boards/raspberrypi/rpi_pico2/rpi_pico2.dtsi> +#include <../boards/raspberrypi/common/rpi_pico-led.dtsi> +#include "proves_flight_control_board_v5e_hardware.dtsi" diff --git a/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.yaml b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.yaml new file mode 100644 index 0000000..e9a8a70 --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33.yaml @@ -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 diff --git a/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33_defconfig b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33_defconfig new file mode 100644 index 0000000..41537e3 --- /dev/null +++ b/boards/proves/proves_flight_control_board_v5e/proves_flight_control_board_v5e_rp2350a_m33_defconfig @@ -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 diff --git a/patches/README.md b/patches/README.md new file mode 100644 index 0000000..651fe1f --- /dev/null +++ b/patches/README.md @@ -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 +``` + +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. diff --git a/patches/zephyr-sx126x-wakeup-busy-delay.patch b/patches/zephyr-sx126x-wakeup-busy-delay.patch new file mode 100644 index 0000000..7bb5550 --- /dev/null +++ b/patches/zephyr-sx126x-wakeup-busy-delay.patch @@ -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); ++ + LOG_DBG("Waiting for device..."); + SX126xWaitOnBusy(); + LOG_DBG("Device ready"); diff --git a/prj.conf b/prj.conf index 58c1a1d..178f522 100644 --- a/prj.conf +++ b/prj.conf @@ -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. diff --git a/settings.ini b/settings.ini index 0ff63e7..65359b0 100644 --- a/settings.ini +++ b/settings.ini @@ -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 \ No newline at end of file + # BOARD=proves_flight_control_board_v5/rp2350a/m33 + # BOARD=proves_flight_control_board_v5e/rp2350a/m33 \ No newline at end of file