m20-custom-firmware/README.md

222 wiersze
8.6 KiB
Markdown
Czysty Zwykły widok Historia

2024-03-17 12:03:55 +00:00
# m20-custom-firmware
2025-02-24 16:06:32 +00:00
The goal of this project is to reverse engineer the Meteomodem M20 radiosonde and build custom firmware for its usage in ham radio baloons based on the [Horus Binary V2](https://github.com/projecthorus/horusdemodlib/wiki) radio protocol.
2025-01-10 21:49:32 +00:00
2025-02-22 11:44:21 +00:00
# Code
2025-02-24 16:06:32 +00:00
The code is writen in C using STM32CubeMX and Low Layer (LL) libraries and compiled using arm-none-eabi toolchain. Now it fits into the original STM32L051R6T6 chip.
2025-01-10 21:49:32 +00:00
# Stage
2025-02-22 11:44:21 +00:00
In this state the code works to the point where it gets GPS data and sends it using Horus Binary over radio. However this code is currently highly experimental and will probably not yet work correctly in the intended application.
2025-01-10 21:49:32 +00:00
2024-03-17 12:03:55 +00:00
# What works
2025-01-10 21:49:32 +00:00
- GPS (NMEA): :heavy_check_mark:
2025-02-22 11:44:21 +00:00
- GPS (XM1110) :heavy_check_mark:
2025-01-10 21:49:32 +00:00
- Radio: :heavy_check_mark:
2024-03-17 12:03:55 +00:00
- Uart: :heavy_check_mark:
2025-01-10 21:49:32 +00:00
- Outside temperature sensor: :x:
2025-02-22 11:44:21 +00:00
- LPS22 barometer + temp sensor: :x: (to be done soon)
2024-03-17 12:03:55 +00:00
- humidity sensor: :x:
2025-02-22 19:44:00 +00:00
# Features list
2025-02-24 16:06:32 +00:00
The currently implemented features are:
- GPS time, position, altitude, speed, ascent rate and number of satellites (NMEA and XM1110)
- Sending data over radio using Horus Binary V2 protocol
- Getting battery voltage
- Watchdog timer
2025-02-22 19:44:00 +00:00
# Planned work
- making the LPS22 sensor work
- making use of STM32 energy saving states
2025-02-24 16:06:32 +00:00
- rewriting nmea.c
2025-02-22 19:44:00 +00:00
- implementing outside temperature and humidity sensors
2025-02-24 16:06:32 +00:00
- implementing APRS
2025-02-22 19:44:00 +00:00
2025-02-22 18:58:24 +00:00
# Authors
- Paweł SQ2IPS
- Jędrzej SQ2DK
# License
2025-02-22 18:58:44 +00:00
See LICENSE
2025-02-22 18:58:24 +00:00
2024-03-22 19:23:43 +00:00
# Images
2025-01-10 21:49:32 +00:00
2024-03-22 19:23:43 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/side.jpg?raw=true)
2024-03-22 19:25:19 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/pcb.jpg?raw=true)
2025-02-22 18:29:10 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/pcb2.jpg?raw=true)
2024-03-22 19:23:43 +00:00
2024-03-22 19:37:48 +00:00
# Schematics
2025-01-10 21:49:32 +00:00
Great pcb reverse enginering work was made by [joyel24](https://github.com/joyel24/M20-radiosonde-firmware-alt), [PDF link](https://www.egimoto.com/dwld/17528ed1858138.pdf) (although there are some errors in it)
2024-03-22 19:37:48 +00:00
2025-01-10 22:14:10 +00:00
# Used libraries
2025-01-10 22:14:38 +00:00
- NMEA parsed based on https://github.com/sztvka/stm32-nmea-gps-hal
- LPS22 implementation based on https://github.com/KitSprout/KSDK/tree/master/firmwareSTM32/KSSTM_Module_LPS22HB/Program/modules
- Radio modules implementation based on https://github.com/adamgreig/wombat
- Horus Binary encoder based on https://github.com/whallmann/RS41HUP_V2/blob/master/horus_l2.c
2025-01-10 22:14:10 +00:00
2025-02-22 11:44:21 +00:00
# GPS
There are 2 variants of GPS modules, both of them are supported.
2025-02-22 18:29:10 +00:00
## New GPS (NMEA)
2025-02-24 16:06:32 +00:00
In newer M20 sondes u-blox MAX-M10M that uses NMEA protocol is used.
2025-02-22 18:32:04 +00:00
2025-02-22 18:31:23 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/gps_new.jpg?raw=true)
2025-01-10 21:49:32 +00:00
2025-02-22 18:29:10 +00:00
## Old GPS (XM1110)
2025-02-24 16:06:32 +00:00
In older M20 sondes XM1110 GPS module is used. It transmits data over UART but with custom firmware that transmits only binary protocol data.
2025-02-22 18:32:04 +00:00
2025-02-22 18:31:23 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/gps_old.jpg?raw=true)
2025-02-22 21:30:08 +00:00
2024-03-22 19:23:43 +00:00
Data format:
2025-02-22 18:32:20 +00:00
2025-02-22 18:32:04 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/GPS.png?raw=true)
2024-04-04 14:12:04 +00:00
2025-01-10 21:49:32 +00:00
# Barometer and temp sensor
2025-02-24 16:06:32 +00:00
LPS22HB sensor is used with SPI interface.
2024-03-22 19:23:43 +00:00
2024-03-22 19:37:48 +00:00
# Radio
TODO
2025-02-22 11:44:21 +00:00
2025-02-22 18:29:10 +00:00
# Running the firmware
2025-02-22 19:31:15 +00:00
## What you will need
Hardware requirements:
- A working M20 radiosonde :)
- A ST-Link v2 programmer USB dongle that looks like this:
![alt text](https://cdn-shop.adafruit.com/970x728/2548-01.jpg)
- 5 male to female goldpin jumper wires
2025-02-24 16:06:32 +00:00
- A computer with Linux or Windows
2025-02-22 19:31:15 +00:00
2025-02-22 19:34:08 +00:00
## Downloading code
2025-02-22 18:29:10 +00:00
First you need to obtain the code, you can do it with `git`:
```bash
git clone https://github.com/sq2ips/m20-custom-firmware.git
```
2025-02-24 16:06:32 +00:00
From github website "code" button, or directly from [here](https://github.com/sq2ips/m20-custom-firmware/archive/refs/heads/main.zip), and then unzip the file.
2025-02-22 18:34:51 +00:00
# Configuration
2025-02-22 18:29:10 +00:00
Before building the firmware you fist need to configure parameters located in the [`config.h`](https://github.com/sq2ips/m20-custom-firmware/blob/main/m20/Core/Inc/config.h) file.
TODO description
2025-02-22 18:34:51 +00:00
# Building the firmware
2025-02-22 21:30:08 +00:00
Before flashing the firmware you need to build it first, there are a few ways you can do it depending on the platform:
2025-02-22 18:34:51 +00:00
## Building directly on Linux
2025-02-22 18:29:10 +00:00
To build directly on linux you need the arm-none-eabi toolchain, you can install it from your package manager depending on the linux distro.
For example, on Debian it will look like this:
```bash
sudo apt install gcc-arm-none-eabi
```
2025-02-22 21:30:08 +00:00
### WARNING: in different distros version of the toolchain can varry and result in a too big result file
A way to avoids this problem is downloading the toolchain from [here](https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi.tar.xz).
2025-02-22 18:29:10 +00:00
After downloading you need to extract it:
```bash
tar -xvf arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi.tar.xz
```
and install the binaries into your system:
```bash
sudo cp arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi/bin/* /usr/local/bin/
```
You will also need `make` to build.
```bash
sudo apt install make
```
After installing everything you can go into the directory where you do downloaded the code, then:
```bash
cd m20
```
And now you can `make` the firmware:
```bash
make
```
After succesful building you should see a memoy usage table like this:
2025-02-22 18:34:03 +00:00
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/memory.png?raw=true)
2025-02-22 18:29:10 +00:00
2025-02-22 18:34:51 +00:00
## Building with Docker on Linux
2025-02-22 18:43:56 +00:00
First you need to get Docker, you can install it from your package manager depending on the linux distro.
For example, on Debian it will look like this:
```bash
sudo apt install docker
```
Then you need to add your user into the docker group like so:
```bash
sudo groupadd docker && sudo usermod -aG docker $USER
```
Now you need to start the docker daemon:
```bash
sudo systemctl start docker
```
But you will need to do it again after reboot of your computer, you can set it to autostart:
```bash
sudo systemctl enable docker
```
Now you should into the directory of the downloaded code, then:
```bash
cd m20
```
And now build the Docker image:
```bash
docker build -t m20 .
```
It will need some time to download an install the packages, after it finishes run:
```bash
docker run --rm -v .:/opt/m20 m20:latest
```
It will build the code and after finishing you should see a memory usage table just like in the previous method.
2025-02-23 10:14:13 +00:00
## Building with MinGW on Windows
First [download MSYS2](https://www.msys2.org/), then install it, after finishing the setup you should now see a terminal.
2025-02-23 13:10:32 +00:00
Now install `make`:
2025-02-23 10:18:37 +00:00
```bash
2025-02-23 13:10:32 +00:00
pacman -Sy make
2025-02-23 10:18:37 +00:00
```
2025-02-23 10:20:17 +00:00
Confirm the instalation and wait for the packages to download and install.
2025-02-23 13:10:32 +00:00
TODO
2025-02-22 18:34:51 +00:00
## Building with Docker on Windows
2025-02-22 21:41:00 +00:00
First [download Docker Desktop](https://www.docker.com/products/docker-desktop/) and install it.
2025-02-22 21:59:17 +00:00
TODO
2025-02-22 19:18:28 +00:00
# Flashing the firmware
2025-02-24 16:06:32 +00:00
## Connecting
2025-02-22 19:18:28 +00:00
Before flashing you first need to connect the sonde to your computer through the ST-LINK programmer.
You can do it using 5 goldpin cables. This is the sonde pinout:
![alt text](https://github.com/sq2ips/m20-custom-firmware/blob/main/img/pinout.jpg?raw=true)
Follow it and the pinout of the programmer printed on the case.
After connecting it and the programmer to your USB port you are now ready to flash the firmware.
2025-02-22 19:44:00 +00:00
You don't need to solder the wires, instead you can just put them into the connector, it should make enough contact for the firmware to flash.
2025-02-22 19:18:28 +00:00
## Flashing on Linux
For flashing you will need the OpenOCD you can install it from your package manager depending on the linux distro.
For example, on Debian it will look like this:
```bash
sudo apt install openocd
```
2025-02-24 16:06:32 +00:00
After installing it and ensuring that you are in the `m20` directory. Then check if ST-Link is connected and then you can remove the write protection (only before the first flash):
2025-02-22 19:18:28 +00:00
```bash
make protection
```
or if you don't have `make` or want to run it directly:
```bash
2025-02-23 13:27:12 +00:00
openocd -s ./openocd/ -f ./openocd/openocd_m20.cfg -c "init; halt; flash protect 0 0 7 reset; exit"
2025-02-22 19:18:28 +00:00
```
2025-02-24 16:06:32 +00:00
After it finishes you can flash the built firmware:
2025-02-22 19:18:28 +00:00
```bash
make flash
```
or directly
```bash
2025-02-23 13:27:12 +00:00
openocd -s ./openocd/ -f ./openocd/openocd_m20.cfg -c "program build/m20.elf verify reset exit"
2025-02-22 19:18:28 +00:00
```
After it finishes your sonde should now work with the new firmware.
2025-02-22 19:23:14 +00:00
2025-02-22 21:41:00 +00:00
## Flashing on Windows
2025-02-24 16:06:32 +00:00
First [download OpenOCD](https://github.com/xpack-dev-tools/openocd-xpack/releases/latest) select the file with ending `win32-x64.zip`, then extract it.
2025-02-23 13:41:13 +00:00
Go to the path of the project then to `m20/`. Ensure that ST-Link is connected and then remove the write protection (only before the first flash):
```cmd
<path\to\openocd>\bin\openocd.exe -s openocd -f openocd\openocd_m20.cfg -c "init; halt; flash protect 0 0 7 reset; exit"
```
2025-02-24 16:06:32 +00:00
replace `<path\to\openocd>` with path of the extracted program.
2025-02-23 13:42:10 +00:00
After it finishes you can flash the built firmware:
2025-02-23 13:41:13 +00:00
```cmd
<path\to\openocd>\bin\openocd.exe -s ./openocd/ -f openocd\openocd_m20.cfg -c "program build\m20.elf verify reset exit"
```
After it finishes your sonde should now work with the new firmware.
2025-02-22 21:41:00 +00:00
2025-02-22 19:23:14 +00:00
# Debuging (TODO)