From f55b236a56f5301696f6941b118e2ab3d7f6882b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Tue, 25 Aug 2020 13:55:17 +0200 Subject: [PATCH] Update MCU-specific defines and includes Distinguish properly between MCU series and actual MCUs. Constants in mcu.h had to be changed to #defines to be useable from C code (not only C++). --- src/load_driver.c | 4 ++-- src/mcu.h | 26 ++++++++++++++------------ src/pwm_switch_driver.c | 7 +++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/load_driver.c b/src/load_driver.c index 2e9c83f..68ac5cf 100644 --- a/src/load_driver.c +++ b/src/load_driver.c @@ -33,6 +33,7 @@ static struct device *dev_usb; #include "hardware.h" #include "leds.h" +#include "mcu.h" // short circuit detection comparator only present in PWM 2420 LUS board so far #ifdef CONFIG_BOARD_PWM_2420_LUS @@ -181,11 +182,10 @@ void usb_out_set(bool status) #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), charge_pump)) -#if defined(CONFIG_SOC_STM32G431XX) +#if defined(CONFIG_SOC_SERIES_STM32G4X) #include #include #include -#include "stm32g431xx.h" #endif #define CP_PWM_PERIOD (DT_PHA(DT_CHILD(DT_PATH(outputs), charge_pump), pwms, period)) diff --git a/src/mcu.h b/src/mcu.h index ba17d46..a4974e1 100644 --- a/src/mcu.h +++ b/src/mcu.h @@ -7,39 +7,41 @@ #ifndef MCU_H_ #define MCU_H_ -#ifdef CONFIG_SOC_SERIES_STM32F0X +#ifdef CONFIG_SOC_STM32F072XB #include "stm32f072xb.h" #endif -#ifdef CONFIG_SOC_SERIES_STM32L0X +#ifdef CONFIG_SOC_STM32L072XX #include "stm32l072xx.h" #endif -#ifdef CONFIG_SOC_SERIES_STM32G4X +#if defined(CONFIG_SOC_STM32G431XX) #include "stm32g431xx.h" +#elif defined(CONFIG_SOC_STM32G474XX) +#include "stm32g474xx.h" #endif // factory calibration values for internal voltage reference and temperature sensor // (see MCU datasheet, not Reference Manual) #if defined(CONFIG_SOC_SERIES_STM32F0X) - const uint16_t VREFINT_CAL = *((uint16_t *)0x1FFFF7BA); // VREFINT @3.3V/30°C + #define VREFINT_CAL (*((uint16_t *)0x1FFFF7BA)) // VREFINT @3.3V/30°C #define VREFINT_VALUE 3300 // mV - const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FFFF7B8); - const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FFFF7C2); + #define TSENSE_CAL1 (*((uint16_t *)0x1FFFF7B8)) + #define TSENSE_CAL2 (*((uint16_t *)0x1FFFF7C2)) #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point #define TSENSE_CAL2_VALUE 110.0 // temperature of second calibration point #elif defined(CONFIG_SOC_SERIES_STM32L0X) - const uint16_t VREFINT_CAL = *((uint16_t *)0x1FF80078); // VREFINT @3.0V/25°C + #define VREFINT_CAL (*((uint16_t *)0x1FF80078)) // VREFINT @3.0V/25°C #define VREFINT_VALUE 3000 // mV - const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FF8007A); - const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FF8007E); + #define TSENSE_CAL1 (*((uint16_t *)0x1FF8007A)) + #define TSENSE_CAL2 (*((uint16_t *)0x1FF8007E)) #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point #define TSENSE_CAL2_VALUE 130.0 // temperature of second calibration point #elif defined(CONFIG_SOC_SERIES_STM32G4X) - const uint16_t VREFINT_CAL = *((uint16_t *)0x1FFF75AA); // VREFINT @3.0V/30°C + #define VREFINT_CAL (*((uint16_t *)0x1FFF75AA)) // VREFINT @3.0V/30°C #define VREFINT_VALUE 3000 // mV - const uint16_t TSENSE_CAL1 = *((uint16_t *)0x1FFF75A8); - const uint16_t TSENSE_CAL2 = *((uint16_t *)0x1FFF75CA); + #define TSENSE_CAL1 (*((uint16_t *)0x1FFF75A8)) + #define TSENSE_CAL2 (*((uint16_t *)0x1FFF75CA)) #define TSENSE_CAL1_VALUE 30.0 // temperature of first calibration point #define TSENSE_CAL2_VALUE 110.0 // temperature of second calibration point #elif defined(UNIT_TEST) diff --git a/src/pwm_switch_driver.c b/src/pwm_switch_driver.c index 54722d3..ca3210d 100644 --- a/src/pwm_switch_driver.c +++ b/src/pwm_switch_driver.c @@ -13,17 +13,16 @@ #include "daq.h" #include "helper.h" +#include "mcu.h" -#if defined(CONFIG_SOC_STM32L072XX) +#if defined(CONFIG_SOC_SERIES_STM32L0X) #include #include #include -#include "stm32l072xx.h" -#elif defined(CONFIG_SOC_STM32G431XX) +#elif defined(CONFIG_SOC_SERIES_STM32G4X) #include #include #include -#include "stm32g431xx.h" #endif #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), pwm_switch))