805bb886c0
* Boot: switch to DFU routines. Implements #132 part 1 of 2. * Boot: boot to DFU shortcut, hard reset USB on each boot. Implements #132 part 2 of 2. * Deploy scripts: fix path for deploy dfu. * Bootloader: initial version. Target_f2: rebase, update deployment scripts. * Bootloader: cleanup, refactor switch2 proc. Readme,wiki: document bootloader. * Wiki: deploy symlinks as files, bootloader info. * Target_f2: valid flash size in linker script. * Github CI: bootloader build and artifacts. * Bootloader: rename platforms to targets. * Bootloader: change dfu/os colors. * disable set -e * lint code * add bootloader testing page Co-authored-by: Aleksandr Kutuzov <aku@plooks.com> Co-authored-by: aanper <mail@s3f.ru>
137 lines
5.6 KiB
Markdown
137 lines
5.6 KiB
Markdown
_Overview of Flipper firmware architecture:_
|
||
|
||
![FW arch](https://github.com/Flipper-Zero/flipperzero-firmware-community/raw/master/wiki_static/flipper_fw_arch.png)
|
||
|
||
# Project structure
|
||
|
||
```
|
||
.
|
||
├── applications # Flipper applications
|
||
│ └── furi_test # Test app for checking and demonstrating FURI func
|
||
├── bootloader # Firmware bootloader, used for `target_f2` and newer
|
||
├── core # Main feature like OS, HAL (target-independed)
|
||
├── target_f1 # Target-depended code for target F1
|
||
│ ├── Drivers # STM HAL drivers
|
||
│ │ ├── CMSIS
|
||
│ │ └── STM32L4xx_HAL_Driver
|
||
│ │ ├── Inc
|
||
│ │ │ └── Legacy
|
||
│ │ └── Src
|
||
│ ├── Inc # Autogenerated CubeMX code and target-depended includes
|
||
│ ├── Middlewares
|
||
│ │ ├── ST
|
||
│ │ │ └── STM32_USB_Device_Library
|
||
│ │ └── Third_Party
|
||
│ │ └── FreeRTOS
|
||
│ └── Src # Autogenerated CubeMX code and target-depended sources
|
||
├── target_lo # Target-depended code for local linux target
|
||
│ ├── Inc
|
||
│ └── Src
|
||
└── wiki # Documentation (wiki) generates from this files
|
||
├── applications # info about separate features of flipper
|
||
├── fw # core, environment info about firmware
|
||
└── hw # info about hardware
|
||
```
|
||
|
||
# HAL
|
||
|
||
We use STM32 HAL/LL. Description available here: [dm00105879.pdf](https://github.com/Flipper-Zero/flipperzero-firmware-community/raw/master/wiki_static/dm00105879-description-of-stm32f4-hal-and-ll-drivers-stmicroelectronics.pdf)
|
||
|
||
## Flipper HAL
|
||
|
||
Some flipper-specific implementation of gpio/HAL:
|
||
|
||
* Init gpio pin: `app_gpio_init`
|
||
* Fast write gpio (inline): `app_gpio_write`
|
||
* Fast read gpio (inline): `app_gpio_read`
|
||
* Microsecond delay `delay_us`
|
||
* Set PWM on timer's pin: `pwm_set`
|
||
|
||
Files location: `/app/app_hal.[ch]`
|
||
|
||
# Bootloader
|
||
|
||
For production targets('target_f2' and newer) bootloader must be flashed first.
|
||
Detailed instruction on how to compile and flash you can find in `bootloader` fodler.
|
||
|
||
Production version will have following features:
|
||
|
||
- Hardware initialization
|
||
- Firmware CRC check
|
||
- Firmware update
|
||
- Interactive UI
|
||
- Boot process LED indicators
|
||
- FS check
|
||
- Recovery mode
|
||
|
||
# OS
|
||
|
||
We use FreeRTOS 10.0.1 for sheduling. Documentation available on [freertos.org](https://www.freertos.org/a00106.html).
|
||
|
||
Files location for L476 version: `/target_f1/Middlewares/Third_Party/FreeRTOS`
|
||
|
||
**[Timers map](Timers)**
|
||
|
||
# Platform code
|
||
|
||
CMSIS, Freertos and HAL files are generated by CubeMX.
|
||
You can find platform code for L476 version in `target_f1` folder:
|
||
|
||
* `Drivers/STM32L4xx_HAL_Driver` – hardware abstraction layer
|
||
* `Drivers/CMSIS` — ARM specific code
|
||
* `Inc` `Src` — CubeMX generated headers & code
|
||
* `Middlewares/Third_Party/FreeRTOS/Source` — freeRTOS
|
||
* `deploy.sh` — flash firmware to device
|
||
* `STM32L476RGTx_FLASH.ld` — linker script
|
||
* `startup_stm32l476xx.s` — board startup/initialization assembler code
|
||
* `flipperzero_l476.ioc` — CubeMX project file
|
||
|
||
You can regenerate platform code:
|
||
1. Download CubeMX from [st.com](https://www.st.com/en/development-tools/stm32cubemx.html)
|
||
2. Open `*.ioc` file
|
||
3. Click `generate code`
|
||
4. After regenerating, look at git status, regenerating may broke some files.
|
||
|
||
## Arduino compatibility
|
||
|
||
There are some arduino-style defines (digitalWrite, delay, etc.). Include `Arduino.h` from `/app/Arduino.h`
|
||
|
||
# Flipper Universal Registry Implementation (FURI)
|
||
|
||
FURI is used to:
|
||
|
||
* application control (start, exit, switch between active)
|
||
* data exchange between application (create/open channel, subscribe and push messages or read/write values)
|
||
* non-volatile data storage for application (create/open value and read/write)
|
||
|
||
Read more at [FURI page](FURI)
|
||
|
||
# FS (not implemented)
|
||
|
||
File system is used to volaile storage some files (config, application data, etc.). There are some folders mounted to different volumes:
|
||
|
||
* `/usr` for store static data like assets, menu items. Build system add files to usr while building. It can be useful for exchange some static data between application. For example, your app can add link to itself to Plugins menu items file, user will see your app and can call it from this menu.
|
||
* Specially `/usr/etc-default` folder contains default configs for apps. Bootloader has `factory default` options to reset applications config. Also when new app is bootstapping, system copy files from default config folder to `/etc`.
|
||
* `/etc` for store configs of application. This volume not overwrite during flashing.
|
||
* `/var` for store some application data (saved keys, application database, logs). This volume also not overwrite during flashing.
|
||
* `/media/*` mounted if SD card is inserted.
|
||
|
||
# Flipper applications
|
||
|
||
Each flipper functionality except OS/HAL/FURI doing by Flipper application. Some application are called at startup, the rest are called by the user (for example, from menu).
|
||
|
||
(you can see some [examples](Application-examples))
|
||
|
||
For exchange data between application each app expose own record in FURI. You can subscribe on/read record to get data from application and write to record to send data to application.
|
||
|
||
**[List of FURI records](FURI-records-list)**
|
||
|
||
# Bootloader (not implemented)
|
||
|
||
After start, bootloader run first. It can:
|
||
|
||
1. Runs main firmware
|
||
2. Reflashes firmware from temporary area after updating from usb/bluetooth
|
||
3. Restores factory default firmware for protected flash area
|
||
4. Restores application settings to default by clearing `/etc` volume
|