From eb037a2f023b7503aa52c349e430ef5d74f36dae Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Mon, 1 Jul 2024 18:55:48 +0300 Subject: [PATCH 1/4] update dronecan submodule from v0.3.30 to v0.3.31, cyphal submodule from v0.8.10 to v0.8.12 --- Libs/Cyphal | 2 +- Libs/Dronecan | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libs/Cyphal b/Libs/Cyphal index 6c0d834..3f65047 160000 --- a/Libs/Cyphal +++ b/Libs/Cyphal @@ -1 +1 @@ -Subproject commit 6c0d8347ae9c894c7bf919d8d24c9aa9c7385792 +Subproject commit 3f6504775b647dd61d5252ffa635e4203f60013a diff --git a/Libs/Dronecan b/Libs/Dronecan index 7c7a93f..ab278ab 160000 --- a/Libs/Dronecan +++ b/Libs/Dronecan @@ -1 +1 @@ -Subproject commit 7c7a93f96fa1838a64da5992560f8ff740784317 +Subproject commit ab278ab80f978a49b494d5a251f694c016800cb3 From 6ab8d0987c91ade1e9066f71d1b4ffd24cd4b4d0 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Mon, 1 Jul 2024 19:07:55 +0300 Subject: [PATCH 2/4] update readme --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d294503..c37703e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Mini v2 Cyphal/DroneCAN application template -This repo introduces a simple ready-to-use Cyphal/DroneCAN application template for [RL Mini v2](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_mini_v2.html) node. +This repo introduces a simple ready-to-use Cyphal/DroneCAN application template for [RL Mini v2](https://docs.raccoonlab.co/guide/can_pwm/can_pwm_mini_v2.html) and [RL Mini v3](https://docs.raccoonlab.co/guide/can_pwm/mini_v3.html) nodes. Please, refer Wiki for details: - [Cyphal template application](https://github.com/RaccoonlabDev/mini_v2_node/wiki/Cyphal-application), @@ -10,31 +10,57 @@ Please, refer Wiki for details: ### 1. Key features -- Minimal recommended Cyphal features are supported out of the box (bootloader and DNA are coming next), +- Minimal recommended Cyphal features are supported out of the box, - You can run the software in SITL mode (don't need to have any hardware), - Cyphal firmware binary is only 35.2 KB. -### 2. Brief hardware info +Not suported yet / In Roadmap: +- Both Cyphal/CAN and DroneCAN protocols in a single firmware +- Bootloader +- Dynamics Node Allocation (DNA) +- MPU-9250 IMU (node v3) +- Redundant CAN interface (node v3) +- CAN terminator resistors control (node v3) -| Top view | Bottom view | Pinout | STM32CubeMX | -| --- | ------ |-|-| -| drawing | drawing | drawing | drawing | +### 2. Supported boards -### 3. Brief Cyphal capabilities +The software supports RL v2 nodes (stm32f103, 128 KBytes flash) and v3 nodes (stm32g0b1, 512 KBytes flash). -By default the application is as simple as possible. It just blinks the RGB LED, subscribes to the setpoint topic to control a single PWM (PWM1) and publishes a feedback with the latest applied setpoint. It doesn't have any safety features like TTL, but you are free to extend it as you want. +| Name | View | Pinout | STM32CubeMX | +| ---- | ---- | ------ | ----------- | +| Mini v2 | drawing | drawing | drawing | +| Mini v3 | drawing | drawing | drawing | -The default capabilities of the node are shown on the picture below: +### 3. Brief Cyphal/DroneCAN capabilities -drawing +You can build the software either for Cyphal/CAN or DroneCAN. By default both applications are as simple as possible. They: +- subscribe on setpoint topics and control PWM1-4 channels, +- measure 5v and Vin voltage, temperature, current (if supported) and publish as circuit status and actuator feedback, +- blink the RGB LED to indicate the current state. -### 4. Brief DroneCAN capabilities +In the table below you can see interfaces of the applications. -The application subscribes on a message configured in `pwm.cmd_type`. It supports: [esc.RawCommand](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#rawcommand), [actuator.ArrayCommand](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#arraycommand), [hardpoint.Command](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#command-1). It controls the PWM and sends back [esc.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status-2), [actuator.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status), [hardpoint.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status-3) as feedback. It also sends [power.CircuitStatus](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#circuitstatus) with the circuit state (5v voltage, vin voltage, current) and [device.Temperature](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#temperature) with stm32 internal measured temperature. +| Cyphal/CAN | DroneCAN | +| ---------- | -------- | +| Subscribe on:
- setpoint ([reg.udral.service.actuator.common.sp.Vector31](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/reg/udral/service/actuator/common/sp/Vector31.0.1.dsdl))


Publish:
- feedback ([reg.udral.service.actuator.common.Feedback](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/reg/udral/service/actuator/common/Feedback.0.1.dsdl))
- crct.5v ([uavcan.si.unit.voltage.Scalar](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/uavcan/si/unit/voltage/Scalar.1.0.dsdl))
- crct.vin ([uavcan.si.unit.voltage.Scalar](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/uavcan/si/unit/voltage/Scalar.1.0.dsdl))
- crct.temp ([uavcan.si.unit.temperature.Scalar](https://github.com/OpenCyphal/public_regulated_data_types/blob/master/uavcan/si/unit/temperature/Scalar.1.0.dsdl))
. | Subscribe on:
- [uavcan.equipment.esc.RawCommand](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#rawcommand)
- [uavcan.equipment.actuator.ArrayComman](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#arraycommand)
- [uavcan.equipment.hardpoint.Command](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#command-1)
Publish:
- [uavcan.equipment.esc.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status-2)
- [uavcan.equipment.actuator.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status)
- [uavcan.equipment.hardpoint.Status](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#status-3)
- [uavcan.equipment.power.CircuitStatus](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#circuitstatus)
- [uavcan.equipment.device.Temperature](https://dronecan.github.io/Specification/7._List_of_standard_data_types/#temperature) | +| drawing | drawing drawing | -||| -|-|-| -| drawing | drawing | +### 4. Use cases + +1. Control 1-4 motors without feedback or servos with current feedback (if hardware supports) + + drawing + +2. Control 1-2 motors with UART/ADC feedback + + drawing + +3. Cyphal/DroneCAN adapter for I2C/UART sensor + + drawing + +4. Control a servo with current feedback (if hardware supports) and angular position feedback (from [AS5600 I2C sensor](https://docs.raccoonlab.co/guide/as5600/)) +5. Control a PWM cargo gripper ### 5. Q&A From bbca689973df2945a571584501a6aa25fd7b583d Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Mon, 1 Jul 2024 19:15:41 +0300 Subject: [PATCH 3/4] update dronecan build workflow --- .github/workflows/dronecan.yml | 10 +++++++--- Makefile | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dronecan.yml b/.github/workflows/dronecan.yml index 4a0630c..9ae8d86 100644 --- a/.github/workflows/dronecan.yml +++ b/.github/workflows/dronecan.yml @@ -10,7 +10,11 @@ jobs: stm32f103: strategy: matrix: - os: [ubuntu-22.04, windows-latest] + include: + - os: ubuntu-22.04 + platform: v2 + - os: windows-latest + platform: v2 runs-on: ${{ matrix.os }} timeout-minutes: 10 steps: @@ -30,10 +34,10 @@ jobs: shell: bash - name: Build DroneCAN binary - run: make dronecan + run: make dronecan_${{ matrix.platform }} - name: Upload .bin file - if: matrix.os == 'ubuntu-22.04' + if: matrix.os == 'ubuntu-22.04' && matrix.platform == 'v2' uses: actions/upload-artifact@v3 with: name: dronecan_firmware.bin diff --git a/Makefile b/Makefile index 9572875..837cd92 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ generate_dsdl: else \ echo "[INFO] Cyphal DSDL: already generated. Skip."; \ fi -cyphal: checks generate_dsdl clean +cyphal: cyphal_v2 +cyphal_v2: checks generate_dsdl clean mkdir -p ${BUILD_OBJ_DIR} cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_NODE_V2=ON -G "Unix Makefiles" ../.. && make sitl_cyphal: checks generate_dsdl clean @@ -24,7 +25,8 @@ sitl_cyphal: checks generate_dsdl clean cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_UBUNTU=ON -G "Unix Makefiles" ../.. && make # Dronecan: -dronecan: checks clean +dronecan: dronecan_v2 +dronecan_v2: checks clean mkdir -p ${BUILD_OBJ_DIR} cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan -DUSE_PLATFORM_NODE_V2=ON -G "Unix Makefiles" ../.. && make sitl_dronecan: checks clean From e5e75228939178e0b39892fcb615cd33e188a1f0 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Mon, 1 Jul 2024 19:19:03 +0300 Subject: [PATCH 4/4] add v3 build --- .github/workflows/dronecan.yml | 2 ++ CMakeLists.txt | 2 +- Makefile | 8 +++++ Src/platform/stm32g0b1/CMakeLists.txt | 52 +++++++++++++++++++++++++++ cmake/stm32g0b1.cmake | 7 ++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Src/platform/stm32g0b1/CMakeLists.txt diff --git a/.github/workflows/dronecan.yml b/.github/workflows/dronecan.yml index 9ae8d86..70ff78a 100644 --- a/.github/workflows/dronecan.yml +++ b/.github/workflows/dronecan.yml @@ -13,6 +13,8 @@ jobs: include: - os: ubuntu-22.04 platform: v2 + - os: ubuntu-22.04 + platform: v3 - os: windows-latest platform: v2 runs-on: ${{ matrix.os }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 560ac12..034ef7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ elseif(USE_PLATFORM_NODE_V2) elseif(USE_PLATFORM_NODE_V3) set(LIBPARAMS_PLATFORM stm32g0b1) set(CAN_PLATFORM fdcan) - set(APP_PLATFORM stm32f103) + set(APP_PLATFORM stm32g0b1) include(${CMAKE_DIR}/stm32g0b1.cmake) else() message(SEND_ERROR "Platform Error: Either v2 (stm32f103), v3 (stm32g0) or SITL (Linux) should be specified.") diff --git a/Makefile b/Makefile index 837cd92..c592365 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,9 @@ cyphal_v2: checks generate_dsdl clean sitl_cyphal: checks generate_dsdl clean mkdir -p ${BUILD_OBJ_DIR} cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_UBUNTU=ON -G "Unix Makefiles" ../.. && make +cyphal_v3: checks generate_dsdl clean + mkdir -p ${BUILD_OBJ_DIR} + cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_NODE_V3=ON -G "Unix Makefiles" ../.. && make # Dronecan: dronecan: dronecan_v2 @@ -32,6 +35,11 @@ dronecan_v2: checks clean sitl_dronecan: checks clean mkdir -p ${BUILD_OBJ_DIR} cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan -DUSE_PLATFORM_UBUNTU=ON -G "Unix Makefiles" ../.. && make +dronecan_v3: checks clean + # --branch dc90159 + if [ ! -d "build/ioc-v3" ]; then git clone --depth 1 https://github.com/RaccoonLabHardware/v3-software-template.git build/ioc-v3; fi + mkdir -p ${BUILD_OBJ_DIR} + cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan -DUSE_PLATFORM_NODE_V3=ON -G "Unix Makefiles" ../.. && make # Common: checks: diff --git a/Src/platform/stm32g0b1/CMakeLists.txt b/Src/platform/stm32g0b1/CMakeLists.txt new file mode 100644 index 0000000..f8ef397 --- /dev/null +++ b/Src/platform/stm32g0b1/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (C) 2023-2024 Dmitry Ponomarev +# Distributed under the terms of the GPL v3 license, available in the file LICENSE. + +# Pathes +cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH PLATFORM_DIR) +cmake_path(GET PLATFORM_DIR PARENT_PATH SRC_DIR) +cmake_path(GET SRC_DIR PARENT_PATH ROOT_DIR) + +set(EXECUTABLE ${PROJECT_NAME}.out) +add_executable(${EXECUTABLE} + ${APPLICATION_SOURCES} + ${BUILD_SRC_DIR}/params.cpp + ${ROOT_DIR}/Src/common/algorithms.cpp + ${ROOT_DIR}/Src/common/module.cpp + + ${PLATFORM_DIR}/stm32f103/adc.cpp + ${PLATFORM_DIR}/ubuntu/pwm.cpp + ${PLATFORM_DIR}/stm32f103/iwdg.cpp + ${PLATFORM_DIR}/stm32f103/led.cpp + ${PLATFORM_DIR}/stm32f103/temperature_sensor.cpp + ${PLATFORM_DIR}/stm32f103/platform_specific.cpp + + ${coreSources} + ${driversSources} + ${startupFile} +) + +target_include_directories(${EXECUTABLE} PRIVATE + ${BUILD_SRC_DIR} + ${APPLICATION_HEADERS} + ${ROOT_DIR}/Src/common + + ${stm32cubeMxProjectPath}/Core/Inc + ${stm32cubeMxProjectPath}/Drivers/CMSIS/Include + + ${stm32cubeMxProjectPath}/Drivers/CMSIS/Device/ST/STM32F1xx/Include + ${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc + ${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy + + ${stm32cubeMxProjectPath}/Drivers/CMSIS/Device/ST/STM32G0xx/Include + ${stm32cubeMxProjectPath}/Drivers/STM32G0xx_HAL_Driver/Inc + ${stm32cubeMxProjectPath}/Drivers/STM32G0xx_HAL_Driver/Inc/Legacy +) + +# Post-build +add_custom_command(TARGET ${EXECUTABLE} + POST_BUILD + COMMAND ${CMAKE_SIZE} ${EXECUTABLE} + COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${BUILD_OBJ_DIR}/${PROJECT_NAME}.hex + COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${BUILD_OBJ_DIR}/${PROJECT_NAME}.bin + COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-little ${EXECUTABLE} ${BUILD_OBJ_DIR}/${PROJECT_NAME}.elf +) diff --git a/cmake/stm32g0b1.cmake b/cmake/stm32g0b1.cmake index b8d6696..ae56131 100644 --- a/cmake/stm32g0b1.cmake +++ b/cmake/stm32g0b1.cmake @@ -3,4 +3,11 @@ set(TARGET_ARCHITECTURE cortex-m0plus) set(CPU STM32G0B1xx) +set(stm32cubeMxProjectPath ${ROOT_DIR}/build/ioc-v3) +FILE(GLOB ldFile ${stm32cubeMxProjectPath}/*_FLASH.ld) +FILE(GLOB coreSources ${stm32cubeMxProjectPath}/Core/Src/*) +FILE(GLOB driversSources ${stm32cubeMxProjectPath}/Drivers/*/*/*.c) +FILE(GLOB startupFile ${stm32cubeMxProjectPath}/*.s + ${stm32cubeMxProjectPath}/Core/Startup/*.s +) include(${CMAKE_CURRENT_LIST_DIR}/Toolchain-arm-none-eabi.cmake)