diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 48ae857..ac0a3d1 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,7 +1,7 @@ { "configurations": [ { - "name": "ARM", + "name": "teal-caniot-device", "compileCommands": "${workspaceRoot}/build/compile_commands.json", "intelliSenseMode": "gcc-arm", "browse": { @@ -10,6 +10,28 @@ ] }, "cStandard": "c23" + }, + { + "name": "teal-caniot-device (sysbuild)", + "compileCommands": "${workspaceRoot}/build/teal-caniot-device/compile_commands.json", + "intelliSenseMode": "gcc-arm", + "browse": { + "path": [ + "${workspaceFolder}" + ] + }, + "cStandard": "c23" + }, + { + "name": "mcuboot (sysbuild)", + "compileCommands": "${workspaceRoot}/build/mcuboot/compile_commands.json", + "intelliSenseMode": "gcc-arm", + "browse": { + "path": [ + "${workspaceFolder}" + ] + }, + "cStandard": "c23" } ], "version": 4 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4320ddb..87e13d8 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,8 @@ { "recommendations": [ "xaver.clang-format", - "nordic-semiconductor.nrf-connect-extension-pack" + "nordic-semiconductor.nrf-connect-extension-pack", + "ms-vscode.cpptools", + "twxs.cmake" ] } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 79f62c9..82ea3a0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,6 +25,18 @@ "runToEntryPoint": "main", "gdbPath": "/home/lucas/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb" }, + { + "name": "external teal (attach, sysbuild)", + "cwd": "${workspaceRoot}", + "executable": "./build/teal-caniot-device/zephyr/teal.elf", + "request": "attach", + "type": "cortex-debug", + "servertype": "external", + "gdbTarget": ":3333", + "device": "stm32l462re", + "runToEntryPoint": "main", + "gdbPath": "/home/lucas/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb" + }, { "name": "external nucleo_l452re (launch)", "cwd": "${workspaceRoot}", diff --git a/.vscode/settings.json b/.vscode/settings.json index b85d8f7..c23453a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,5 @@ "files.associations": { "kernel.h": "c", "inttypes.h": "c" - } + }, } \ No newline at end of file diff --git a/Kconfig b/Kconfig index ca0d6c6..222b64c 100644 --- a/Kconfig +++ b/Kconfig @@ -1,13 +1,15 @@ -menuconfig APPLICATION - bool "Application" - help - Enable application +menu "Application Configuration" -if APPLICATION +config APP_USB_DFU_FW_DOWNLOAD + bool "USB DFU firmware download" + default y + select USB_DFU_CLASS + help + Enable USB DFU firmware download. -endif +endmenu menuconfig TEST bool "Test firmware" diff --git a/Makefile b/Makefile index e80f646..0921fec 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,24 @@ -.PHONY: build flash debugserver debug menuconfig clean reports teal nucleo_l452 nucleo_f072 nucleo_h745 nucleo_f429 +.PHONY: build flash debugserver debug menuconfig clean reports teal sysbuild -all: build +all: build teal flash debug menuconfig reports clean -build: - west build +# nucleo_l452re nucleo_f429zi +BOARD=teal_caniot + +build: teal # board specific build teal: - west build -b teal_caniot - -nucleo_l452: - west build -b nucleo_l452re + west build -b $(BOARD) -nucleo_f072: - west build -b teal_f072 +test: + west build -b $(BOARD) -- -DFILE_SUFFIX=test -nucleo_h745: - west build -b nucleo_h745zi_q/stm32h745xx/m7 +sysbuild_test: + west build -b $(BOARD) --sysbuild -- -DFILE_SUFFIX=test -nucleo_f429: - west build -b nucleo_f429zi +sysbuild: + west build -b $(BOARD) --sysbuild # tools flash: @@ -35,8 +34,7 @@ menuconfig: west build -t menuconfig reports: - west build -t ram_report > build/ram_report.txt - west build -t rom_report > build/rom_report.txt + ./scripts/zephyr-report.sh clean: rm -rf build \ No newline at end of file diff --git a/app.overlay b/app.overlay index 4bb13d6..8c8d211 100644 --- a/app.overlay +++ b/app.overlay @@ -14,4 +14,4 @@ status = "okay"; compatible = "zephyr,cdc-acm-uart"; }; -}; \ No newline at end of file +}; diff --git a/boards/arm/teal_caniot/Kconfig b/boards/arm/teal_caniot/Kconfig new file mode 100644 index 0000000..e3d432c --- /dev/null +++ b/boards/arm/teal_caniot/Kconfig @@ -0,0 +1,47 @@ +# +# Copyright (c) 2024 Lucas Dietrich +# +# SPDX-License-Identifier: Apache-2.0 +# + +if BOARD_TEAL_CANIOT + +config BOARD_TEAL_CANIOT_FULL_FEATURED + bool "Enable extended configuration for Teal CANIoT" + default y + +endif + +if BOARD_TEAL_CANIOT_FULL_FEATURED + +config I2C + default y + +config SPI + default y + +config ADC + default y + +config CAN + default y + +config CRC + default y + +config W1 + default y + +config USB_CDC_ACM + default y + +config USB_DEVICE_STACK + default y + +config SENSOR + default y + +config TCN75A + default y + +endif \ No newline at end of file diff --git a/boards/arm/teal_caniot/Kconfig.sysbuild b/boards/arm/teal_caniot/Kconfig.sysbuild new file mode 100644 index 0000000..815895b --- /dev/null +++ b/boards/arm/teal_caniot/Kconfig.sysbuild @@ -0,0 +1,13 @@ +# +# Copyright (c) 2024 Lucas Dietrich +# +# SPDX-License-Identifier: Apache-2.0 +# + +choice BOOTLOADER + default BOOTLOADER_MCUBOOT +endchoice + +choice BOOT_SIGNATURE_TYPE + default BOOT_SIGNATURE_TYPE_NONE +endchoice diff --git a/boards/arm/teal_caniot/teal_caniot.dts b/boards/arm/teal_caniot/teal_caniot.dts index 368a2ff..3b025d1 100644 --- a/boards/arm/teal_caniot/teal_caniot.dts +++ b/boards/arm/teal_caniot/teal_caniot.dts @@ -9,7 +9,6 @@ #include #include - / { model = "Teal CANIoT device board"; compatible = "custom,teal_caniot"; @@ -20,6 +19,7 @@ zephyr,flash = &flash0; zephyr,console = &lpuart1; zephyr,shell-uart = &lpuart1; + zephyr,code-partition = &slot0_partition; }; gpio_keys { @@ -55,6 +55,39 @@ }; }; +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 DT_SIZE_K(48)>; + read-only; + }; + slot0_partition: partition@C000 { + label = "image-0"; + reg = <0x0000C000 DT_SIZE_K(216)>; + }; + slot1_partition: partition@42000 { + label = "image-1"; + reg = <0x00042000 DT_SIZE_K(216)>; + }; + + /* + * The flash starting at 78000 and ending at + * 0x0007ffff is reserved for use by the application. + */ + + /* Storage partition will be used by FCB/NFFS/NVS if enabled. */ + storage_partition: partition@78000 { + label = "storage"; + reg = <0x00078000 DT_SIZE_K(32)>; + }; + }; +}; + /* clocks */ &clk_lsi { status = "okay"; diff --git a/boards/arm/teal_caniot/teal_caniot_defconfig b/boards/arm/teal_caniot/teal_caniot_defconfig index daff836..4f29194 100644 --- a/boards/arm/teal_caniot/teal_caniot_defconfig +++ b/boards/arm/teal_caniot/teal_caniot_defconfig @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 # +# Standard configuration for an application CONFIG_ARM_MPU=y CONFIG_HW_STACK_PROTECTION=y @@ -18,23 +19,7 @@ CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_UART_LINE_CTRL=y -CONFIG_I2C=y -CONFIG_SPI=y CONFIG_GPIO=y -CONFIG_ADC=y -CONFIG_CAN=y -CONFIG_CRC=y -CONFIG_W1=y - -# usb -CONFIG_USB_CDC_ACM=y -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_MANUFACTURER="Lucas" -CONFIG_USB_DEVICE_PRODUCT="Teal CANIoT" - -# st microelectronics -CONFIG_USB_DEVICE_VID=0x0483 -CONFIG_USB_DEVICE_PID=0xFFFF # tcn75 CONFIG_SENSOR=y diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..ced4d92 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,19 @@ +# Documentation + +## TODOs + +- Understand why creating file `sysbuild/mcuboot.overlay` breaks the build: + +```dts +&can1 { + status = "disabled"; +}; + +&i2c1 { + status = "disabled"; +}; + +&usb { + status = "disabled"; +}; +``` \ No newline at end of file diff --git a/prj.conf b/prj.conf index 382018e..dad3084 100644 --- a/prj.conf +++ b/prj.conf @@ -12,15 +12,37 @@ CONFIG_KERNEL_BIN_NAME="teal" CONFIG_DEBUG=y +# MCUBOOT features +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_STREAM_FLASH=y +CONFIG_IMG_MANAGER=y +CONFIG_MCUBOOT_IMG_MANAGER=y +CONFIG_IMG_BLOCK_BUF_SIZE=512 +CONFIG_IMG_ENABLE_IMAGE_CHECK=y +CONFIG_IMG_ERASE_PROGRESSIVELY=y + +# usb (TODO move to dedicated board config) +CONFIG_USB_CDC_ACM=y +CONFIG_USB_DEVICE_STACK=y CONFIG_USB_COMPOSITE_DEVICE=y +CONFIG_USB_DFU_CLASS=y # We need to disable the logs in the USB CDC ACM driver otherwise # the logs will be printed on the (USB) console causing a chain reaction # (eventually recursion leading to a stack overflow) -CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y +# CONFIG_USB_CDC_ACM_LOG_LEVEL_ERR=n + +# usb info +CONFIG_USB_DEVICE_MANUFACTURER="Lucas" +CONFIG_USB_DEVICE_PRODUCT="Teal CANIoT" + +# st microelectronics +CONFIG_USB_DEVICE_VID=0x0483 +CONFIG_USB_DEVICE_PID=0xFFFF CONFIG_CANIOT_LIB=y CONFIG_CANIOT_DEVICE_DRIVERS_API=y -CONFIG_TEST=y -CONFIG_STM32L4_MCO=y +# Application specific configurations +CONFIG_APP_USB_DFU_FW_DOWNLOAD=y \ No newline at end of file diff --git a/prj_test.conf b/prj_test.conf index 99f9b98..ed9f620 100644 --- a/prj_test.conf +++ b/prj_test.conf @@ -4,5 +4,56 @@ # SPDX-License-Identifier: Apache-2.0 # +# Debug +# CONFIG_OUTPUT_DISASSEMBLY=y +# CONFIG_OUTPUT_SYMBOLS=y +# CONFIG_OUTPUT_STAT=y + +CONFIG_KERNEL_BIN_NAME="teal" +CONFIG_DEBUG=y + +# MCUBOOT features +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_STREAM_FLASH=y +CONFIG_IMG_MANAGER=y +CONFIG_MCUBOOT_IMG_MANAGER=y +CONFIG_IMG_BLOCK_BUF_SIZE=512 +CONFIG_IMG_ENABLE_IMAGE_CHECK=y +CONFIG_IMG_ERASE_PROGRESSIVELY=y + +# peripherals (TODO move to dedicated board config) +CONFIG_I2C=y +CONFIG_SPI=y +CONFIG_ADC=y +CONFIG_CAN=y +CONFIG_CRC=y +CONFIG_W1=y + +# tcn75 (TODO move to dedicated board config) +CONFIG_SENSOR=y +CONFIG_TCN75A=y + +# usb (TODO move to dedicated board config) +CONFIG_USB_CDC_ACM=y +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_COMPOSITE_DEVICE=y + +# usb info +CONFIG_USB_DEVICE_MANUFACTURER="Lucas" +CONFIG_USB_DEVICE_PRODUCT="Teal CANIoT" + +# st microelectronics +CONFIG_USB_DEVICE_VID=0x0483 +CONFIG_USB_DEVICE_PID=0xFFFF + +# We need to disable the logs in the USB CDC ACM driver otherwise +# the logs will be printed on the (USB) console causing a chain reaction +# (eventually recursion leading to a stack overflow) +CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y + +CONFIG_CANIOT_LIB=y +CONFIG_CANIOT_DEVICE_DRIVERS_API=y + CONFIG_TEST=y CONFIG_STM32L4_MCO=y \ No newline at end of file diff --git a/readme.md b/readme.md index 443106e..7368853 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Teal caniot device -`teal` is a custom board for an home automation system. +`teal` is a custom board for an home automation device. It is based on the `stm32l462re` microcontroller. The current design replaces [caniot-device](https://github.com/lucasdietrich/caniot-device?tab=readme-ov-file#boards) boards (i.e. V1 and Tiny boards) based on an 8-bit AVR microcontroller. diff --git a/scripts/zephyr-reports.sh b/scripts/zephyr-reports.sh new file mode 100755 index 0000000..0761d98 --- /dev/null +++ b/scripts/zephyr-reports.sh @@ -0,0 +1,20 @@ +#!/usr/bin/bash + +# +function zephyr_report() { + if [ ! -d "$1" ]; then + echo "Usage: zephyr_report " + return 1 + fi + + # get relative path + local dir_path=$(realpath $1) + + west build -d $dir_path -t ram_report > $dir_path/ram_report.txt + west build -d $dir_path -t rom_report > $dir_path/rom_report.txt +} + +# run the function +zephyr_report "build/teal-caniot-device" +zephyr_report "build/mcuboot" +zephyr_report "build" \ No newline at end of file diff --git a/src/main.c b/src/main.c index 2d9af2b..487b876 100644 --- a/src/main.c +++ b/src/main.c @@ -4,11 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ +#if defined(CONFIG_TEST) #include +#endif int main(void) { - int ret; + int ret = 0; #if defined(CONFIG_TEST) ret = test_main(); @@ -17,5 +19,5 @@ int main(void) for (;;) { } - return 0; + return ret; } \ No newline at end of file diff --git a/sysbuild.conf b/sysbuild.conf new file mode 100644 index 0000000..30f57a4 --- /dev/null +++ b/sysbuild.conf @@ -0,0 +1,5 @@ +# Sysbuild configuration file. + +# Enable MCUboot per default for this sample. +SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_BOOT_SIGNATURE_TYPE_NONE=y \ No newline at end of file diff --git a/sysbuild/CMakeLists.txt b/sysbuild/CMakeLists.txt new file mode 100644 index 0000000..4cf31c5 --- /dev/null +++ b/sysbuild/CMakeLists.txt @@ -0,0 +1,11 @@ +# This file is required if you don't build with +# `west build -b $(BOARD) --sysbuild -- -DBOARD_ROOT=.` + +# Get the parent directory +get_filename_component(CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE) +get_filename_component(PARENT_DIR ${CURRENT_DIR} DIRECTORY) + +# set board root +set(BOARD_ROOT ${PARENT_DIR}) +find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sysbuild LANGUAGES) diff --git a/sysbuild/mcuboot.conf b/sysbuild/mcuboot.conf new file mode 100644 index 0000000..cfb9efd --- /dev/null +++ b/sysbuild/mcuboot.conf @@ -0,0 +1,18 @@ +# Example of sample specific Kconfig changes when building sample with MCUboot +# when using sysbuild. + +# No firmware signature +CONFIG_BOOT_SIGNATURE_TYPE_NONE=y +CONFIG_BOOT_SIGNATURE_TYPE_RSA=n +CONFIG_BOOT_ENCRYPT_IMAGE=n + +CONFIG_MCUBOOT_LOG_LEVEL_WRN=y + +CONFIG_BOOT_UPGRADE_ONLY=n +# CONFIG_MCUBOOT_DOWNGRADE_PREVENTION=y + +# Prefer swap move, don't use scratch partition +CONFIG_BOOT_PREFER_SWAP_MOVE=y + +# disable unecessary TEAL board features +CONFIG_BOARD_TEAL_CANIOT_FULL_FEATURED=n \ No newline at end of file diff --git a/west.yml b/west.yml index c231c91..ebcacdc 100644 --- a/west.yml +++ b/west.yml @@ -5,5 +5,5 @@ manifest: projects: - name: zephyr remote: zephyrproject-rtos - revision: v3.7.0 + revision: v4.0.0 import: true \ No newline at end of file