Skip to content

Commit 2bdb5c0

Browse files
authored
Merge pull request #21689 from LeonardHerbst/crazyflie
boards: Bitcraze Crazyflie 2.1 main application board support
2 parents a8fafa1 + f2ac773 commit 2bdb5c0

File tree

11 files changed

+571
-0
lines changed

11 files changed

+571
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2025 TU Dresden
2+
# SPDX-License-Identifier: LGPL-2.1-only
3+
4+
config BOARD
5+
default "bitcraze-crazyflie21-main" if BOARD_BITCRAZE_CRAZYFLIE21_MAIN
6+
7+
config BOARD_BITCRAZE_CRAZYFLIE21_MAIN
8+
bool
9+
default y
10+
select CPU_MODEL_STM32F405RG
11+
12+
# Clock configuration
13+
select BOARD_HAS_HSE
14+
select BOARD_HAS_LSE
15+
16+
config CLOCK_HSE
17+
default 8000000
18+
19+
config CLOCK_PLL_M
20+
default 8
21+
22+
config CLOCK_PLL_N
23+
default 336 if USEMODULE_PERIPH_USBDEV_CLK
24+
default 360
25+
26+
source "$(RIOTBOARD)/common/stm32/Kconfig"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODULE = board
2+
3+
include $(RIOTBASE)/Makefile.base
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ifneq (,$(filter saul_default,$(USEMODULE)))
2+
USEMODULE += saul_gpio
3+
endif
4+
5+
include $(RIOTBOARD)/common/makefiles/stdio_cdc_acm.dep.mk
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CPU = stm32
2+
CPU_MODEL = stm32f405rg
3+
4+
CFLAGS += -DCONFIG_MOTOR_DRIVER_MAX=3
5+
6+
# Put defined MCU peripherals here (in alphabetical order)
7+
FEATURES_PROVIDED += periph_adc
8+
FEATURES_PROVIDED += periph_dma
9+
FEATURES_PROVIDED += periph_i2c
10+
FEATURES_PROVIDED += periph_pwm
11+
FEATURES_PROVIDED += periph_spi
12+
FEATURES_PROVIDED += periph_timer
13+
FEATURES_PROVIDED += periph_uart
14+
FEATURES_PROVIDED += periph_usbdev
15+
16+
FEATURES_PROVIDED += highlevel_stdio
17+
FEATURES_PROVIDED += motor_driver
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# include shared STM32 headers
2+
INCLUDES += -I$(RIOTBOARD)/common/stm32/include
3+
4+
PORT_LINUX ?= /dev/ttyACM0
5+
6+
ROM_OFFSET ?= 0x4000
7+
TERM_DELAY ?= 2
8+
9+
PROGRAMMER ?= dfu-util
10+
PROGRAMMERS_SUPPORTED += dfu-util
11+
DFU_USB_ID ?= 0483:df11
12+
DFU_USE_DFUSE ?= 1
13+
14+
include $(RIOTMAKE)/tools/usb_board_reset.mk
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
@defgroup boards_bitcraze_crazyflie21_main bitcraze Crazyflie 2.1 Main Application MCU
2+
@ingroup boards
3+
@brief Support for the main application MCU of the bitcraze Crazyflie 2.1 board.
4+
5+
### General information
6+
7+
The Crazyflie 2.1 is an open source flying development platform produced by bitcraze.
8+
It has two onboard microcontrollers, an nRF51822 used for radio communication and power management and
9+
an STM32F405 (this board definition) used for running the main application.
10+
11+
### Pinout
12+
13+
The pinout is part of the [Board Datasheet][board-datasheet].
14+
The [Board Schematics][board-schematics] show which pins are connected to the motors, LEDs, etc.
15+
16+
[board-datasheet]: https://www.bitcraze.io/documentation/hardware/crazyflie_2_1/crazyflie_2_1-datasheet.pdf
17+
[board-schematics]: https://www.bitcraze.io/documentation/hardware/crazyflie_2_1/crazyflie_2.1_schematics_rev.b.pdf
18+
19+
### MCU
20+
21+
| MCU | STM32F405RG |
22+
|:---------------------|:--------------------------------------------|
23+
| Family | ARM Cortex-M4 |
24+
| Vendor | ST Microelectronics |
25+
| Package | LQFP64 |
26+
| RAM | 192 KiB (128 KiB RAM + 64 KiB CCMRAM) |
27+
| Flash | 1024 KiB |
28+
| Frequency | up to 168 MHz (running at 168 MHz) |
29+
| FPU | yes |
30+
| Timers | 14 (12× 16bit, 2× 32bit [TIM2 + TIM5]) |
31+
| ADCs | 3× 16 channel 6 to 12-bit |
32+
| UARTs | 6 |
33+
| SPIs | 3 |
34+
| I2Cs | 3 |
35+
| Vcc | 2.0 V - 3.6 V |
36+
| MCU Datasheet | [MCU Datasheet][mcu-datasheet] |
37+
| MCU Reference Manual | [MCU Reference Manual][mcu-ref] |
38+
39+
[mcu-datasheet]: https://www.st.com/resource/en/datasheet/stm32f405rg.pdf
40+
[mcu-ref]: https://www.st.com/resource/en/reference_manual/dm00031020-stm32f405-415-stm32f407-417-stm32f427-437-and-stm32f429-439-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf
41+
42+
### Flash the board
43+
Prerequisites:
44+
- the Crazyflie NRF firmware runs on the NRF [instructions](https://www.bitcraze.io/documentation/repository/crazyflie2-nrf-firmware/master/build/build/)
45+
- the original Crazyflie bootloader runs on the STM32 [instructions](https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/development/dfu/#bootloader-recovery)
46+
- `dfu-util` is installed
47+
- the Crazyflie's battery is disconnected
48+
49+
To flash the board:
50+
- navigate to the folder of the app you want to flash
51+
- Hold down the power button on the Crazyflie
52+
- connect via usb to your computer
53+
- keep holding down the button for four seconds until the blink rate changes (the mcu is now in DFU mode)
54+
- flash the board by running `BOARD=bitcraze-crazyflie21-main make all flash`
55+
56+
### STDIO
57+
By default, STDIO is implemented via the native USB interface.
58+
In order to use STDIO over UART connect your UART adapter as follows:
59+
60+
| PIN board | UART adapter |
61+
|:----------|:-------------|
62+
| PC10 (TX) | RX |
63+
| PC11 (RX) | TX |
64+
| GND | GND |
65+
66+
Now flash the board with stdio over UART:
67+
```
68+
USEMODULE=stdio_uart BOARD=bitcraze-crazyflie21-main make all flash
69+
```
70+
71+
### Known Issues
72+
- `timer_set()`: the callback is never called for timeouts of only one tick.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 TU Dresden
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @ingroup boards_bitcraze_crazyflie21_main
10+
* @{
11+
*
12+
* @file
13+
* @brief Board specific definitions for the Crazyflie 2.1 main application MCU
14+
*
15+
* @author Leonard Herbst <[email protected]>
16+
*/
17+
18+
#include "cpu.h"
19+
#include "motor_driver.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/**
26+
* @name Macros for controlling the on-board LEDs.
27+
* @{
28+
*/
29+
#define LED0_IS_INVERTED 1
30+
#define LED0_PIN_NUM 3 /* LED top right red */
31+
#define LED0_PORT GPIO_PORT_C
32+
#define LED0_PORT_NUM PORT_C
33+
34+
#define LED1_IS_INVERTED 1
35+
#define LED1_PIN_NUM 2 /* LED top right green */
36+
#define LED1_PORT GPIO_PORT_C
37+
#define LED1_PORT_NUM PORT_C
38+
39+
#define LED2_PIN_NUM 2 /* LED bottom left blue */
40+
#define LED2_PORT GPIO_PORT_D
41+
#define LED2_PORT_NUM PORT_D
42+
43+
#define LED3_IS_INVERTED 1
44+
#define LED3_PIN_NUM 0 /* LED top left red*/
45+
#define LED3_PORT GPIO_PORT_C
46+
#define LED3_PORT_NUM PORT_C
47+
48+
#define LED4_IS_INVERTED 1
49+
#define LED4_PIN_NUM 1 /* LED top left green */
50+
#define LED4_PORT GPIO_PORT_C
51+
#define LED4_PORT_NUM PORT_C
52+
/** @} */
53+
54+
/**
55+
* @name Describe DC motors with PWM channel and GPIOs
56+
* @{
57+
*/
58+
/** Motor driver config. Two driver with three and one motor attached respectively */
59+
static const motor_driver_config_t motor_driver_config[] = {
60+
{
61+
.pwm_dev = 1,
62+
.mode = MOTOR_DRIVER_1_DIR,
63+
.mode_brake = MOTOR_BRAKE_HIGH,
64+
.pwm_mode = PWM_LEFT,
65+
.pwm_frequency = 20000U,
66+
.pwm_resolution = 4200U,
67+
.nb_motors = 3,
68+
.motors = {
69+
{
70+
.pwm_channel = 1,
71+
.gpio_enable = 0,
72+
.gpio_dir0 = 0,
73+
.gpio_dir1_or_brake = 0,
74+
.gpio_dir_reverse = 0,
75+
.gpio_enable_invert = 0,
76+
.gpio_brake_invert = 0,
77+
},
78+
{
79+
.pwm_channel = 3,
80+
.gpio_enable = 0,
81+
.gpio_dir0 = 0,
82+
.gpio_dir1_or_brake = 0,
83+
.gpio_dir_reverse = 0,
84+
.gpio_enable_invert = 0,
85+
.gpio_brake_invert = 0,
86+
},
87+
{
88+
.pwm_channel = 0,
89+
.gpio_enable = 0,
90+
.gpio_dir0 = 0,
91+
.gpio_dir1_or_brake = 0,
92+
.gpio_dir_reverse = 0,
93+
.gpio_enable_invert = 0,
94+
.gpio_brake_invert = 0,
95+
},
96+
},
97+
.cb = NULL,
98+
},
99+
{
100+
.pwm_dev = 2,
101+
.mode = MOTOR_DRIVER_1_DIR,
102+
.mode_brake = MOTOR_BRAKE_HIGH,
103+
.pwm_mode = PWM_LEFT,
104+
.pwm_frequency = 20000U,
105+
.pwm_resolution = 4200U,
106+
.nb_motors = 1,
107+
.motors = {
108+
{
109+
.pwm_channel = 0,
110+
.gpio_enable = 0,
111+
.gpio_dir0 = 0,
112+
.gpio_dir1_or_brake = 0,
113+
.gpio_dir_reverse = 0,
114+
.gpio_enable_invert = 0,
115+
.gpio_brake_invert = 0,
116+
},
117+
},
118+
.cb = NULL,
119+
}
120+
};
121+
122+
/** Number of motor drivers */
123+
#define MOTOR_DRIVER_NUMOF ARRAY_SIZE(motor_driver_config)
124+
/** @} */
125+
126+
#ifdef __cplusplus
127+
}
128+
#endif
129+
130+
#include "stm32_leds.h"
131+
/** @} */
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 TU Dresden
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @ingroup boards_bitcraze_crazyflie21_main
10+
* @{
11+
*
12+
* @file
13+
* @brief Board specific definitions for the Crazyflie 2.1 main application MCU
14+
*
15+
* @author Leonard Herbst <[email protected]>
16+
*/
17+
18+
#include "board.h"
19+
#include "saul/periph.h"
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
/**
26+
* @brief GPIO pin configuration
27+
*/
28+
static const saul_gpio_params_t saul_gpio_params[] =
29+
{
30+
{
31+
.name = "red LED top right",
32+
.pin = LED0_PIN,
33+
.mode = GPIO_OUT
34+
},
35+
{
36+
.name = "green LED top left",
37+
.pin = LED1_PIN,
38+
.mode = GPIO_OUT
39+
},
40+
{
41+
.name = "blue LED bottom left",
42+
.pin = LED2_PIN,
43+
.mode = GPIO_OUT
44+
},
45+
{
46+
.name = "red LED top left",
47+
.pin = LED3_PIN,
48+
.mode = GPIO_OUT
49+
},
50+
{
51+
.name = "green LED top left",
52+
.pin = LED4_PIN,
53+
.mode = GPIO_OUT
54+
},
55+
};
56+
/** @} */
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif

0 commit comments

Comments
 (0)