Skip to content

Commit

Permalink
Merge pull request #1311 from bitcraze/krichardsson/stm-gap8-cpx
Browse files Browse the repository at this point in the history
Example app for CPX communication with the GAP8
  • Loading branch information
krichardsson committed Aug 24, 2023
2 parents 343e19b + 153203b commit 711efe4
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions examples/app_stm_gap8_cpx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/*
cf2.*
1 change: 1 addition & 0 deletions examples/app_stm_gap8_cpx/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += src/
23 changes: 23 additions & 0 deletions examples/app_stm_gap8_cpx/Makefile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions examples/app_stm_gap8_cpx/README.md
Original file line number Diff line number Diff line change
@@ -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/)
3 changes: 3 additions & 0 deletions examples/app_stm_gap8_cpx/app-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_APP_ENABLE=y
CONFIG_APP_PRIORITY=1
CONFIG_APP_STACKSIZE=350
1 change: 1 addition & 0 deletions examples/app_stm_gap8_cpx/src/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += stm_gap8_cpx.o
72 changes: 72 additions & 0 deletions examples/app_stm_gap8_cpx/src/stm_gap8_cpx.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*
* App layer application that communicates with the GAP8 on an AI deck.
*/


#include <string.h>
#include <stdint.h>
#include <stdbool.h>

#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]);
}

0 comments on commit 711efe4

Please sign in to comment.