Skip to content

Commit

Permalink
RCE target
Browse files Browse the repository at this point in the history
RCExplorer F3 board support for Cleanflight
  • Loading branch information
lkaino committed May 17, 2016
1 parent 961cbfd commit bdaeec1
Show file tree
Hide file tree
Showing 9 changed files with 753 additions and 5 deletions.
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ FLASH_SIZE ?=

FORKNAME = triflight

VALID_TARGETS = ALIENWIIF1 ALIENWIIF3 CC3D CHEBUZZF3 CJMCU COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE NAZE32PRO OLIMEXINO PORT103R RMDO SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY
VALID_TARGETS = ALIENWIIF1 ALIENWIIF3 CC3D CHEBUZZF3 CJMCU COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE NAZE32PRO OLIMEXINO PORT103R RCE RMDO SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY

# Configure default flash sizes for the targets
ifeq ($(FLASH_SIZE),)
ifeq ($(TARGET),$(filter $(TARGET),CJMCU))
FLASH_SIZE = 64
else ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF1 CC3D NAZE OLIMEXINO RMDO))
FLASH_SIZE = 128
else ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE32PRO PORT103R SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY))
else ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE32PRO PORT103R RCE SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY))
FLASH_SIZE = 256
else
$(error FLASH_SIZE not configured for target)
Expand All @@ -70,7 +70,7 @@ FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))

CSOURCES := $(shell find $(SRC_DIR) -name '*.c')

ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE MOTOLAB NAZE32PRO RMDO SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY))
ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE MOTOLAB NAZE32PRO RCE RMDO SPARKY SPRACINGF3 SPRACINGF3MINI STM32F3DISCOVERY))

STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver

Expand Down Expand Up @@ -590,6 +590,25 @@ ALIENWIIF3_SRC = \
$(HIGHEND_SRC) \
$(COMMON_SRC) \
$(VCP_SRC)

RCE_SRC = \
$(STM32F30x_COMMON_SRC) \
drivers/accgyro_mpu.c \
drivers/accgyro_spi_mpu6000.c \
drivers/accgyro_mpu6050.c \
drivers/barometer_ms5611.c \
drivers/compass_hmc5883l.c \
drivers/compass_ak8975.c \
drivers/display_ug2864hsweg01.c \
drivers/serial_usb_vcp.c \
drivers/flash_m25p16.c \
drivers/light_ws2811strip.c \
drivers/light_ws2811strip_stm32f30x.c \
drivers/sonar_hcsr04.c \
io/flashfs.c \
$(HIGHEND_SRC) \
$(COMMON_SRC) \
$(VCP_SRC)

RMDO_SRC = \
$(STM32F30x_COMMON_SRC) \
Expand Down
17 changes: 16 additions & 1 deletion src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ static void resetBatteryConfig(batteryConfig_t *batteryConfig)
batteryConfig->vbatmaxcellvoltage = 43;
batteryConfig->vbatmincellvoltage = 33;
batteryConfig->vbatwarningcellvoltage = 35;
#if defined(RCE)
batteryConfig->currentMeterScale = 360; // for the built-in current sensor on RCExplorer board
#else
batteryConfig->currentMeterScale = 400; // for Allegro ACS758LCB-100U (40mV/A)
#endif
batteryConfig->currentMeterType = CURRENT_SENSOR_ADC;
}

Expand Down Expand Up @@ -280,6 +284,13 @@ void resetSerialConfig(serialConfig_t *serialConfig)
// This allows MSP connection via USART & VCP so the board can be reconfigured.
serialConfig->portConfigs[1].functionMask = FUNCTION_MSP;
#endif
#if defined(RCE)
// On RCExplorer board, UART1 is serial RX by default
serialConfig->portConfigs[1].functionMask = FUNCTION_RX_SERIAL;
// UART2 and UART3 as MSP for safety
serialConfig->portConfigs[2].functionMask = FUNCTION_MSP;
serialConfig->portConfigs[3].functionMask = FUNCTION_MSP;
#endif

serialConfig->reboot_character = 'R';
}
Expand Down Expand Up @@ -320,8 +331,12 @@ static void resetMixerConfig(mixerConfig_t *mixerConfig) {
mixerConfig->tri_servo_min_adc = 0;
mixerConfig->tri_servo_mid_adc = 0;
mixerConfig->tri_servo_max_adc = 0;
#if defined(RCE)
mixerConfig->tri_servo_feedback = TRI_SERVO_FB_RSSI;
#else
mixerConfig->tri_servo_feedback = TRI_SERVO_FB_VIRTUAL;
#endif
#endif
}

uint8_t getCurrentProfile(void)
Expand Down Expand Up @@ -367,7 +382,7 @@ STATIC_UNIT_TESTED void resetConf(void)
masterConfig.version = EEPROM_CONF_VERSION;
masterConfig.mixerMode = MIXER_TRI;
featureClearAll();
#if defined(CJMCU) || defined(SPARKY) || defined(COLIBRI_RACE) || defined(MOTOLAB) || defined(SPRACINGF3MINI) || defined(LUX_RACE)
#if defined(CJMCU) || defined(SPARKY) || defined(COLIBRI_RACE) || defined(MOTOLAB) || defined(SPRACINGF3MINI) || defined(LUX_RACE) || defined(RCE)
featureSet(FEATURE_RX_PPM);
#endif

Expand Down
47 changes: 47 additions & 0 deletions src/main/drivers/pwm_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,46 @@ static const uint16_t airPWM[] = {
};
#endif

#ifdef RCE
static const uint16_t multiPPM[] = {
PWM6 | (MAP_TO_PPM_INPUT << 8), // PPM input
PWM3 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM2 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM17 - can be switched to servo
PWM4 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM1 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM1
PWM5 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
0xFFFF
};

static const uint16_t multiPWM[] = {
PWM3 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM2 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM17 - can be switched to servo
PWM4 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM1 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM1
PWM5 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
0xFFFF
};

static const uint16_t airPPM[] = {
PWM6 | (MAP_TO_PPM_INPUT << 8), // PPM input
PWM3 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM2 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM17 - can be switched to servo
PWM4 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM1 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM1
PWM5 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
0xFFFF
};

static const uint16_t airPWM[] = {
PWM3 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM2 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM17 - can be switched to servo
PWM4 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
PWM1 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM1
PWM5 | (MAP_TO_MOTOR_OUTPUT << 8), // TIM3
0xFFFF
};
#endif

static const uint16_t * const hardwareMaps[] = {
multiPWM,
multiPPM,
Expand Down Expand Up @@ -710,6 +750,13 @@ pwmIOConfiguration_t *pwmInit(drv_pwm_config_t *init)
type = MAP_TO_SERVO_OUTPUT;
#endif

#if defined(RCE)
if (timerIndex == PWM2)
{
type = MAP_TO_SERVO_OUTPUT;
}
#endif

#if defined(NAZE32PRO) || (defined(STM32F3DISCOVERY) && !defined(CHEBUZZF3))
// remap PWM 5+6 or 9+10 as servos - softserial pin pairs require timer ports that use the same timer
if (init->useSoftSerial) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/drivers/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
#define TIMER_APB1_PERIPHERALS (RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4)
#define TIMER_APB2_PERIPHERALS (RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM15 | RCC_APB2Periph_TIM16 | RCC_APB2Periph_TIM17)
#define TIMER_AHB_PERIPHERALS (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB)
#endif
#if defined(RCE)
const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = {
{ TIM3, GPIOA, Pin_4, TIM_Channel_2, TIM3_IRQn, 1, Mode_AF_PP, GPIO_PinSource4, GPIO_AF_2}, // PWM1 - PA4
{ TIM17, GPIOA, Pin_7, TIM_Channel_1, TIM1_TRG_COM_TIM17_IRQn, 1, Mode_AF_PP, GPIO_PinSource7, GPIO_AF_1}, // PWM2 - PA7
{ TIM1, GPIOA, Pin_8, TIM_Channel_1, TIM1_CC_IRQn, 1, Mode_AF_PP, GPIO_PinSource8, GPIO_AF_6}, // PWM3 - PA8
{ TIM3, GPIOB, Pin_0, TIM_Channel_3, TIM3_IRQn, 1, Mode_AF_PP, GPIO_PinSource0, GPIO_AF_2}, // PWM4 - PB0
{ TIM3, GPIOB, Pin_1, TIM_Channel_4, TIM3_IRQn, 1, Mode_AF_PP, GPIO_PinSource1, GPIO_AF_2}, // PWM5 - PB1
{ TIM2, GPIOA, Pin_1, TIM_Channel_2, TIM2_IRQn, 0, Mode_AF_PP, GPIO_PinSource1, GPIO_AF_1}, // PWM6 - PPM
};

#define USED_TIMERS (TIM_N(1) | TIM_N(2) | TIM_N(3) | TIM_N(17))

#define TIMER_APB1_PERIPHERALS (RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3)
#define TIMER_APB2_PERIPHERALS (RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM17)
#define TIMER_AHB_PERIPHERALS (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB)

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/main/sensors/initialisation.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const extiConfig_t *selectMPUIntExtiConfig(void)
return &cc3dMPUIntExtiConfig;
#endif

#ifdef MOTOLAB
#if defined(MOTOLAB) || defined(RCE)
static const extiConfig_t MotolabF3MPUIntExtiConfig = {
.gpioAHBPeripherals = RCC_AHBPeriph_GPIOA,
.gpioPort = GPIOA,
Expand Down
12 changes: 12 additions & 0 deletions src/main/sensors/sonar.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ const sonarHardware_t *sonarGetHardwareConfiguration(batteryConfig_t *batteryCon
.exti_irqn = EXTI1_IRQn
};
return &sonarHardware;
#elif defined(RCE)
UNUSED(batteryConfig);
static const sonarHardware_t const sonarHardware = {
.trigger_pin = Pin_6, // PWM5 (PA5) - only 3.3v ( add a 1K Ohms resistor )
.trigger_gpio = GPIOA,
.echo_pin = Pin_1, // PWM6 (PB1) - only 3.3v ( add a 1K Ohms resistor )
.echo_gpio = GPIOB,
.exti_line = EXTI_Line1,
.exti_pin_source = EXTI_PinSource1,
.exti_irqn = EXTI1_IRQn
};
return &sonarHardware;
#elif defined(UNIT_TEST)
UNUSED(batteryConfig);
return 0;
Expand Down
Loading

2 comments on commit bdaeec1

@pqueiros
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do the integration of the RCE target directly in cleanflight?. I think we should not limit the usage of the target to triflight only. Are you planning to do a pull request as soon as the target integration is available (possibly earlier than merging the complete fork upstream)?

@lkaino
Copy link
Owner Author

@lkaino lkaino commented on bdaeec1 May 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes plan is to pull to CF and BF. The .md page for the new target needs to be written.

Please sign in to comment.