Firmware for the CommonSense project.
Go to file
2025-10-04 02:07:12 +02:00
.cargo Adapt Cargo.toml, .cargo/config.toml, and memory.x to the nRF52832 2025-10-03 01:05:59 +02:00
src/bin Refactor temp and humidity measurement code into structs with traits 2025-10-04 02:07:12 +02:00
.gitignore Basic project setup (#1) 2024-11-01 23:49:53 +00:00
build.rs Basic project setup (#1) 2024-11-01 23:49:53 +00:00
Cargo.lock Make ble_gatt_server.rs work with the nRF552 DK 2025-10-03 01:05:59 +02:00
Cargo.toml Add settings to disable test warnings to Cargo.toml 2025-10-04 02:06:47 +02:00
Dockerfile Basic project setup (#1) 2024-11-01 23:49:53 +00:00
LICENSE Initial commit 2023-08-24 19:13:43 +00:00
memory.x Make memory.x more similar to the nRF52810 version 2025-10-03 01:05:59 +02:00
README.md Add troubleshooting note about fixing locked up core 2025-10-03 01:05:05 +02:00
s112_nrf52_7.3.0_softdevice.hex Make software compatible with commonsense-hw 2025-09-30 00:50:14 +02:00
s132_nrf52_7.3.0_softdevice.hex Basic project setup (#1) 2024-11-01 23:49:53 +00:00

CommonSense

Firmware for the CommonSense project.

Compile and Run

The firmware depends on the S132 softdevice. Before running the firmware, the softdevice has to flashed to the chip.

Flashing the Softdevice

  1. Erase the chip
    $ probe-rs erase --chip nRF52832_xxAA
    
  2. Flash the softdevice
    $ probe-rs download --verify --binary-format hex --chip nRF52832_xxAA s132_nrf52_7.3.0_softdevice.hex
    

Compile and Run

  1. Install the required tools. Consult Dockerfile for specifics
  2. Build the firmware
    $ cargo build --release
    
  3. Flash / run the firmware
    $ cargo fr
    $ # OR
    $ cargo run --release
    

Compile and Run using Docker

  1. Build the docker image
    $ docker build . -t commonsense
    
  2. Build the firmware
    $ docker run --rm -v $PWD:$PWD -w $PWD -u $(id -u):$(id -g) commonsense cargo build --release
    
  3. Flash / run the firmware
    $ docker run --privileged -v /dev/bus/usb/:/dev/bus/usb --rm -v $PWD:$PWD -w $PWD -u $(id -u):$(id -g) commonsense cargo fr
    $ # OR
    $ docker run --privileged -v /dev/bus/usb/:/dev/bus/usb --rm -v $PWD:$PWD -w $PWD -u $(id -u):$(id -g) commonsense cargo run --release
    

Notes

Troubleshooting

Core locking up

One possible cause for the core to lock up is to have a flash memory configuration that doesn't match the selected softdevice.

Background

When the device powers up, it looks for certain things at certain positions in memory, namely the interrupt vector table and the program entrypoint. The interrupt vector table and entrypoint it finds are from the softdevice. After initialization, the softdevice then attempts to hand over control to the user program. The user program again has an interrupt vector table and an entrypoint that are expected to be at a certain position in memory. Specifically, they are expected to be right after the softdevice. If they are not there, the device enters a hard fault state and locks up the core.

This means that the flash memory configuration in memory.x has to be correct for the program to start up properly:

MEMORY
{
  FLASH : ORIGIN = 0x00000000 + <softdevice size>, LENGTH = <flash memory size> - <softdevice size>
  ...
}

The softdevice size can be found in the release notes of the softdevice. This is a pdf that is downloaded along with the hex file from the nordic website. The flash memory size depends on the model of microcontroller used.

Solution

  1. Make sure memory.x is configured correctly for the selected softdevice. E.g., for S112 running on an nRF52832 chip:
    MEMORY
    {
      FLASH : ORIGIN = 0x00000000 + 100K, LENGTH = 512K - 100K
      RAM : ORIGIN = 0x20000000 + 30K, LENGTH = 64K - 30K
    }
    
  2. Recover the device from it's locked state. This erases the flash memory:
    $ probe-rs erase --chip nRF52832_xxAA --allow-erase-all
    
  3. Compile and flash the program:
    $ cargo run --bin blinky --release
    
    The program will not run successfully at this time, as it requires the softdevice to be flashed as well.
  4. Flash the desired softdevice, e.g., S112:
    $ probe-rs download --verify --binary-format hex --chip nRF52832_xxAA s112_nrf52_7.3.0_softdevice.hex