A lot of stuff
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# Build
|
||||
|
||||
## Install zephyr SDK
|
||||
> See [INSTALL.md](INSTALL.md) for installing the SDK.
|
||||
|
||||
## Build the app without MCUboot
|
||||
|
||||
```bash
|
||||
source ../env.sh
|
||||
west build -p -b nrf52840_qalmari
|
||||
```
|
||||
|
||||
## Build everything
|
||||
|
||||
```bash
|
||||
source ../env.sh
|
||||
west build -p -b nrf52840_qalmari --sysbuild
|
||||
```
|
||||
|
||||
## Generate your own key for MCUboot
|
||||
```bash
|
||||
openssl genrsa -out key.pem 2048
|
||||
```
|
||||
|
||||
## Flash the binary to the device
|
||||
> See [FLASH.md](FLASH.md) for installing the app to the device.
|
||||
+7
-1
@@ -5,7 +5,13 @@ cmake_minimum_required(VERSION 3.20.0)
|
||||
set(BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(meditation)
|
||||
project(chill)
|
||||
|
||||
# Zephyr has way too many deprecated warnings
|
||||
target_compile_options(app PRIVATE
|
||||
-Wno-deprecated-declarations
|
||||
-Wno-unused-parameter
|
||||
)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Flashing the device
|
||||
To flash `merged_<device>.hex`, you need a debugger and probably know how to do it.
|
||||
|
||||
DAPlink with openocd or pyocd works.
|
||||
|
||||
# Flashing `bin/zephyr.signed.hex`
|
||||
You need `NRFconnect` and install `Programmer` inside NRFconnect app.
|
||||
## 1. Choose the MCUboot device.
|
||||

|
||||
|
||||
## 2. Open the signed hex file
|
||||

|
||||
|
||||
## 3. Write the file to device
|
||||

|
||||
|
||||
## 4. Success!
|
||||

|
||||
+82
@@ -0,0 +1,82 @@
|
||||
# Installation Guide
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Install required tools:
|
||||
|
||||
```bash
|
||||
python -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install west pyserial pyocd
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
zephyr/
|
||||
├── venv/ # Python virtual environment
|
||||
├── sdk/zephyr/ # Zephyr source code
|
||||
├── zephyr-sdk-1.0.1/ # Zephyr SDK installation
|
||||
├── chill/ # This project
|
||||
└── env.sh # Environment setup script
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
### 1. Clone Zephyr SDK
|
||||
|
||||
```bash
|
||||
# in zephyr/
|
||||
mkdir sdk
|
||||
cd sdk
|
||||
git clone https://github.com/zephyrproject-rtos/zephyr.git
|
||||
```
|
||||
|
||||
### 2. Install Zephyr SDK
|
||||
|
||||
```bash
|
||||
# in zephyr/
|
||||
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v1.0.1/zephyr-sdk-1.0.1_linux-x86_64_gnu.tar.xz
|
||||
tar xf zephyr-sdk-1.0.1_linux-x86_64_gnu.tar.xz
|
||||
```
|
||||
|
||||
### 3. Initialize West
|
||||
|
||||
```bash
|
||||
# in zephyr/sdk/zephyr
|
||||
west init -l .
|
||||
west update
|
||||
```
|
||||
|
||||
### 4. Export a Zephyr CMake package.
|
||||
|
||||
```bash
|
||||
# in zephyr/sdk/zephyr
|
||||
west zephyr-export
|
||||
```
|
||||
|
||||
### 5. Install Python dependencies using west packages.
|
||||
|
||||
```bash
|
||||
# in zephyr/sdk/zephyr
|
||||
west packages pip --install
|
||||
```
|
||||
|
||||
### 6. Create env.sh
|
||||
|
||||
Create `zephyr/env.sh` with the following content:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
|
||||
export ZEPHYR_BASE="${SCRIPT_DIR}/sdk/zephyr"
|
||||
echo "export ZEPHYR_BASE=\"${SCRIPT_DIR}/sdk/zephyr\""
|
||||
|
||||
export ZEPHYR_SDK_INSTALL_DIR="${SCRIPT_DIR}/zephyr-sdk-1.0.1"
|
||||
echo "export ZEPHYR_SDK_INSTALL_DIR=\"${SCRIPT_DIR}/zephyr-sdk-1.0.1\""
|
||||
|
||||
source "${SCRIPT_DIR}/venv/bin/activate"
|
||||
echo "source \"${SCRIPT_DIR}/venv/bin/activate\""
|
||||
```
|
||||
@@ -1,16 +1,48 @@
|
||||
## client
|
||||
## Serial client
|
||||
Prefer socat to support arrow keys
|
||||
```
|
||||
nc 192.168.1.154 7777
|
||||
socat -d -d -,raw,echo=0 TCP:192.168.1.154:7777
|
||||
```
|
||||
|
||||
## server
|
||||
## Serial server
|
||||
```
|
||||
socat -d -d /dev/ttyACM0,b115200,raw,echo=0 tcp-listen:7777,reuseaddr
|
||||
```
|
||||
|
||||
## openocd
|
||||
## openocd server
|
||||
```
|
||||
openocd -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "bindto 0.0.0.0"
|
||||
```
|
||||
|
||||
## VScode launch.json
|
||||
```json
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Zephyr Remote Cortex-Debug (OpenOCD)",
|
||||
"type": "cortex-debug",
|
||||
"request": "launch",
|
||||
|
||||
"executable": "${workspaceFolder}/build/zephyr/zephyr.elf",
|
||||
|
||||
"servertype": "external",
|
||||
"gdbTarget": "192.168.1.154:3333",
|
||||
|
||||
"gdbPath": "/usr/bin/arm-none-eabi-gdb",
|
||||
|
||||
"runToEntryPoint": "main",
|
||||
|
||||
"preLaunchCommands": [
|
||||
"monitor reset halt"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## generate key
|
||||
```
|
||||
openssl genrsa -out key.pem 2048
|
||||
```
|
||||
@@ -24,4 +24,9 @@ Example 15min and 20s:
|
||||
mode set 900000 20000
|
||||
```
|
||||
|
||||
> See [DEBUG.md](DEBUG.md) for development/test commands.
|
||||
## Links
|
||||
> See [DEBUG.md](DEBUG.md) for development/test commands.
|
||||
|
||||
> See [BUILD.md](BUILD.md) for building the project.
|
||||
|
||||
> See [FLASH.md](FLASH.md) for installing the app to the device.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -12,21 +12,19 @@
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
/* The size of this partition ensures that MCUBoot can be built
|
||||
* with an RTT console, CDC ACM support, and w/o optimizations.
|
||||
*/
|
||||
|
||||
boot_partition: partition@0 {
|
||||
label = "mcuboot";
|
||||
reg = <0x00000000 0x00087000>;
|
||||
reg = <0x00000000 0x00014000>;
|
||||
};
|
||||
|
||||
// slot0_partition: partition@12000 {
|
||||
// label = "image-0";
|
||||
// reg = <0x00012000 0x00075000>;
|
||||
// };
|
||||
slot1_partition: partition@87000 {
|
||||
slot0_partition: partition@14000 {
|
||||
label = "image-0";
|
||||
reg = <0x00014000 0x00074000>;
|
||||
};
|
||||
slot1_partition: partition@88000 {
|
||||
label = "image-1";
|
||||
reg = <0x00087000 0x00075000>;
|
||||
reg = <0x00088000 0x00074000>;
|
||||
};
|
||||
storage_partition: partition@fc000 {
|
||||
label = "storage";
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
zephyr,bt-c2h-uart = &cdc_acm_uart;
|
||||
zephyr,sram = &sram0;
|
||||
zephyr,flash = &flash0;
|
||||
zephyr,code-partition = &boot_partition;
|
||||
zephyr,code-partition = &slot0_partition;
|
||||
zephyr,ieee802154 = &ieee802154;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDP8Kl7UkdOutrq
|
||||
q/AsCz6muBXAegTTOQ1iEjeefkYOEonNXQV4moMUz8x5ovgQVivR7CQNLGAbrw79
|
||||
8o53VHMp2qqYTz3ju7O8UQu284VGAhbqDxfQCDt4RNg8m5reybDmUfnk3zjREJBi
|
||||
PJBaScyVgBF4ql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dzv+z518N2sJW9um5TB/UT3jOj90Nq275l7Q8
|
||||
K+ZCMxZFMtvkoHULTL+Jstd2TOA+LX2jDPxJVq6e/yqt59SGjqTnaJsBAoGAYSAv
|
||||
UO+Bc8fYtbP4iZBecIxzQfAq+KrdYWnP5HXnP3BIOf5br+7RgeUQTC6EWy+5xOyz
|
||||
7gBWTgxno2ukI9OUOWZzGBv4gxIzRaH7RgPe+JHjD56RGIUI2K1/T9sqWLFICYlR
|
||||
hARQjfvHgIKXjmypSPPszPAv1yOcpJRgLcw9UzECgYAu6hI48gLEZsqr69x7oBKl
|
||||
SLYsbmx+mzMGZDdd2dVDBF8yRltPYiQ5vHxYdtpTOB7Rw7CGY5xbmu4cVJPZI+I3
|
||||
5vS4ab9F9/H71KQzhDgANjI57Gn4GB48SCCZnzRi6HBTCKR7SDxnzUx20FrXmSpt
|
||||
oEb0sketlpr2mnCZOwSnmA==
|
||||
-----END PRIVATE KEY-----
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 112 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 105 KiB |
@@ -10,12 +10,15 @@ CONFIG_SPI=y
|
||||
# Serial
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_USB_DEVICE_STACK=y
|
||||
# CONFIG_USB_DEVICE_STACK_NEXT=y
|
||||
CONFIG_USB_CDC_ACM=y
|
||||
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=n
|
||||
CONFIG_USBD_LOOPBACK_CLASS=y
|
||||
CONFIG_UDC_BUF_POOL_SIZE=4096
|
||||
CONFIG_UART_CONSOLE=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_UART_LINE_CTRL=y
|
||||
|
||||
# USB
|
||||
CONFIG_USB_DEVICE_STACK_NEXT=y
|
||||
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=y
|
||||
CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="SulaJalmari"
|
||||
CONFIG_CDC_ACM_SERIAL_PID=0x0004
|
||||
|
||||
# Shell
|
||||
CONFIG_SHELL=y
|
||||
@@ -33,14 +36,17 @@ CONFIG_I2C_TARGET=y
|
||||
|
||||
# LOG
|
||||
CONFIG_LOG=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
||||
CONFIG_USBD_CDC_ACM_LOG_LEVEL_OFF=y # This removes a pointless warning
|
||||
CONFIG_LOG_DEFAULT_LEVEL=1
|
||||
CONFIG_LOG_MODE_IMMEDIATE=y
|
||||
CONFIG_USBD_LOG_LEVEL_WRN=y
|
||||
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
|
||||
|
||||
#ZBUS
|
||||
CONFIG_ZBUS=y
|
||||
CONFIG_ZBUS_LOG_LEVEL_INF=n
|
||||
CONFIG_ZBUS_CHANNEL_NAME=y
|
||||
CONFIG_ZBUS_OBSERVER_NAME=y
|
||||
CONFIG_ZBUS_MSG_SUBSCRIBER=y
|
||||
CONFIG_ZBUS_MSG_SUBSCRIBER=y
|
||||
|
||||
# MCUBoot
|
||||
CONFIG_BOOTLOADER_MCUBOOT=y
|
||||
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="key.pem"
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/fs/nvs.h>
|
||||
#include <zephyr/kvss/nvs.h>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
|
||||
#define NVS_ID_CONFIG 1
|
||||
@@ -34,14 +34,14 @@ static const app_config_t default_config = {
|
||||
int config_init(void)
|
||||
{
|
||||
struct flash_pages_info page;
|
||||
const struct device *dev = FIXED_PARTITION_DEVICE(storage_partition);
|
||||
const struct device *dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(storage_partition)));
|
||||
|
||||
flash_get_page_info_by_offs(dev, FIXED_PARTITION_OFFSET(storage_partition), &page);
|
||||
flash_get_page_info_by_offs(dev, DT_REG_ADDR(DT_NODELABEL(storage_partition)), &page);
|
||||
|
||||
nvs.flash_device = dev;
|
||||
nvs.offset = FIXED_PARTITION_OFFSET(storage_partition);
|
||||
nvs.offset = DT_REG_ADDR(DT_NODELABEL(storage_partition));
|
||||
nvs.sector_size = page.size;
|
||||
nvs.sector_count = FIXED_PARTITION_SIZE(storage_partition) / page.size;
|
||||
nvs.sector_count = DT_REG_SIZE(DT_NODELABEL(storage_partition)) / page.size;
|
||||
|
||||
int rc = nvs_mount(&nvs);
|
||||
if (rc) {
|
||||
@@ -69,4 +69,4 @@ int config_save(const app_config_t *cfg)
|
||||
void config_get(app_config_t *cfg)
|
||||
{
|
||||
*cfg = ram_config;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ const int color_table_size = ARRAY_SIZE(color_table);
|
||||
int led_color_from_str(const char *name, struct color_t *out)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(color_table); i++) {
|
||||
if (strcasecmp(color_table[i].name, name) == 0) {
|
||||
if (strncmp(color_table[i].name, name, strlen(color_table[i].name) + 1) == 0) {
|
||||
*out = color_table[i].color;
|
||||
return 0;
|
||||
}
|
||||
@@ -153,14 +153,6 @@ static float get_brightness(void)
|
||||
return b;
|
||||
}
|
||||
|
||||
static float get_brightness_pwm(void)
|
||||
{
|
||||
for (int j = 0; j < NR_LEDS; j++) {
|
||||
set_pwm(leds[j], 0, PWM_RESOLUTION);
|
||||
}
|
||||
return get_brightness();
|
||||
}
|
||||
|
||||
/**
|
||||
* Like set_pwm() but scales `value` by the current ambient brightness before
|
||||
* writing. All PWM-facing call sites go through here.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "led.h"
|
||||
@@ -14,12 +13,6 @@ int main(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = usb_enable(NULL);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to enable USB: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = config_init();
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to init config: %d", ret);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
SB_CONFIG_BOOTLOADER_MCUBOOT=y
|
||||
SB_CONFIG_MERGED_HEX_FILES=y
|
||||
SB_CONFIG_MCUBOOT_MODE_SINGLE_APP=y
|
||||
SB_CONFIG_BOOT_SIGNATURE_KEY_FILE="${APP_DIR}/key.pem"
|
||||
@@ -0,0 +1,6 @@
|
||||
# Set local board files
|
||||
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
|
||||
|
||||
find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(sysbuild LANGUAGES)
|
||||
@@ -0,0 +1,19 @@
|
||||
CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
|
||||
CONFIG_MCUBOOT_INDICATION_LED=y
|
||||
CONFIG_MCUBOOT_SERIAL=y
|
||||
CONFIG_BOOT_SERIAL_CDC_ACM=y
|
||||
|
||||
# New USB stack is too big
|
||||
# CONFIG_USB_DEVICE_STACK_NEXT=y
|
||||
# CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=y
|
||||
# CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="SulaJalmari MCUBoot"
|
||||
# CONFIG_CDC_ACM_SERIAL_PID=0x0004
|
||||
|
||||
# Old USB stack
|
||||
CONFIG_USB_DEVICE_STACK=y
|
||||
CONFIG_USB_DEVICE_PRODUCT="SulaJalmari MCUBoot"
|
||||
CONFIG_USB_CDC_ACM=y
|
||||
|
||||
# Needed to recognize as MCUboot in nrf connect
|
||||
CONFIG_USB_DEVICE_VID=0x1915
|
||||
CONFIG_USB_DEVICE_PID=0x5300
|
||||
Reference in New Issue
Block a user