From 3d9c4589cdb476ca97b1ec0395cd97f3d6bafe27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Mon, 9 Nov 2020 07:53:35 +0100 Subject: [PATCH] Upgrade to Zephyr 2.4 - Make all struct device * constant - Add additional argument to PWM nodes in devicetree - Track customized LibreSolar/zephyr branch in platformio - Update OLED submodule --- boards/arm/mppt_1210_hus/pinmux.c | 2 +- boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts | 4 ++-- boards/arm/mppt_2420_hpx/pinmux.c | 2 +- boards/arm/mppt_2420_lc/pinmux.c | 2 +- boards/arm/mppt_2420_rc/pinmux.c | 2 +- boards/arm/pwm_2420_lus/pinmux.c | 2 +- boards/arm/pwm_2420_lus/pwm_2420_lus.dts | 4 ++-- lib/oled-display | 2 +- platformio-extra.py | 8 ++++++++ platformio.ini | 11 ++++++++--- src/daq_driver.c | 2 +- src/dcdc.cpp | 4 ++-- src/eeprom.cpp | 4 ++-- src/ext/can.cpp | 4 ++-- src/ext/oled.cpp | 2 +- src/ext/serial.cpp | 4 ++-- src/hardware.cpp | 4 ++-- src/leds.cpp | 2 +- src/load_driver.c | 6 +++--- 19 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 platformio-extra.py diff --git a/boards/arm/mppt_1210_hus/pinmux.c b/boards/arm/mppt_1210_hus/pinmux.c index 8e8c275..9335d1c 100644 --- a/boards/arm/mppt_1210_hus/pinmux.c +++ b/boards/arm/mppt_1210_hus/pinmux.c @@ -46,7 +46,7 @@ static const struct pin_config pinconf[] = { #endif /* CONFIG_DAC, dac1 */ }; -static int pinmux_stm32_init(struct device *port) +static int pinmux_stm32_init(const struct device *port) { ARG_UNUSED(port); diff --git a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts index b7424df..3695ee3 100644 --- a/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts +++ b/boards/arm/mppt_2420_hpx/mppt_2420_hpx.dts @@ -51,7 +51,7 @@ pwm_switch { label = "PWM power switch (solar panel)"; - pwms = <&pwm3 2 (20*1000*1000)>; /* 20 ms period = 50 Hz */ + pwms = <&pwm3 2 (20*1000*1000) PWM_POLARITY_NORMAL>; /* 20 ms period = 50 Hz */ current-max = <20>; kconfig-flag; /* make node visible in Kconfig */ }; @@ -65,7 +65,7 @@ charge_pump { label = "Charge pump for HS MOSFET drivers"; - pwms = <&pwm8 1 200000>; /* 200 us period = 5 kHz */ + pwms = <&pwm8 1 200000 PWM_POLARITY_NORMAL>; /* 200 us period = 5 kHz */ }; hv-ext-sense { diff --git a/boards/arm/mppt_2420_hpx/pinmux.c b/boards/arm/mppt_2420_hpx/pinmux.c index dfc0a30..cd10438 100644 --- a/boards/arm/mppt_2420_hpx/pinmux.c +++ b/boards/arm/mppt_2420_hpx/pinmux.c @@ -54,7 +54,7 @@ static const struct pin_config pinconf[] = { #endif /* CONFIG_USB_DC_STM32 */ }; -static int pinmux_stm32_init(struct device *port) +static int pinmux_stm32_init(const struct device *port) { ARG_UNUSED(port); diff --git a/boards/arm/mppt_2420_lc/pinmux.c b/boards/arm/mppt_2420_lc/pinmux.c index 47f56cc..577c6df 100644 --- a/boards/arm/mppt_2420_lc/pinmux.c +++ b/boards/arm/mppt_2420_lc/pinmux.c @@ -58,7 +58,7 @@ static const struct pin_config pinconf[] = { #endif /* CONFIG_CAN, can1 */ }; -static int pinmux_stm32_init(struct device *port) +static int pinmux_stm32_init(const struct device *port) { ARG_UNUSED(port); diff --git a/boards/arm/mppt_2420_rc/pinmux.c b/boards/arm/mppt_2420_rc/pinmux.c index 255f907..fcb546c 100644 --- a/boards/arm/mppt_2420_rc/pinmux.c +++ b/boards/arm/mppt_2420_rc/pinmux.c @@ -49,7 +49,7 @@ static const struct pin_config pinconf[] = { #endif }; -static int pinmux_stm32_init(struct device *port) +static int pinmux_stm32_init(const struct device *port) { ARG_UNUSED(port); diff --git a/boards/arm/pwm_2420_lus/pinmux.c b/boards/arm/pwm_2420_lus/pinmux.c index 868367e..6c6a082 100644 --- a/boards/arm/pwm_2420_lus/pinmux.c +++ b/boards/arm/pwm_2420_lus/pinmux.c @@ -39,7 +39,7 @@ static const struct pin_config pinconf[] = { #endif /* CONFIG_SPI, spi1 */ }; -static int pinmux_stm32_init(struct device *port) +static int pinmux_stm32_init(const struct device *port) { ARG_UNUSED(port); diff --git a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts index 7010379..c9fddbe 100644 --- a/boards/arm/pwm_2420_lus/pwm_2420_lus.dts +++ b/boards/arm/pwm_2420_lus/pwm_2420_lus.dts @@ -66,7 +66,7 @@ pwm_switch { label = "PWM power switch (solar panel)"; - pwms = <&pwm3 4 (20*1000*1000)>; /* 20 ms period = 50 Hz */ + pwms = <&pwm3 4 (20*1000*1000) PWM_POLARITY_NORMAL>; /* 20 ms period = 50 Hz */ // Current reduced to 15A. Increase to 20A PCB max values // only if attached to a big heat sink. current-max = <15>; @@ -162,7 +162,7 @@ status = "okay"; st,prescaler = <10000>; label = "PWM_3"; - #pwm-cells = <2>; + #pwm-cells = <3>; }; }; }; diff --git a/lib/oled-display b/lib/oled-display index 3b10da7..4eec1ea 160000 --- a/lib/oled-display +++ b/lib/oled-display @@ -1 +1 @@ -Subproject commit 3b10da79dc852b1e125640754d688fd4c82df105 +Subproject commit 4eec1ea4d8d1537c4bb7ab67572c968dac808343 diff --git a/platformio-extra.py b/platformio-extra.py new file mode 100644 index 0000000..3a5d8de --- /dev/null +++ b/platformio-extra.py @@ -0,0 +1,8 @@ + +# Custom settings, as referred to as "extra_script" in platformio.ini +# +# See http://docs.platformio.org/en/latest/projectconf.html#extra-script + +Import("env") + +env.Append( CXXFLAGS=[ "-Wno-register -fno-rtti" ] ) diff --git a/platformio.ini b/platformio.ini index 1b768a1..a0d8fbd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,12 +23,14 @@ extra_configs = [env] -# ststm32 platform release >7.1.1 includes Zephyr 2.3.0 #platform = https://github.com/platformio/platform-ststm32.git -platform = ststm32@~8.0.0 +platform = ststm32@~8.1.0 framework = zephyr +# Use customized Zephyr branch from Libre Solar repository +platform_packages = framework-zephyr@https://github.com/LibreSolar/zephyr#v2.4-branch + #upload_protocol = mbed upload_protocol = stlink #upload_protocol = jlink @@ -44,7 +46,10 @@ build_flags = -fsingle-precision-constant -Wl,-Map,memory.map -build_unflags = -std=gnu++98 -std=gnu++14 +# Below flags are only valid for C++ and create warnings for C files, so we add them as +# CXXFLAGS in extra_script. +build_unflags = -Wno-register -fno-rtti +extra_scripts = platformio-extra.py check_tool = cppcheck, clangtidy check_flags = diff --git a/src/daq_driver.c b/src/daq_driver.c index 0167fd0..5dee52c 100644 --- a/src/daq_driver.c +++ b/src/daq_driver.c @@ -257,7 +257,7 @@ static void adc_init(ADC_TypeDef *adc) static void adc_setup() { #if DT_NODE_EXISTS(DT_PROP(V_HIGH_ENABLE_GPIO, enable_gpios)) - struct device *dev = device_get_binding(DT_GPIO_LABEL(V_HIGH_ENABLE_GPIO, enable_gpios)); + const struct device *dev = device_get_binding(DT_GPIO_LABEL(V_HIGH_ENABLE_GPIO, enable_gpios)); gpio_pin_configure(dev, DT_GPIO_PIN(V_HIGH_ENABLE_GPIO, enable_gpios), DT_GPIO_FLAGS(V_HIGH_ENABLE_GPIO, enable_gpios) | GPIO_OUTPUT_ACTIVE); #endif diff --git a/src/dcdc.cpp b/src/dcdc.cpp index fb871e3..6b39289 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -335,7 +335,7 @@ void Dcdc::fuse_destruction() void Dcdc::output_hvs_enable() { #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_ext_sense)) - struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); + const struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); gpio_pin_configure(dev_hv_ext, DT_GPIO_PIN(HV_EXT_SENSE_GPIO, gpios), DT_GPIO_FLAGS(HV_EXT_SENSE_GPIO, gpios) | GPIO_OUTPUT_ACTIVE); #endif @@ -344,7 +344,7 @@ void Dcdc::output_hvs_enable() void Dcdc::output_hvs_disable() { #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), hv_ext_sense)) - struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); + const struct device *dev_hv_ext = device_get_binding(DT_GPIO_LABEL(HV_EXT_SENSE_GPIO, gpios)); gpio_pin_configure(dev_hv_ext, DT_GPIO_PIN(HV_EXT_SENSE_GPIO, gpios), DT_GPIO_FLAGS(HV_EXT_SENSE_GPIO, gpios) | GPIO_OUTPUT_INACTIVE); #endif diff --git a/src/eeprom.cpp b/src/eeprom.cpp index 370e75e..036e021 100644 --- a/src/eeprom.cpp +++ b/src/eeprom.cpp @@ -71,7 +71,7 @@ void eeprom_restore_data() uint8_t buf_req[300]; // ThingSet request buffer int err; - struct device *eeprom_dev = device_get_binding("EEPROM_0"); + const struct device *eeprom_dev = device_get_binding("EEPROM_0"); // EEPROM header uint8_t buf_header[EEPROM_HEADER_SIZE] = {}; // initialize to avoid compiler warning @@ -114,7 +114,7 @@ void eeprom_store_data() { uint8_t buf[300]; - struct device *eeprom_dev = device_get_binding("EEPROM_0"); + const struct device *eeprom_dev = device_get_binding("EEPROM_0"); int len = ts.bin_pub(buf + EEPROM_HEADER_SIZE, sizeof(buf) - EEPROM_HEADER_SIZE, PUB_NVM); uint32_t crc = _calc_crc(buf + EEPROM_HEADER_SIZE, len); diff --git a/src/ext/can.cpp b/src/ext/can.cpp index 6702fcc..708780b 100644 --- a/src/ext/can.cpp +++ b/src/ext/can.cpp @@ -30,7 +30,7 @@ LOG_MODULE_REGISTER(ext_can, CONFIG_LOG_DEFAULT_LEVEL); extern ThingSet ts; extern uint16_t ts_can_node_id; -struct device *can_dev; +const struct device *can_dev; #ifdef CONFIG_ISOTP @@ -127,7 +127,7 @@ void can_pub_thread() unsigned int can_id; uint8_t can_data[8]; - struct device *can_en_dev = device_get_binding(DT_GPIO_LABEL(CAN_EN_GPIO, gpios)); + const struct device *can_en_dev = device_get_binding(DT_GPIO_LABEL(CAN_EN_GPIO, gpios)); gpio_pin_configure(can_en_dev, DT_GPIO_PIN(CAN_EN_GPIO, gpios), DT_GPIO_FLAGS(CAN_EN_GPIO, gpios) | GPIO_OUTPUT_ACTIVE); diff --git a/src/ext/oled.cpp b/src/ext/oled.cpp index 33d8f3c..20cc03e 100644 --- a/src/ext/oled.cpp +++ b/src/ext/oled.cpp @@ -173,7 +173,7 @@ void oled_update() void oled_thread() { #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), uext_en)) - struct device *dev_uext_en = device_get_binding(DT_GPIO_LABEL(UEXT_EN_GPIO, gpios)); + const struct device *dev_uext_en = device_get_binding(DT_GPIO_LABEL(UEXT_EN_GPIO, gpios)); gpio_pin_configure(dev_uext_en, DT_GPIO_PIN(UEXT_EN_GPIO, gpios), DT_GPIO_FLAGS(UEXT_EN_GPIO, gpios) | GPIO_OUTPUT_ACTIVE); #endif diff --git a/src/ext/serial.cpp b/src/ext/serial.cpp index c01146d..a333576 100644 --- a/src/ext/serial.cpp +++ b/src/ext/serial.cpp @@ -26,7 +26,7 @@ #error "No UART for ThingSet serial defined." #endif -struct device *uart_dev = device_get_binding(UART_DEVICE_NAME); +const struct device *uart_dev = device_get_binding(UART_DEVICE_NAME); static char buf_resp[CONFIG_THINGSET_SERIAL_TX_BUF_SIZE]; static char buf_req[CONFIG_THINGSET_SERIAL_RX_BUF_SIZE]; @@ -73,7 +73,7 @@ void process_asap() * Read characters from stream until line end \n detected, signal command available then * and wait for processing */ -void process_input(void* user_data) +void process_input(const struct device *dev, void* user_data) { uint8_t c; diff --git a/src/hardware.cpp b/src/hardware.cpp index 6e8a8a0..a96aa8c 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -43,7 +43,7 @@ struct sw_wdt_channel { uint32_t timeout; // timeout of corresponding thread for sw_watchdog }; -static struct device *wdt; +static const struct device *wdt; struct k_timer sw_wdt_timer; struct sw_wdt_channel sw_wdt_channels[MAX_SW_WDT_CHANNELS]; @@ -124,7 +124,7 @@ void start_stm32_bootloader() #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), boot0)) // pin is connected to BOOT0 via resistor and capacitor - struct device *dev = device_get_binding(DT_GPIO_LABEL(BOOT0_GPIO, gpios)); + const struct device *dev = device_get_binding(DT_GPIO_LABEL(BOOT0_GPIO, gpios)); gpio_pin_configure(dev, DT_GPIO_PIN(BOOT0_GPIO, gpios), DT_GPIO_FLAGS(BOOT0_GPIO, gpios) | GPIO_OUTPUT_ACTIVE); diff --git a/src/leds.cpp b/src/leds.cpp index 312034c..9266bc0 100644 --- a/src/leds.cpp +++ b/src/leds.cpp @@ -115,7 +115,7 @@ void leds_update_thread() unsigned int led_count = 0; int flicker_count = 0; bool flicker_state = true; - struct device *led_devs[NUM_LED_PINS]; + const struct device *led_devs[NUM_LED_PINS]; int wdt_channel = watchdog_register(1000); diff --git a/src/load_driver.c b/src/load_driver.c index 68ac5cf..5b6a0d6 100644 --- a/src/load_driver.c +++ b/src/load_driver.c @@ -23,12 +23,12 @@ #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load)) #define LOAD_GPIO DT_CHILD(DT_PATH(outputs), load) -static struct device *dev_load; +static const struct device *dev_load; #endif #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr)) #define USB_GPIO DT_CHILD(DT_PATH(outputs), usb_pwr) -static struct device *dev_usb; +static const struct device *dev_usb; #endif #include "hardware.h" @@ -229,7 +229,7 @@ void load_cp_enable() This should do the same using the Zephyr driver, but there seems to be a bug in Zephyr v2.2 so that it doesn't work with advanced timer as TIM8. Keep it here until Zephyr bug was fixed. - struct device *pwm_dev; + const struct device *pwm_dev; pwm_dev = device_get_binding(DT_OUTPUTS_CHARGE_PUMP_PWMS_CONTROLLER); if (!pwm_dev) { LOG_ERR("Cannot find %s!\n", DT_OUTPUTS_CHARGE_PUMP_PWMS_CONTROLLER);