Skip to content

Commit

Permalink
Merge pull request #1039 from bitcraze/krichardsson/oot-improvements
Browse files Browse the repository at this point in the history
Improvements for OOT builds
  • Loading branch information
krichardsson authored May 9, 2022
2 parents 52a9bf9 + 531a221 commit c34e97c
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ jobs:
example:
- examples/app_hello_world
- examples/app_hello_world-cpp
- examples/app_hello_file_tree
- examples/app_peer_to_peer
- examples/demos/app_push_demo
- examples/demos/swarm_demo
Expand Down
11 changes: 9 additions & 2 deletions docs/development/oot.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ title: Out of tree build
page_id: oot
---

It is possible to have an out-of-tree build of parts of the crazyflie firmware. This enables developers to work on elements without worrrying about merging it with the full code base.
It is possible to have an out-of-tree build of parts of the crazyflie firmware. This enables developers to work on elements without worrying about merging it with the full code base.

# General out-of-tree build process
In a seperate folder make a Makefile which contain the following content:
In a separate folder create a Makefile which contain the following content:

```Makefile
CRAZYFLIE_BASE := [LOCATION OF THE CRAZYFLIE FIRMWARE]
Expand Down Expand Up @@ -44,7 +44,14 @@ It can also add point out another folder where the code resides:
obj-y += src/
```

If you have header files in another folder, use `EXTRA_CFLAGS` in the Makefile to let the compiler know where to find them:

```Makefile
EXTRA_CFLAGS += -I$(PWD)/src/inc
```

And since you are providing a config file by way of `$(OOT_CONFIG)` you do not need to run any make command to create a config like `make menuconfig` or `make defconfig`. Just a simple `make` will suffice.

# OOT estimators
The `config` file needs to enable ESTIMATOR_OOT, and can also set other config options:

Expand Down
2 changes: 2 additions & 0 deletions examples/app_hello_file_tree/.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_hello_file_tree/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += src/
29 changes: 29 additions & 0 deletions examples/app_hello_file_tree/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 := ../..

#
# To include header files from other directories
#
EXTRA_CFLAGS += -I$(PWD)/src/hello_sub
EXTRA_CFLAGS += -I$(PWD)/src/world_sub

#
# 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
18 changes: 18 additions & 0 deletions examples/app_hello_file_tree/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Hello file tree App for Crazyflie 2.X

This folder contains an app layer application for the Crazyflie to show how to work with a file tree in Out Of Tree builds.
It prints the classic hello world debug message, which can be read in the console tab of the [cfclient](https://github.com/bitcraze/crazyflie-clients-python).

See App layer API guide [here](https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/userguides/app_layer/)

## Build

Make sure that you are in the app_hello_file_tree folder (not the main folder of the crazyflie firmware). Then type the following to build and flash it while the crazyflie is put into bootloader mode:

```
make clean
make
make cload
```

If you want to compile the application elsewhere in your machine, make sure to update ```CRAZYFLIE_BASE``` in the **Makefile**.
3 changes: 3 additions & 0 deletions examples/app_hello_file_tree/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
3 changes: 3 additions & 0 deletions examples/app_hello_file_tree/src/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj-y += hello_file_tree.o
obj-y += hello_sub/
obj-y += world_sub/
53 changes: 53 additions & 0 deletions examples/app_hello_file_tree/src/hello_file_tree.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2022 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/>.
*
*
* hello_file_tree.c - App layer application of a simple hello world app with the functionality implemented in
* files that are located in multiple directories.
*/


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

#include "app.h"

#include "FreeRTOS.h"
#include "task.h"

#include "hello_sub.h"
#include "world_sub.h"

#define DEBUG_MODULE "THEAPP"
#include "debug.h"

void appMain() {
DEBUG_PRINT("Waiting for activation ...\n");

while(1) {
vTaskDelay(M2T(2000));
print_hello();
print_world();
}
}
1 change: 1 addition & 0 deletions examples/app_hello_file_tree/src/hello_sub/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += hello_sub.o
32 changes: 32 additions & 0 deletions examples/app_hello_file_tree/src/hello_sub/hello_sub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2022 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/>.
*/

#include "hello_sub.h"

#define DEBUG_MODULE "HELLO_SUB"
#include "debug.h"

void print_hello() {
DEBUG_PRINT("Hello\n");
}
27 changes: 27 additions & 0 deletions examples/app_hello_file_tree/src/hello_sub/hello_sub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2022 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/>.
*/

#pragma once

void print_hello();
1 change: 1 addition & 0 deletions examples/app_hello_file_tree/src/world_sub/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += world_sub.o
32 changes: 32 additions & 0 deletions examples/app_hello_file_tree/src/world_sub/world_sub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2022 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/>.
*/

#include "world_sub.h"

#define DEBUG_MODULE "WORLD_SUB"
#include "debug.h"

void print_world() {
DEBUG_PRINT("World!\n");
}
27 changes: 27 additions & 0 deletions examples/app_hello_file_tree/src/world_sub/world_sub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
* | / ,--´ | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
* +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
*
* Crazyflie control firmware
*
* Copyright (C) 2022 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/>.
*/

#pragma once

void print_world();
5 changes: 0 additions & 5 deletions examples/app_hello_world/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
#
CRAZYFLIE_BASE := ../..

#
# To include header files from another dir
#
EXTRA_CFLAGS += -I$(PWD)/other

#
# We override the default OOT_CONFIG here, we could also name our config
# to oot-config and that would be the default.
Expand Down
3 changes: 0 additions & 3 deletions examples/app_hello_world/other/headerInOtherDir.h

This file was deleted.

7 changes: 2 additions & 5 deletions examples/app_hello_world/src/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@
#include "FreeRTOS.h"
#include "task.h"

#include "headerInOtherDir.h"

#define DEBUG_MODULE "HELLOWORLD"
#include "debug.h"

#define DEBUG_MODULE "HELLOWORLD"

void appMain()
{
void appMain() {
DEBUG_PRINT("Waiting for activation ...\n");

while(1) {
Expand Down
2 changes: 1 addition & 1 deletion tools/make/oot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OOT ?= $(PWD)
#
OOT_CONFIG ?= $(OOT)/oot-config

OOT_ARGS ?= -C $(CRAZYFLIE_BASE) OOT=$(OOT) EXTRA_CFLAGS=$(EXTRA_CFLAGS)
OOT_ARGS ?= -C $(CRAZYFLIE_BASE) OOT=$(OOT) EXTRA_CFLAGS="$(EXTRA_CFLAGS)"

ifneq ($(OOT_USES_CXX),)
OOT_ARGS += OOT_USES_CXX=1
Expand Down

0 comments on commit c34e97c

Please sign in to comment.