Initial bare-metal foundation for nRF52840 PTT-FHSS

- Fully open toolchain: arm-none-eabi-gcc inside Podman/Docker container
- Platform-agnostic build via justfile (auto-detects podman vs docker)
- CMake + Ninja build system with arm-none-eabi toolchain file
- nRF52840 linker script and startup with full 64-entry vector table
- Register access via typed bitfield unions (include/regs.h)
- FHSS channel sequencer: AES-128-ECB PRNG over 40 channels (2402-2480 MHz)
- Low-power sleep via SYSTEM_ON WFI + GPIOTE wakeup on button press
- Vendor deps as shallow git submodules: nrfx, CMSIS_5, tiny-AES-c
This commit is contained in:
Krzysztof Cieślik
2026-05-21 18:40:02 +02:00
commit f654df0e78
18 changed files with 641 additions and 0 deletions

6
include/fhss.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
#include <stdint.h>
void fhss_init(void);
uint8_t fhss_next_channel(void); /* next channel from AES-ECB PRNG sequence */
void fhss_sync_tick(void); /* call every FHSS_DWELL_MS ms */

4
include/power.h Normal file
View File

@@ -0,0 +1,4 @@
#pragma once
void power_init(void);
void power_sleep_until_button(void); /* SYSTEM_ON WFI, woken by GPIOTE event */

7
include/radio.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
#include <stdint.h>
void radio_init(void);
void radio_set_channel(uint8_t ch); /* 039, maps to 24022480 MHz */
void radio_tx(const uint8_t *data, uint8_t len);
void radio_tx_burst(void); /* TX with FHSS hopping */

90
include/regs.h Normal file
View File

@@ -0,0 +1,90 @@
#pragma once
#include <stdint.h>
/*
* Hardware register bitfield unions for nRF52840 peripherals.
* Layout is guaranteed correct only with arm-none-eabi-gcc (LSB-first bitfields).
* Bit ranges match nRF52840 Product Specification v1.7.
*/
/* ── GPIOTE ──────────────────────────────────────────────────────────────── */
/* CONFIG[n] — channel configuration */
typedef union {
struct {
uint32_t MODE : 2; /* [1:0] 0=Disabled 1=Event 3=Task */
uint32_t : 6; /* [7:2] reserved */
uint32_t PSEL : 5; /* [12:8] pin number within port */
uint32_t PORT : 1; /* [13] 0=Port0 1=Port1 */
uint32_t : 2; /* [15:14] reserved */
uint32_t POLARITY : 2; /* [17:16] 0=None 1=LoToHi 2=HiToLo 3=Toggle */
uint32_t : 2; /* [19:18] reserved */
uint32_t OUTINIT : 1; /* [20] initial output value for Task mode */
uint32_t : 11; /* [31:21] reserved */
} bit;
uint32_t reg;
} gpiote_config_t;
#define GPIOTE_MODE_DISABLED 0u
#define GPIOTE_MODE_EVENT 1u
#define GPIOTE_MODE_TASK 3u
#define GPIOTE_POL_NONE 0u
#define GPIOTE_POL_LOTOHI 1u
#define GPIOTE_POL_HITOLO 2u
#define GPIOTE_POL_TOGGLE 3u
/* INTENSET / INTENCLR — interrupt enable */
typedef union {
struct {
uint32_t IN0 : 1; /* [0] channel 0 input event */
uint32_t IN1 : 1; /* [1] channel 1 input event */
uint32_t IN2 : 1; /* [2] */
uint32_t IN3 : 1; /* [3] */
uint32_t IN4 : 1; /* [4] */
uint32_t IN5 : 1; /* [5] */
uint32_t IN6 : 1; /* [6] */
uint32_t IN7 : 1; /* [7] */
uint32_t : 23; /* [30:8] reserved */
uint32_t PORT : 1; /* [31] PORT event */
} bit;
uint32_t reg;
} gpiote_inten_t;
/* ── RADIO ───────────────────────────────────────────────────────────────── */
/* FREQUENCY — radio channel */
typedef union {
struct {
uint32_t FREQUENCY : 7; /* [6:0] offset from base frequency in MHz */
uint32_t : 1; /* [7] reserved */
uint32_t MAP : 1; /* [8] 0: base=2400 MHz 1: base=2360 MHz */
uint32_t : 23; /* [31:9] reserved */
} bit;
uint32_t reg;
} radio_frequency_t;
#define RADIO_MAP_DEFAULT 0u /* channel n → 2400+n MHz */
#define RADIO_MAP_BLE 1u /* channel n → 2360+n MHz */
/* TXPOWER — transmit power */
typedef union {
struct {
int32_t TXPOWER : 8; /* [7:0] signed dBm: +8, +7, +6, +5, +4, +3, +2,
0, -4, -8, -12, -16, -20, -40 */
uint32_t : 24; /* [31:8] reserved */
} bit;
uint32_t reg;
} radio_txpower_t;
/* MODE — radio data rate and modulation */
typedef union {
struct {
uint32_t MODE : 4; /* [3:0] 0=NRF_1Mbit 1=NRF_2Mbit 4=BLE_1Mbit … */
uint32_t : 28; /* [31:4] reserved */
} bit;
uint32_t reg;
} radio_mode_t;
#define RADIO_MODE_NRF_1MBIT 0u
#define RADIO_MODE_NRF_2MBIT 1u
#define RADIO_MODE_BLE_1MBIT 4u