From 524bbf43297aecf21017831cf7cfb5f0d0be64a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=98=82?= Date: Tue, 12 Sep 2023 01:09:14 +0800 Subject: [PATCH] fix stm32 support for f1 --- package/STM32/pika_hal_stm32_ADC.c | 4 ++-- package/STM32/pika_hal_stm32_DAC.c | 12 ++++++++++ package/STM32/pika_hal_stm32_common.c | 3 +++ package/STM32/pika_hal_stm32_common.h | 32 +++++++++++++++++++++------ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/package/STM32/pika_hal_stm32_ADC.c b/package/STM32/pika_hal_stm32_ADC.c index 016313bf4..3c1c3e473 100644 --- a/package/STM32/pika_hal_stm32_ADC.c +++ b/package/STM32/pika_hal_stm32_ADC.c @@ -152,7 +152,7 @@ static rt_err_t stm32_adc_get_channel(rt_int8_t rt_channel, uint32_t *stm32_chan #define ADCx_CLK_ENABLE __HAL_RCC_ADC1_CLK_ENABLE static void adcx_clock_enable(ADC_HandleTypeDef *adch) { - #if defined(STM32F0) || defined(STM32F4) || defined(STM32F7) || defined(STM32L1) + #if defined(STM32F0) || defined(STM32F1) || defined(STM32F4) || defined(STM32F7) || defined(STM32L1) ADCx_CLK_ENABLE(); #elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) __HAL_RCC_ADC12_CLK_ENABLE(); @@ -340,7 +340,7 @@ static rt_int16_t stm32_adc_get_vref (struct rt_adc_device *device) static void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t timeout) { uint32_t tickstart = HAL_GetTick(); - #if defined(STM32F4) || defined(STM32F7) || defined(STM32L1) + #if defined(STM32F4) || defined(STM32F1) || defined(STM32F7) || defined(STM32L1) while ((adcHandle->Instance->SR & ADC_FLAG_EOC) != ADC_FLAG_EOC) { #elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB) while (READ_BIT(adcHandle->Instance->ISR, ADC_FLAG_EOC) != ADC_FLAG_EOC) { diff --git a/package/STM32/pika_hal_stm32_DAC.c b/package/STM32/pika_hal_stm32_DAC.c index 8818784b7..2ceac255d 100644 --- a/package/STM32/pika_hal_stm32_DAC.c +++ b/package/STM32/pika_hal_stm32_DAC.c @@ -24,6 +24,16 @@ //#define LOG_TAG "drv.dac" //#include +#ifndef DAC1_CONFIG +#undef BSP_USING_DAC1 +#endif + +#ifndef DAC2_CONFIG +#undef BSP_USING_DAC2 +#endif + +#if defined(BSP_USING_DAC1) || defined(BSP_USING_DAC2) + static DAC_HandleTypeDef dac_config[] = { #ifdef BSP_USING_DAC1 @@ -386,4 +396,6 @@ int pika_hal_platform_DAC_ioctl_disable(pika_dev* dev) { return -1; } +#endif + #endif /* BSP_USING_DAC */ diff --git a/package/STM32/pika_hal_stm32_common.c b/package/STM32/pika_hal_stm32_common.c index 92e6037a6..fc622113d 100644 --- a/package/STM32/pika_hal_stm32_common.c +++ b/package/STM32/pika_hal_stm32_common.c @@ -17,6 +17,9 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) { #if defined(STM32F0) || defined(STM32L1) #define AHBxENR AHBENR #define AHBxENR_GPIOAEN_Pos RCC_AHBENR_GPIOAEN_Pos + #elif defined(STM32F1) + #define AHBxENR APB2ENR + #define AHBxENR_GPIOAEN_Pos RCC_APB2ENR_IOPAEN #elif defined(STM32F4) || defined(STM32F7) #define AHBxENR AHB1ENR #define AHBxENR_GPIOAEN_Pos RCC_AHB1ENR_GPIOAEN_Pos diff --git a/package/STM32/pika_hal_stm32_common.h b/package/STM32/pika_hal_stm32_common.h index d8535da1e..c217b21c3 100644 --- a/package/STM32/pika_hal_stm32_common.h +++ b/package/STM32/pika_hal_stm32_common.h @@ -12,35 +12,53 @@ #define CHIP_FAMILY_STM32 #define SOC_FAMILY_STM32 #define RT_USING_DEVICE_OPS + +#define SERIES_OF(_start) (defined(_start##xx) || defined(_start##x8) || \ + defined(_start##xB) || defined(_start##xC) || \ + defined(_start##xD) || defined(_start##xE) || defined(_start##xG)) -#if defined(STM32H750xx) || defined(STM32H743xx) || defined(STM32H753xx) || defined(STM32H755xx) || defined(STM32H757xx) +/* auto select HAL header */ +#if SERIES_OF(STM32H750) || SERIES_OF(STM32H743) || SERIES_OF(STM32H753) || \ + SERIES_OF(STM32H755) || SERIES_OF(STM32H757) #define SOC_SERIES_STM32H7 #define CHIP_SERIES_STM32H7 #include "stm32h7xx_hal.h" -#elif defined(STM32F103xx) || defined(STM32F101xx) || defined(STM32F102xx) + +#elif SERIES_OF(STM32F103) || SERIES_OF(STM32F102) || SERIES_OF(STM32F101) #define SOC_SERIES_STM32F1 #define CHIP_SERIES_STM32F1 #include "stm32f1xx_hal.h" -#elif defined(STM32G030xx) || defined(STM32G031xx) || defined(STM32G041xx) || defined(STM32G070xx) || defined(STM32G071xx) || defined(STM32G081xx) + +#elif SERIES_OF(STM32G030) || SERIES_OF(STM32G031) || SERIES_OF(STM32G041) || \ + SERIES_OF(STM32G070) || SERIES_OF(STM32G071) || SERIES_OF(STM32G081) #define SOC_SERIES_STM32G0 #define CHIP_SERIES_STM32G0 #include "stm32g0xx_hal.h" -#elif defined(STM32F030xx) || defined(STM32F031xx) || defined(STM32F051xx) || defined(STM32F070xx) || defined(STM32F042xx) + +#elif SERIES_OF(STM32F030) || SERIES_OF(STM32F031) || SERIES_OF(STM32F051) || \ + SERIES_OF(STM32F070) || SERIES_OF(STM32F042) #define SOC_SERIES_STM32F0 #define CHIP_SERIES_STM32F0 #include "stm32f0xx_hal.h" -#elif defined(STM32F401xx) || defined(STM32F405xx) || defined(STM32F407xx) || defined(STM32F411xx) + +#elif SERIES_OF(STM32F401) || SERIES_OF(STM32F405) || SERIES_OF(STM32F407) || \ + SERIES_OF(STM32F411) #define SOC_SERIES_STM32F4 #define CHIP_SERIES_STM32F4 #include "stm32f4xx_hal.h" -#elif defined(STM32U585xx) || defined(STM32U575xx) + +#elif SERIES_OF(STM32U585) || SERIES_OF(STM32U575) #define SOC_SERIES_STM32U5 #define CHIP_SERIES_STM32U5 #include "stm32u5xx_hal.h" -#elif defined(STM32L451xx) || defined(STM32L452xx) || defined(STM32L462xx) || defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) + +#elif SERIES_OF(STM32L451) || SERIES_OF(STM32L452) || SERIES_OF(STM32L462) || \ + SERIES_OF(STM32L471) || SERIES_OF(STM32L475) || SERIES_OF(STM32L476) || \ + SERIES_OF(STM32L485) || SERIES_OF(STM32L486) #define SOC_SERIES_STM32L4 #define CHIP_SERIES_STM32L4 #include "stm32l4xx_hal.h" + #else #error "Unsupported STM32 series" #endif