From e2a61094a71e5d74177e7908c2abf66b474b5a86 Mon Sep 17 00:00:00 2001 From: Kristoffer Richardsson Date: Thu, 24 Aug 2023 10:14:55 +0200 Subject: [PATCH 1/2] Added example for using CPX --- .github/workflows/CI.yml | 1 + examples/app_stm_gap8_cpx/.gitignore | 2 + examples/app_stm_gap8_cpx/Kbuild | 1 + examples/app_stm_gap8_cpx/Makefile | 23 +++++++ examples/app_stm_gap8_cpx/README.md | 17 +++++ examples/app_stm_gap8_cpx/app-config | 3 + examples/app_stm_gap8_cpx/src/Kbuild | 1 + examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c | 72 ++++++++++++++++++++ 8 files changed, 120 insertions(+) create mode 100644 examples/app_stm_gap8_cpx/.gitignore create mode 100644 examples/app_stm_gap8_cpx/Kbuild create mode 100644 examples/app_stm_gap8_cpx/Makefile create mode 100644 examples/app_stm_gap8_cpx/README.md create mode 100644 examples/app_stm_gap8_cpx/app-config create mode 100644 examples/app_stm_gap8_cpx/src/Kbuild create mode 100644 examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 84cd35daeb..bd00667e44 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -100,6 +100,7 @@ jobs: - examples/demos/app_push_demo - examples/demos/swarm_demo - examples/demos/app_wall_following_demo + - examples/demos/app_stm_gap8_cpx env: EXAMPLE: ${{ matrix.example }} diff --git a/examples/app_stm_gap8_cpx/.gitignore b/examples/app_stm_gap8_cpx/.gitignore new file mode 100644 index 0000000000..a743f37a76 --- /dev/null +++ b/examples/app_stm_gap8_cpx/.gitignore @@ -0,0 +1,2 @@ +bin/* +cf2.* diff --git a/examples/app_stm_gap8_cpx/Kbuild b/examples/app_stm_gap8_cpx/Kbuild new file mode 100644 index 0000000000..9d804337a0 --- /dev/null +++ b/examples/app_stm_gap8_cpx/Kbuild @@ -0,0 +1 @@ +obj-y += src/ diff --git a/examples/app_stm_gap8_cpx/Makefile b/examples/app_stm_gap8_cpx/Makefile new file mode 100644 index 0000000000..d0a76e2ac3 --- /dev/null +++ b/examples/app_stm_gap8_cpx/Makefile @@ -0,0 +1,23 @@ +# The firmware uses the Kbuild build system. There are 'Kbuild' files in this +# example that outlays what needs to be built. (check src/Kbuild). +# +# The firmware is configured using options in Kconfig files, the +# values of these end up in the .config file in the firmware directory. +# +# By setting the OOT_CONFIG (it is '$(PWD)/oot-config' by default) environment +# variable you can provide a custom configuration. It is important that you +# enable the app-layer. See app-config in this directory for example. + +# +# We want to execute the main Makefile for the firmware project, +# it will handle the build for us. +# +CRAZYFLIE_BASE := ../.. + +# +# We override the default OOT_CONFIG here, we could also name our config +# to oot-config and that would be the default. +# +OOT_CONFIG := $(PWD)/app-config + +include $(CRAZYFLIE_BASE)/tools/make/oot.mk diff --git a/examples/app_stm_gap8_cpx/README.md b/examples/app_stm_gap8_cpx/README.md new file mode 100644 index 0000000000..e7f2ef840f --- /dev/null +++ b/examples/app_stm_gap8_cpx/README.md @@ -0,0 +1,17 @@ +# STM-GAP8 CPX communication example + +This folder contains the app layer application for an example app that communicates with the GAP8 on the AI-deck. +The intention is to show how CPX can be used to feed data from the STM to the GAP8 or the other way around. +One possible use case for this type of communication could be to control the Crzyflie from a neural network for instance. + +This application is intended to be used with an AI-deck, together with the "stm_gap8_cpx" example in the +[aideck-gap8-examples](https://github.com/bitcraze/aideck-gap8-examples) repository. + +CPX packets are sent from the STM (this app) to the GAP8, containing a counter that is increased for each packet. The +same number is sent back to the STM in a new CPX packet and the number is printed on the console, that is when a +number is printed on the console, the counter value has done a round trip STM-GAP8-STM. + + +See the [CPX documentation](https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/functional-areas/cpx/). + +See App layer API guide and build instructions [here](https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/userguides/app_layer/) diff --git a/examples/app_stm_gap8_cpx/app-config b/examples/app_stm_gap8_cpx/app-config new file mode 100644 index 0000000000..c86fe9169e --- /dev/null +++ b/examples/app_stm_gap8_cpx/app-config @@ -0,0 +1,3 @@ +CONFIG_APP_ENABLE=y +CONFIG_APP_PRIORITY=1 +CONFIG_APP_STACKSIZE=350 diff --git a/examples/app_stm_gap8_cpx/src/Kbuild b/examples/app_stm_gap8_cpx/src/Kbuild new file mode 100644 index 0000000000..a50a7e0b59 --- /dev/null +++ b/examples/app_stm_gap8_cpx/src/Kbuild @@ -0,0 +1 @@ +obj-y += stm_gap8_cpx.o diff --git a/examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c b/examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c new file mode 100644 index 0000000000..d3fb633068 --- /dev/null +++ b/examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c @@ -0,0 +1,72 @@ +/** + * ,---------, ____ _ __ + * | ,-^-, | / __ )(_) /_______________ _____ ___ + * | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \ + * | / ,--ยด | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ + * +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/ + * + * Crazyflie control firmware + * + * Copyright (C) 2023 Bitcraze AB + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, in version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + * App layer application that communicates with the GAP8 on an AI deck. + */ + + +#include +#include +#include + +#include "app.h" + +#include "cpx.h" +#include "cpx_internal_router.h" + +#include "FreeRTOS.h" +#include "task.h" + +#define DEBUG_MODULE "APP" +#include "debug.h" + +// Callback that is called when a CPX packet arrives +static void cpxPacketCallback(const CPXPacket_t* cpxRx); + +static CPXPacket_t txPacket; + +void appMain() { + DEBUG_PRINT("Hello! I am the stm_gap8_cpx app\n"); + + // Register a callback for CPX packets. + // Packets sent to destination=CPX_T_STM32 and function=CPX_F_APP will arrive here + cpxRegisterAppMessageHandler(cpxPacketCallback); + + uint8_t counter = 0; + while(1) { + vTaskDelay(M2T(2000)); + + cpxInitRoute(CPX_T_STM32, CPX_T_GAP8, CPX_F_APP, &txPacket.route); + txPacket.data[0] = counter; + txPacket.dataLength = 1; + + cpxSendPacketBlocking(&txPacket); + DEBUG_PRINT("Sent packet to GAP8 (%u)\n", counter); + counter++; + } +} + +static void cpxPacketCallback(const CPXPacket_t* cpxRx) { + DEBUG_PRINT("Got packet from GAP8 (%u)\n", cpxRx->data[0]); +} From 153203bfe72cba7b33a1f84489e6eb07cc26e80a Mon Sep 17 00:00:00 2001 From: Kristoffer Richardsson Date: Thu, 24 Aug 2023 13:31:06 +0200 Subject: [PATCH 2/2] Correct build script --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index bd00667e44..7f86f778ce 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -97,10 +97,10 @@ jobs: - examples/app_hello_file_tree - examples/app_peer_to_peer - examples/app_p2p_DTR + - examples/app_stm_gap8_cpx - examples/demos/app_push_demo - examples/demos/swarm_demo - examples/demos/app_wall_following_demo - - examples/demos/app_stm_gap8_cpx env: EXAMPLE: ${{ matrix.example }}