Skip to content

Commit

Permalink
Merge pull request #2419 from paparazzi/tawaki_board-integration
Browse files Browse the repository at this point in the history
Tawaki board integration
  • Loading branch information
gautierhattenberger committed Jun 19, 2019
2 parents 4d7045d + 5ed41ce commit 17b185d
Show file tree
Hide file tree
Showing 30 changed files with 3,871 additions and 44 deletions.
99 changes: 99 additions & 0 deletions conf/boards/tawaki_1.0.makefile
@@ -0,0 +1,99 @@
# Hey Emacs, this is a -*- makefile -*-
#
# tawaki_1.0.makefile
#
# based on STM32F7
# only compatible with ChibiOS
#

BOARD=tawaki
BOARD_VERSION=1.0
BOARD_DIR=$(BOARD)/chibios/v$(BOARD_VERSION)
BOARD_CFG=\"boards/$(BOARD_DIR)/$(BOARD).h\"

ARCH=chibios
$(TARGET).ARCHDIR = $(ARCH)

RTOS=chibios
MCU=cortex-m7

## FPU on F7
USE_FPU=softfp
USE_FPU_OPT= -mfpu=fpv5-d16

USE_LTO=yes

$(TARGET).CFLAGS += -DSTM32F7 -DPPRZLINK_ENABLE_FD -DUSE_HARD_FAULT_RECOVERY

##############################################################################
# Architecture or project specific options
#
# Define project name here (target)
PROJECT = $(TARGET)

# Project specific files and paths (see Makefile.chibios for details)
CHIBIOS_BOARD_PLATFORM = STM32F7xx/platform.mk
CHIBIOS_BOARD_PORT = ARMCMx/STM32F7xx/port.mk
CHIBIOS_BOARD_LINKER = STM32F76xxI.ld
CHIBIOS_BOARD_STARTUP = startup_stm32f7xx.mk

# ITCM flash is a special flash that allow faster operations
# At the moment it is not possible to flash the code in this mode using dfu-util
# but it should work with the BlackMagicProbe or STLINK
# By default, normal flash is used
ifeq ($(USE_ITCM),1)
$(TARGET).CFLAGS += -DUSE_ITCM=1
DFU_ADDR = 0x00200000
else
$(TARGET).CFLAGS += -DUSE_ITCM=0
DFU_ADDR = 0x08000000
endif

##############################################################################
# Compiler settings
#

# default flash mode is via usb dfu bootloader
# possibilities: DFU-UTIL, SWD, STLINK
FLASH_MODE ?= DFU-UTIL

HAS_LUFTBOOT = FALSE

#
# default LED configuration
#
RADIO_CONTROL_LED ?= 4
BARO_LED ?= none
AHRS_ALIGNER_LED ?= 2
GPS_LED ?= 3
SYS_TIME_LED ?= 1

#
# default UART configuration (modem, gps, spektrum)
#

MODEM_PORT ?= UART2
MODEM_BAUD ?= B57600

GPS_PORT ?= UART7
GPS_BAUD ?= B57600

RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT ?= UART6
RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT ?= UART8

# single mode
SBUS_PORT ?= UART8
# dual mode
SBUS1_PORT ?= UART8
SBUS2_PORT ?= UART6

#
# default actuator configuration
#
# you can use different actuators by adding a configure option to your firmware section
# e.g. <configure name="ACTUATORS" value="actuators_ppm/>
# and by setting the correct "driver" attribute in servo section
# e.g. <servo driver="Ppm">
#
ACTUATORS ?= actuators_pwm

1 change: 1 addition & 0 deletions conf/firmwares/test_chibios.makefile
Expand Up @@ -64,6 +64,7 @@ COMMON_TEST_CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
COMMON_TEST_SRCS += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c

COMMON_TEST_CFLAGS += -DUSE_LED
COMMON_TEST_SRCS += $(SRC_ARCH)/mcu_periph/gpio_arch.c

# pprz downlink/datalink
COMMON_TELEMETRY_CFLAGS = -DDOWNLINK -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=PPRZ
Expand Down
3 changes: 3 additions & 0 deletions conf/flash_modes.xml
Expand Up @@ -60,6 +60,7 @@
<board name="elle*"/>
<board name="openpilot_revo.*"/>
<board name="chimera_.*"/>
<board name="tawaki_.*"/>
</boards>
</mode>
<mode name="STLink (SWD)">
Expand All @@ -73,6 +74,7 @@
<board name="naze32*"/>
<board name="openpilot_revo.*"/>
<board name="chimera_.*"/>
<board name="tawaki_.*"/>
</boards>
</mode>
<mode name="BlackMagic Probe (SWD)">
Expand All @@ -91,6 +93,7 @@
<board name="openpilot_revo.*"/>
<board name="lia_.*"/>
<board name="chimera_.*"/>
<board name="tawaki_.*"/>
<board name="vms_ecu_.*"/>
</boards>
</mode>
Expand Down
34 changes: 34 additions & 0 deletions conf/modules/board_tawaki.xml
@@ -0,0 +1,34 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="board_tawaki" dir="boards">
<doc>
<description>
Autoload several onboard sensors for the Tawaki board with proper configuration
- IMU (icm206xx) (auto-detected from MPU6000 driver)
- Baro (BMP3)
- Mag (LIS3MDL)
Normal front of the board is on USB connector side
Normal up of the board is on the Molex connector side
</description>
<configure name="BOARD_TAWAKI_ROTATED" value="FALSE|TRUE" description="if TRUE, the board is not using is default orientation and axis can be redefined by hand"/>
</doc>
<autoload name="imu" type="mpu6000"/>
<autoload name="baro" type="bmp3"/>
<autoload name="mag" type="lis3mdl"/>
<makefile target="!sim|nps|fbw">
<define name="IMU_MPU_GYRO_RANGE" value="MPU60X0_GYRO_RANGE_1000"/>
<define name="IMU_MPU_ACCEL_RANGE" value="MPU60X0_ACCEL_RANGE_8G"/>
<configure name="IMU_MPU_SPI_DEV" value="spi4" case="upper|lower"/>
<configure name="IMU_MPU_SPI_SLAVE_IDX" value="SPI_SLAVE5"/>
<define name="IMU_MPU_CHAN_X" value="1" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<define name="IMU_MPU_CHAN_Y" value="0" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<define name="IMU_MPU_Y_SIGN" value="-1" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<configure name="BMP3_I2C_DEV" value="i2c4" case="upper|lower"/>
<define name="BMP3_SLAVE_ADDR" value="BMP3_I2C_ADDR_ALT"/>
<configure name="MAG_LIS3MDL_I2C_DEV" value="i2c4" case="upper|lower"/>
<define name="LIS3MDL_CHAN_X" value="1" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<define name="LIS3MDL_CHAN_Y" value="0" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<define name="LIS3MDL_CHAN_X_SIGN" value="-" cond="ifneq (,$(findstring $(BOARD_TAWAKI_ROTATED),0 FALSE))"/>
<configure name="SDLOG_USE_RTC" value="FALSE"/> <!-- disable RTC for now -->
</makefile>
</module>
3 changes: 2 additions & 1 deletion conf/modules/logger_sd_chibios.xml
Expand Up @@ -30,8 +30,9 @@
<file name="sdlog_chibios/usb_msd.c"/>
<file name="sdlog_chibios/usbStorage.c"/>
<file_arch name="sdio_arch.c" dir="mcu_periph"/>
<configure name="SDLOG_USE_RTC" default="TRUE"/>
<configure name="USE_FATFS" value="TRUE"/>
<define name="HAL_USE_RTC" value="TRUE"/>
<define name="HAL_USE_RTC" value="TRUE" cond="ifneq (,$(findstring $(SDLOG_USE_RTC),0 FALSE))"/>
<define name="HAL_USE_SDC" value="TRUE"/>
<define name="HAL_USE_USB" value="TRUE"/>
</makefile>
Expand Down
2 changes: 1 addition & 1 deletion sw/airborne/arch/chibios/halconf.h
Expand Up @@ -105,7 +105,7 @@
* @brief Enables the I2C subsystem.
*/
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
#if USE_I2C1 || USE_I2C2 || USE_I2C3
#if USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4
#define HAL_USE_I2C TRUE
#else
#define HAL_USE_I2C FALSE
Expand Down
21 changes: 11 additions & 10 deletions sw/airborne/arch/chibios/led_hw.h
Expand Up @@ -34,23 +34,24 @@
* hal.h is needed for palXXX functions
*/
#include <hal.h>
#include "mcu_periph/gpio_def.h"
#include "mcu_periph/gpio.h"
#include BOARD_CONFIG

/*
* Regular GPIO driven LEDs
*/
#define _LED_GPIO(i) i
#define _LED_GPIO_PIN(i) i
#define _LED_EVAL(i) i

#define LED_GPIO(i) _LED_GPIO(LED_ ## i ## _GPIO)
#define LED_GPIO_PIN(i) _LED_GPIO_PIN(LED_ ## i ## _GPIO_PIN)
#define LED_GPIO(i) _LED_EVAL(LED_ ## i ## _GPIO)
#define LED_GPIO_PIN(i) _LED_EVAL(LED_ ## i ## _GPIO_PIN)
#define LED_GPIO_ON(i) _LED_EVAL(LED_ ## i ## _GPIO_ON)
#define LED_GPIO_OFF(i) _LED_EVAL(LED_ ## i ## _GPIO_OFF)

#define LED_INIT(i) palSetPadMode(LED_GPIO(i), LED_GPIO_PIN(i), PAL_MODE_OUTPUT_PUSHPULL)
#define LED_ON(i) palClearPad(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_OFF(i) palSetPad(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_TOGGLE(i) palTogglePad(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_DISABLE(i) palSetPadMode(LED_GPIO(i), LED_GPIO_PIN(i), PAL_MODE_INPUT)
#define LED_INIT(i) gpio_setup_output(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_ON(i) LED_GPIO_ON(i)(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_OFF(i) LED_GPIO_OFF(i)(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_TOGGLE(i) gpio_toggle(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_DISABLE(i) gpio_setup_input(LED_GPIO(i), LED_GPIO_PIN(i))
#define LED_PERIODIC() {}

#endif /* LED_HW_H */
63 changes: 59 additions & 4 deletions sw/airborne/arch/chibios/mcu_periph/i2c_arch.c
Expand Up @@ -46,7 +46,7 @@
#define I2C_THREAD_STACK_SIZE 512
#endif

#if USE_I2C1 || USE_I2C2 || USE_I2C3
#if USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4

// private I2C init structure
struct i2c_init {
Expand Down Expand Up @@ -177,7 +177,7 @@ static void handle_i2c_thd(struct i2c_periph *p)
break;
}
}
#endif /* USE_I2C1 || USE_I2C2 || USE_I2C3 */
#endif /* USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4 */

#if USE_I2C1
// I2C1 config
Expand Down Expand Up @@ -342,6 +342,61 @@ static void thd_i2c3(void *arg)
}
#endif /* USE_I2C3 */

#if USE_I2C4
// I2C4 config
PRINT_CONFIG_VAR(I2C4_CLOCK_SPEED)
static SEMAPHORE_DECL(i2c4_sem, 0);
static I2CConfig i2cfg4 = I2C4_CFG_DEF;
#if defined STM32F7
// We need a special buffer for DMA operations
static IN_DMA_SECTION(uint8_t i2c4_dma_buf[I2C_BUF_LEN]);
static struct i2c_init i2c4_init_s = {
.sem = &i2c4_sem,
.cfg = &i2cfg4,
.dma_buf = i2c4_dma_buf
};
#else
static struct i2c_init i2c4_init_s = {
.sem = &i2c4_sem,
.cfg = &i2cfg4
};
#endif
// Errors
struct i2c_errors i2c4_errors;
// Thread
static __attribute__((noreturn)) void thd_i2c4(void *arg);
static THD_WORKING_AREA(wa_thd_i2c4, 128);

/*
* I2C4 init
*/
void i2c4_hw_init(void)
{
i2cStart(&I2CD4, &i2cfg4);
i2c4.reg_addr = &I2CD4;
i2c4.init_struct = NULL;
i2c4.errors = &i2c4_errors;
i2c4.init_struct = &i2c4_init_s;
// Create thread
chThdCreateStatic(wa_thd_i2c4, sizeof(wa_thd_i2c4),
NORMALPRIO + 1, thd_i2c4, NULL);
}

/*
* I2C4 thread
*
*/
static void thd_i2c4(void *arg)
{
(void) arg;
chRegSetThreadName("i2c4");

while (TRUE) {
handle_i2c_thd(&i2c4);
}
}
#endif /* USE_I2C4 */


/**
* i2c_event() function
Expand Down Expand Up @@ -377,7 +432,7 @@ void i2c_setbitrate(struct i2c_periph *p __attribute__((unused)), int bitrate __
*/
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
{
#if USE_I2C1 || USE_I2C2 || USE_I2C3
#if USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4
// sys lock
chSysLock();
uint8_t temp;
Expand Down Expand Up @@ -406,7 +461,7 @@ bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
(void)p;
(void)t;
return FALSE;
#endif /* USE_I2C1 || USE_I2C2 || USE_I2C3 */
#endif /* USE_I2C1 || USE_I2C2 || USE_I2C3 || USE_I2C4 */
}

/**
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/arch/chibios/mcu_periph/i2c_arch.h
Expand Up @@ -45,4 +45,8 @@ extern void i2c2_hw_init(void);
extern void i2c3_hw_init(void);
#endif /* USE_I2C3 */

#if USE_I2C4
extern void i2c4_hw_init(void);
#endif /* USE_I2C4 */

#endif /* I2C_HW_H */
45 changes: 43 additions & 2 deletions sw/airborne/arch/chibios/mcu_periph/spi_arch.c
Expand Up @@ -167,10 +167,12 @@ static inline uint16_t spi_resolve_slave_pin(uint8_t slave)
static inline uint16_t spi_resolve_CR1(struct spi_transaction *t __attribute__((unused)))
{
uint16_t CR1 = 0;
#if defined(STM32F1) || defined(STM32F4) || defined(STM32F7)
#if defined(STM32F1) || defined(STM32F4)
if (t->dss == SPIDss16bit) {
CR1 |= SPI_CR1_DFF;
CR1 |= SPI_CR1_DFF; // FIXME for F7
}
#endif
#if defined(STM32F1) || defined(STM32F4) || defined(STM32F7)
if (t->bitorder == SPILSBFirst) {
CR1 |= SPI_CR1_LSBFIRST;
}
Expand Down Expand Up @@ -443,6 +445,45 @@ void spi3_arch_init(void)
}
#endif

#if USE_SPI4
static SEMAPHORE_DECL(spi4_sem, 0);
#if defined STM32F7
// We need a special buffer for DMA operations
static IN_DMA_SECTION(uint8_t spi4_dma_buf_out[SPI_DMA_BUF_LEN]);
static IN_DMA_SECTION(uint8_t spi4_dma_buf_in[SPI_DMA_BUF_LEN]);
static struct spi_init spi4_init_s = {
.sem = &spi4_sem,
.dma_buf_out = spi4_dma_buf_out,
.dma_buf_in = spi4_dma_buf_in
};
#else
static struct spi_init spi4_init_s = {
.sem = &spi4_sem,
};
#endif

static __attribute__((noreturn)) void thd_spi4(void *arg)
{
(void) arg;
chRegSetThreadName("spi4");

while (TRUE) {
handle_spi_thd(&spi4);
}
}

static THD_WORKING_AREA(wa_thd_spi4, 256);

void spi4_arch_init(void)
{
spi4.reg_addr = &SPID4;
spi4.init_struct = &spi4_init_s;
// Create thread
chThdCreateStatic(wa_thd_spi4, sizeof(wa_thd_spi4),
NORMALPRIO + 1, thd_spi4, NULL);
}
#endif


/**
* Submit SPI transaction
Expand Down

0 comments on commit 17b185d

Please sign in to comment.