mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
REFACTOR: Removing platform specific defines from init.c (#14463)
* REFACTOR: Removing platform specific defines from init.c * Further MCO improvements * Adding default
This commit is contained in:
parent
3ab8931a71
commit
cb6fc5aabd
10 changed files with 48 additions and 35 deletions
|
@ -104,7 +104,6 @@ COMMON_SRC = \
|
||||||
drivers/io.c \
|
drivers/io.c \
|
||||||
drivers/io_preinit.c \
|
drivers/io_preinit.c \
|
||||||
drivers/light_led.c \
|
drivers/light_led.c \
|
||||||
drivers/mco.c \
|
|
||||||
drivers/motor.c \
|
drivers/motor.c \
|
||||||
drivers/pinio.c \
|
drivers/pinio.c \
|
||||||
drivers/pin_pull_up_down.c \
|
drivers/pin_pull_up_down.c \
|
||||||
|
|
|
@ -1685,7 +1685,7 @@ const clivalue_t valueTable[] = {
|
||||||
#endif // end of #ifdef USE_OSD
|
#endif // end of #ifdef USE_OSD
|
||||||
|
|
||||||
// PG_SYSTEM_CONFIG
|
// PG_SYSTEM_CONFIG
|
||||||
#if defined(STM32F4) || defined(STM32G4) || defined(APM32F4)
|
#if PLATFORM_TRAIT_CONFIG_HSE
|
||||||
{ "system_hse_mhz", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, hseMhz) },
|
{ "system_hse_mhz", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, 30 }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, hseMhz) },
|
||||||
#endif
|
#endif
|
||||||
{ "task_statistics", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, task_statistics) },
|
{ "task_statistics", VAR_INT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_SYSTEM_CONFIG, offsetof(systemConfig_t, task_statistics) },
|
||||||
|
@ -1867,11 +1867,12 @@ const clivalue_t valueTable[] = {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MCO
|
#ifdef USE_MCO
|
||||||
#ifdef STM32G4
|
#if defined(USE_MCO_DEVICE1)
|
||||||
|
// TODO: remove pin specific names
|
||||||
{ "mco_on_pa8", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, enabled) },
|
{ "mco_on_pa8", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, enabled) },
|
||||||
{ "mco_source", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, MCO_SOURCE_COUNT - 1 }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, source) },
|
{ "mco_source", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, MCO_SOURCE_COUNT - 1 }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, source) },
|
||||||
{ "mco_divider", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, MCO_DIVIDER_COUNT - 1 }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, divider) },
|
{ "mco_divider", VAR_UINT8 | HARDWARE_VALUE, .config.minmaxUnsigned = { 0, MCO_DIVIDER_COUNT - 1 }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 0, divider) },
|
||||||
#else
|
#elif defined(USE_MCO_DEVICE2)
|
||||||
{ "mco2_on_pc9", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 1, enabled) },
|
{ "mco2_on_pc9", VAR_UINT8 | HARDWARE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_MCO_CONFIG, PG_ARRAY_ELEMENT_OFFSET(mcoConfig_t, 1, enabled) },
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,9 +27,4 @@ typedef enum {
|
||||||
MCODEV_2,
|
MCODEV_2,
|
||||||
} MCODevice_e;
|
} MCODevice_e;
|
||||||
|
|
||||||
#ifdef STM32G4
|
void mcoInit(void);
|
||||||
#define MCO_SOURCE_COUNT 8
|
|
||||||
#define MCO_DIVIDER_COUNT 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mcoConfigure(MCODevice_e device, const mcoConfig_t *config);
|
|
||||||
|
|
|
@ -483,9 +483,7 @@ void init(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STM32F4) || defined(STM32G4) || defined(APM32F4)
|
#if PLATFORM_TRAIT_CONFIG_HSE
|
||||||
// F4 has non-8MHz boards
|
|
||||||
// G4 for Betaflight allow 8, 16, 24, 26 or 27MHz oscillator
|
|
||||||
systemClockSetHSEValue(systemConfig()->hseMhz * 1000000U);
|
systemClockSetHSEValue(systemConfig()->hseMhz * 1000000U);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -495,18 +493,7 @@ void init(void)
|
||||||
|
|
||||||
// Configure MCO output after config is stable
|
// Configure MCO output after config is stable
|
||||||
#ifdef USE_MCO
|
#ifdef USE_MCO
|
||||||
// Note that mcoConfigure must be augmented with an additional argument to
|
mcoInit();
|
||||||
// indicate which device instance to configure when MCO and MCO2 are both supported
|
|
||||||
|
|
||||||
#if defined(STM32F4) || defined(STM32F7) || defined(APM32F4)
|
|
||||||
// F4 and F7 support MCO on PA8 and MCO2 on PC9, but only MCO2 is supported for now
|
|
||||||
mcoConfigure(MCODEV_2, mcoConfig(MCODEV_2));
|
|
||||||
#elif defined(STM32G4)
|
|
||||||
// G4 only supports one MCO on PA8
|
|
||||||
mcoConfigure(MCODEV_1, mcoConfig(MCODEV_1));
|
|
||||||
#else
|
|
||||||
#error Unsupported MCU
|
|
||||||
#endif
|
|
||||||
#endif // USE_MCO
|
#endif // USE_MCO
|
||||||
|
|
||||||
#ifdef USE_TIMER
|
#ifdef USE_TIMER
|
||||||
|
@ -574,7 +561,7 @@ void init(void)
|
||||||
initFlags |= QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED;
|
initFlags |= QUAD_OCTO_SPI_BUSSES_INIT_ATTEMPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_SDCARD_SDIO) && !defined(CONFIG_IN_SDCARD) && defined(STM32H7)
|
#if defined(USE_SDCARD_SDIO) && !defined(CONFIG_IN_SDCARD) && PLATFORM_TRAIT_SDIO_INIT
|
||||||
sdioPinConfigure();
|
sdioPinConfigure();
|
||||||
SDIO_GPIO_Init();
|
SDIO_GPIO_Init();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -117,6 +117,7 @@
|
||||||
#define USE_USB_MSC
|
#define USE_USB_MSC
|
||||||
#define USE_PERSISTENT_MSC_RTC
|
#define USE_PERSISTENT_MSC_RTC
|
||||||
#define USE_MCO
|
#define USE_MCO
|
||||||
|
#define USE_MCO_DEVICE2
|
||||||
#define USE_DMA_SPEC
|
#define USE_DMA_SPEC
|
||||||
#define USE_PERSISTENT_OBJECTS
|
#define USE_PERSISTENT_OBJECTS
|
||||||
#define USE_LATE_TASK_STATISTICS
|
#define USE_LATE_TASK_STATISTICS
|
||||||
|
@ -127,6 +128,7 @@
|
||||||
#define SCHEDULER_DELAY_LIMIT 10
|
#define SCHEDULER_DELAY_LIMIT 10
|
||||||
|
|
||||||
#define DEFAULT_CPU_OVERCLOCK 0
|
#define DEFAULT_CPU_OVERCLOCK 0
|
||||||
|
#define PLATFORM_TRAIT_CONFIG_HSE 1
|
||||||
|
|
||||||
#define FAST_IRQ_HANDLER
|
#define FAST_IRQ_HANDLER
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,7 @@ MCU_COMMON_SRC = \
|
||||||
common/stm32/system.c \
|
common/stm32/system.c \
|
||||||
common/stm32/io_impl.c \
|
common/stm32/io_impl.c \
|
||||||
common/stm32/config_flash.c \
|
common/stm32/config_flash.c \
|
||||||
|
common/stm32/mco.c \
|
||||||
APM32/startup/system_apm32f4xx.c \
|
APM32/startup/system_apm32f4xx.c \
|
||||||
drivers/inverter.c \
|
drivers/inverter.c \
|
||||||
drivers/dshot_bitbang_decode.c \
|
drivers/dshot_bitbang_decode.c \
|
||||||
|
|
|
@ -85,6 +85,7 @@ MCU_COMMON_SRC = \
|
||||||
common/stm32/system.c \
|
common/stm32/system.c \
|
||||||
common/stm32/io_impl.c \
|
common/stm32/io_impl.c \
|
||||||
common/stm32/config_flash.c \
|
common/stm32/config_flash.c \
|
||||||
|
common/stm32/mco.c \
|
||||||
AT32/startup/at32f435_437_clock.c \
|
AT32/startup/at32f435_437_clock.c \
|
||||||
AT32/startup/system_at32f435_437.c \
|
AT32/startup/system_at32f435_437.c \
|
||||||
AT32/adc_at32f43x.c \
|
AT32/adc_at32f43x.c \
|
||||||
|
|
|
@ -130,6 +130,7 @@
|
||||||
#define USE_USB_MSC
|
#define USE_USB_MSC
|
||||||
#define USE_PERSISTENT_MSC_RTC
|
#define USE_PERSISTENT_MSC_RTC
|
||||||
#define USE_MCO
|
#define USE_MCO
|
||||||
|
#define USE_MCO_DEVICE2
|
||||||
#define USE_DMA_SPEC
|
#define USE_DMA_SPEC
|
||||||
#define USE_PERSISTENT_OBJECTS
|
#define USE_PERSISTENT_OBJECTS
|
||||||
#define USE_LATE_TASK_STATISTICS
|
#define USE_LATE_TASK_STATISTICS
|
||||||
|
@ -152,6 +153,7 @@
|
||||||
#define USE_USB_MSC
|
#define USE_USB_MSC
|
||||||
#define USE_PERSISTENT_MSC_RTC
|
#define USE_PERSISTENT_MSC_RTC
|
||||||
#define USE_MCO
|
#define USE_MCO
|
||||||
|
#define USE_MCO_DEVICE2
|
||||||
#define USE_DMA_SPEC
|
#define USE_DMA_SPEC
|
||||||
#define USE_PERSISTENT_OBJECTS
|
#define USE_PERSISTENT_OBJECTS
|
||||||
#define USE_LATE_TASK_STATISTICS
|
#define USE_LATE_TASK_STATISTICS
|
||||||
|
@ -188,6 +190,7 @@
|
||||||
#define USE_USB_MSC
|
#define USE_USB_MSC
|
||||||
#define USE_USB_CDC_HID
|
#define USE_USB_CDC_HID
|
||||||
#define USE_MCO
|
#define USE_MCO
|
||||||
|
#define USE_MCO_DEVICE1
|
||||||
#define USE_DMA_SPEC
|
#define USE_DMA_SPEC
|
||||||
#define USE_LATE_TASK_STATISTICS
|
#define USE_LATE_TASK_STATISTICS
|
||||||
#endif
|
#endif
|
||||||
|
@ -447,4 +450,16 @@ extern uint8_t _dmaram_end__;
|
||||||
#define QUADSPI_TRAIT_AF_PIN 1
|
#define QUADSPI_TRAIT_AF_PIN 1
|
||||||
#define QUADSPI_TRAIT_HANDLE 1
|
#define QUADSPI_TRAIT_HANDLE 1
|
||||||
#define MAX_QUADSPI_PIN_SEL 3
|
#define MAX_QUADSPI_PIN_SEL 3
|
||||||
|
#define PLATFORM_TRAIT_SDIO_INIT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// F4 has non-8MHz boards
|
||||||
|
// G4 for Betaflight allow 8, 16, 24, 26 or 27MHz oscillator
|
||||||
|
#if defined(STM32F4) || defined(STM32G4)
|
||||||
|
#define PLATFORM_TRAIT_CONFIG_HSE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(STM32G4)
|
||||||
|
#define MCO_SOURCE_COUNT 8
|
||||||
|
#define MCO_DIVIDER_COUNT 5
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@ MCU_COMMON_SRC += \
|
||||||
common/stm32/system.c \
|
common/stm32/system.c \
|
||||||
common/stm32/config_flash.c \
|
common/stm32/config_flash.c \
|
||||||
common/stm32/bus_spi_pinconfig.c \
|
common/stm32/bus_spi_pinconfig.c \
|
||||||
|
common/stm32/mco.c \
|
||||||
drivers/bus_spi_config.c \
|
drivers/bus_spi_config.c \
|
||||||
drivers/serial_pinconfig.c \
|
drivers/serial_pinconfig.c \
|
||||||
common/stm32/bus_i2c_pinconfig.c \
|
common/stm32/bus_i2c_pinconfig.c \
|
||||||
|
|
|
@ -61,7 +61,7 @@ const uint32_t mcoDividers[MCO_DIVIDER_COUNT] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void mcoConfigure(MCODevice_e device, const mcoConfig_t *config)
|
static void mcoConfigure(MCODevice_e device, const mcoConfig_t *config)
|
||||||
{
|
{
|
||||||
if (!config->enabled) {
|
if (!config->enabled) {
|
||||||
return;
|
return;
|
||||||
|
@ -69,15 +69,19 @@ void mcoConfigure(MCODevice_e device, const mcoConfig_t *config)
|
||||||
|
|
||||||
IO_t io;
|
IO_t io;
|
||||||
|
|
||||||
#if defined(STM32F4) || defined(STM32F7) || defined(APM32F4)
|
|
||||||
// Only configure MCO2 with PLLI2SCLK as source for now.
|
// Only configure MCO2 with PLLI2SCLK as source for now.
|
||||||
// Other MCO1 and other sources can easily be added.
|
// Other MCO1 and other sources can easily be added.
|
||||||
|
|
||||||
switch(device) {
|
switch(device) {
|
||||||
case MCODEV_1: // MCO1 on PA8
|
case MCODEV_1: // MCO1 on PA8
|
||||||
return; // Not supported (yet)
|
#if defined(STM32G4)
|
||||||
|
io = IOGetByTag(DEFIO_TAG_E(PA8));
|
||||||
|
IOInit(io, OWNER_MCO, 1);
|
||||||
|
HAL_RCC_MCOConfig(RCC_MCO, mcoSources[config->source], mcoDividers[config->divider]);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
case MCODEV_2: // MCO2 on PC9
|
case MCODEV_2: // MCO2 on PC9
|
||||||
|
#if defined(STM32F4) || defined(STM32F7) || defined(APM32F4)
|
||||||
io = IOGetByTag(DEFIO_TAG_E(PC9));
|
io = IOGetByTag(DEFIO_TAG_E(PC9));
|
||||||
IOInit(io, OWNER_MCO, 2);
|
IOInit(io, OWNER_MCO, 2);
|
||||||
#if defined(STM32F7)
|
#if defined(STM32F7)
|
||||||
|
@ -90,16 +94,23 @@ void mcoConfigure(MCODevice_e device, const mcoConfig_t *config)
|
||||||
// All F4s
|
// All F4s
|
||||||
RCC_MCO2Config(RCC_MCO2Source_PLLI2SCLK, RCC_MCO2Div_4);
|
RCC_MCO2Config(RCC_MCO2Source_PLLI2SCLK, RCC_MCO2Div_4);
|
||||||
IOConfigGPIOAF(io, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL), GPIO_AF_MCO);
|
IOConfigGPIOAF(io, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_NOPULL), GPIO_AF_MCO);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// No MCO configured
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcoInit(void)
|
||||||
|
{
|
||||||
|
#if defined(STM32F4) || defined(STM32F7) || defined(APM32F4)
|
||||||
|
// F4 and F7 support MCO on PA8 and MCO2 on PC9, but only MCO2 is supported for now
|
||||||
|
mcoConfigure(MCODEV_2, mcoConfig(MCODEV_2));
|
||||||
#elif defined(STM32G4)
|
#elif defined(STM32G4)
|
||||||
// G4 only supports one MCO on PA8
|
// G4 only supports one MCO on PA8
|
||||||
UNUSED(device);
|
mcoConfigure(MCODEV_1, mcoConfig(MCODEV_1));
|
||||||
|
|
||||||
io = IOGetByTag(DEFIO_TAG_E(PA8));
|
|
||||||
IOInit(io, OWNER_MCO, 1);
|
|
||||||
HAL_RCC_MCOConfig(RCC_MCO, mcoSources[config->source], mcoDividers[config->divider]);
|
|
||||||
#else
|
#else
|
||||||
#error Unsupported MCU
|
#error Unsupported MCU
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue