diff --git a/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt b/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt new file mode 100755 index 0000000..d1b8108 --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_PINMUX) +zephyr_library() +zephyr_library_sources(pinmux.c) +zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) +endif() diff --git a/boards/arm/mppt_1210_hus_0v7/Kconfig b/boards/arm/mppt_1210_hus_0v7/Kconfig new file mode 100644 index 0000000..abfb339 --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/Kconfig @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2019 Martin Jäger / Libre Solar + +# include generic charge controller Kconfig +rsource "../../Kconfig" diff --git a/boards/arm/mppt_1210_hus_0v7/Kconfig.board b/boards/arm/mppt_1210_hus_0v7/Kconfig.board new file mode 100755 index 0000000..0e83836 --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/Kconfig.board @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2019 Martin Jäger / Libre Solar + +config BOARD_MPPT_1210_HUS_0V7 + bool "Libre Solar MPPT 1210 HUS v0.7" + depends on SOC_STM32L073XX diff --git a/boards/arm/mppt_1210_hus_0v7/Kconfig.defconfig b/boards/arm/mppt_1210_hus_0v7/Kconfig.defconfig new file mode 100755 index 0000000..4eb2fd0 --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/Kconfig.defconfig @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright (c) 2019 Martin Jäger / Libre Solar + +if BOARD_MPPT_1210_HUS_0V7 + +config BOARD + default "mppt_1210_hus_0v7" + +config HAS_DCDC_CONVERTER + default y + +config DCDC_PWM_FREQUENCY_KHZ + default 50 + +config DCDC_PWM_DEADTIME_NS + default 230 + +config HAS_LOAD_OUTPUT + default y + +config NUM_LED_PINS + default 3 + +if UART_CONSOLE + +config UART_2 + default y + +endif # UART_CONSOLE + +if I2C + +config I2C_1 + default y + +endif # I2C + +if SPI + +config SPI_1 + default y + +config SPI_STM32_INTERRUPT + default y + +endif # SPI + +endif # BOARD_MPPT_1210_HUS_0V7 diff --git a/boards/arm/mppt_1210_hus_0v7/board.cmake b/boards/arm/mppt_1210_hus_0v7/board.cmake new file mode 100755 index 0000000..6f20255 --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/board.cmake @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(jlink "--device=STM32L073RZ" "--speed=4000") + +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) diff --git a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts new file mode 100755 index 0000000..615dbbf --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.dts @@ -0,0 +1,86 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2020 Martin Jäger / Libre Solar + */ + +/dts-v1/; +#include + +/ { + model = "Libre Solar MPPT 1210 HUS v0.7"; + compatible = "st,stm32l073"; + + chosen { + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + }; + + leds { + compatible = "gpio-leds"; + a { + gpios = <&gpiob 13 GPIO_INT_ACTIVE_HIGH>; + label = "LED pin A"; + }; + b { + gpios = <&gpiob 14 GPIO_INT_ACTIVE_HIGH>; + label = "LED pin B"; + }; + c { + gpios = <&gpiob 2 GPIO_INT_ACTIVE_HIGH>; + label = "LED pin C"; + }; + }; + + switches { + compatible = "switch"; + load-en { + gpios = <&gpioc 13 GPIO_DIR_IN>; + label = "Load enable"; + }; + usb-pwr-en { + gpios = <&gpiob 10 GPIO_DIR_IN>; + label = "USB charging port enable"; + }; + v-solar-en { + gpios = <&gpioc 14 GPIO_DIR_IN>; + label = "Solar voltage measurement enable"; + }; + }; + + aliases { + uart-dbg = &usart1; + uext-uart = &usart2; + spi-uext = &spi1; + i2c-uext = &i2c1; + }; +}; + +&usart1 { + current-speed = <115200>; + status = "okay"; +}; + +&usart2 { + current-speed = <115200>; + status = "okay"; +}; + +&i2c1 { + status = "okay"; + clock-frequency = ; +}; + +&spi1 { + status = "okay"; +}; + +&iwdg { + status = "okay"; +}; + +&adc1 { + status = "okay"; +}; diff --git a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.yaml b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.yaml new file mode 100755 index 0000000..f41092e --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7.yaml @@ -0,0 +1,17 @@ +identifier: mppt_1210_hus_0v7 +name: MPPT-1210-HUS-0V7 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 20 +flash: 192 +supported: + - arduino_i2c + - gpio + - i2c + - spi + - watchdog + - adc diff --git a/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7_defconfig b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7_defconfig new file mode 100755 index 0000000..f7481bb --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/mppt_1210_hus_0v7_defconfig @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Zephyr Kernel Configuration +CONFIG_ARM=y +CONFIG_SOC_SERIES_STM32L0X=y + +# Platform Configuration +CONFIG_SOC_STM32L073XX=y + +# General Kernel Options +CONFIG_CORTEX_M_SYSTICK=y +CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=32000000 + +# Serial Drivers +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# Pinmux Driver +CONFIG_PINMUX=y + +# GPIO Controller +CONFIG_GPIO=y + +# Clock configuration +CONFIG_CLOCK_CONTROL=y +# SYSCLK selection +CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y + +# PLL configuration +CONFIG_CLOCK_STM32_PLL_SRC_HSI=y +CONFIG_CLOCK_STM32_PLL_MULTIPLIER=4 +CONFIG_CLOCK_STM32_PLL_DIVISOR=2 +CONFIG_CLOCK_STM32_AHB_PRESCALER=1 +CONFIG_CLOCK_STM32_APB1_PRESCALER=1 diff --git a/boards/arm/mppt_1210_hus_0v7/pinmux.c b/boards/arm/mppt_1210_hus_0v7/pinmux.c new file mode 100755 index 0000000..79e0e7a --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/pinmux.c @@ -0,0 +1,74 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2019 Martin Jäger / Libre Solar + */ + +#include +#include +#include +#include +#include + +#include + +// preliminary fix until PR for pinmux_stm32l0.h got accepted and merged to Zephyr master branch, +// see also here: https://github.com/zephyrproject-rtos/zephyr/pull/20997 +#ifndef STM32L0_PINMUX_FUNC_PB6_I2C1_SCL +#define STM32L0_PINMUX_FUNC_PB6_I2C1_SCL \ + (STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP) +#endif +#ifndef STM32L0_PINMUX_FUNC_PB7_I2C1_SDA +#define STM32L0_PINMUX_FUNC_PB7_I2C1_SDA \ + (STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP) +#endif + +/* pin assignments for NUCLEO-L073RZ board */ +static const struct pin_config pinconf[] = { +#ifdef CONFIG_UART_1 + {STM32_PIN_PA9, STM32L0_PINMUX_FUNC_PA9_USART1_TX}, + {STM32_PIN_PA10, STM32L0_PINMUX_FUNC_PA10_USART1_RX}, +#endif /* CONFIG_UART_1 */ +#ifdef CONFIG_UART_2 + {STM32_PIN_PA2, STM32L0_PINMUX_FUNC_PA2_USART2_TX}, + {STM32_PIN_PA3, STM32L0_PINMUX_FUNC_PA3_USART2_RX}, +#endif /* CONFIG_UART_2 */ +#ifdef CONFIG_I2C_1 + {STM32_PIN_PB6, STM32L0_PINMUX_FUNC_PB6_I2C1_SCL}, + {STM32_PIN_PB7, STM32L0_PINMUX_FUNC_PB7_I2C1_SDA}, +#endif /* CONFIG_I2C_1 */ +#ifdef CONFIG_SPI_1 + {STM32_PIN_PA5, STM32L0_PINMUX_FUNC_PA5_SPI1_SCK}, + {STM32_PIN_PA6, STM32L0_PINMUX_FUNC_PA6_SPI1_MISO}, + {STM32_PIN_PA7, STM32L0_PINMUX_FUNC_PA7_SPI1_MOSI}, +#endif /* CONFIG_SPI_1 */ +#ifdef CONFIG_ADC_1 + {STM32_PIN_PA0, STM32L0_PINMUX_FUNC_PA0_ADC_IN0}, +#endif /* CONFIG_ADC_1 */ +#ifdef CONFIG_DAC_1 + {STM32_PIN_PA4, STM32L0_PINMUX_FUNC_PA4_DAC_OUT1}, +#endif /* CONFIG_ADC_1 */ +}; + +static int pinmux_stm32_init(struct device *port) +{ + ARG_UNUSED(port); + + stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf)); + + return 0; +} + +SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, + CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY); + +const char *led_ports[CONFIG_NUM_LED_PINS] = { + DT_GPIO_LEDS_A_GPIOS_CONTROLLER, + DT_GPIO_LEDS_C_GPIOS_CONTROLLER, + DT_GPIO_LEDS_B_GPIOS_CONTROLLER, +}; +const int led_pins[CONFIG_NUM_LED_PINS] = { + DT_GPIO_LEDS_A_GPIOS_PIN, + DT_GPIO_LEDS_C_GPIOS_PIN, + DT_GPIO_LEDS_B_GPIOS_PIN, +}; \ No newline at end of file diff --git a/boards/arm/mppt_1210_hus_0v7/support/openocd.cfg b/boards/arm/mppt_1210_hus_0v7/support/openocd.cfg new file mode 100755 index 0000000..b2f37ca --- /dev/null +++ b/boards/arm/mppt_1210_hus_0v7/support/openocd.cfg @@ -0,0 +1,27 @@ +# STM32L072 MCU + +source [find interface/stlink.cfg] + +transport select hla_swd + +set WORKAREASIZE 0x2000 + +source [find target/stm32l0.cfg] + +# Add the second flash bank. +set _FLASHNAME $_CHIPNAME.flash1 +flash bank $_FLASHNAME stm32lx 0 0 0 0 $_TARGETNAME + +# There is only system reset line and JTAG/SWD command can be issued when SRST +reset_config srst_only + +$_TARGETNAME configure -event gdb-attach { + echo "Debugger attaching: halting execution" + reset halt + gdb_breakpoint_override hard +} + +$_TARGETNAME configure -event gdb-detach { + echo "Debugger detaching: resuming execution" + resume +} diff --git a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts index 394e469..b27b781 100644 --- a/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts +++ b/boards/arm/pwm_2420_lus_0v3/pwm_2420_lus_0v3.dts @@ -40,7 +40,7 @@ gpios = <&gpiob 2 GPIO_DIR_IN>; label = "Load disable"; }; - usb-dis { + usb-pwr-dis { gpios = <&gpiob 5 GPIO_DIR_IN>; label = "USB charging port disable"; }; diff --git a/boards/mppt_1210_hus_0v7.json b/boards/mppt_1210_hus_0v7.json new file mode 100644 index 0000000..535106a --- /dev/null +++ b/boards/mppt_1210_hus_0v7.json @@ -0,0 +1,43 @@ +{ + "build": { + "cpu": "cortex-m0plus", + "extra_flags": "-DSTM32L073xx", + "f_cpu": "32000000L", + "framework_extra_flags": { + "arduino": "-D__CORTEX_SC=0" + }, + "mcu": "stm32l073rz", + "variant": "MPPT-1210-HUS" + }, + "debug": { + "default_tools": [ + "stlink" + ], + "jlink_device": "STM32L073RZ", + "onboard_tools": [ + "stlink" + ], + "openocd_board": "st_nucleo_l073rz", + "svd_path": "STM32L07x.svd" + }, + "frameworks": [ + "arduino", + "mbed", + "stm32cube", + "zephyr" + ], + "name": "Libre Solar MPPT 1210 HUS v0.7", + "upload": { + "maximum_ram_size": 20480, + "maximum_size": 196608, + "protocol": "stlink", + "protocols": [ + "jlink", + "stlink", + "blackmagic", + "mbed" + ] + }, + "url": "http://libre.solar/", + "vendor": "Libre Solar" +} diff --git a/platformio.ini b/platformio.ini index 09df52a..7ef14d5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,6 +17,7 @@ default_envs = # mppt-1210-hus-v0.6 # mppt-1210-hus-v0.7 # mppt-1210-hus-v0.4-zephyr +# mppt-1210-hus-v0.7-zephyr # pwm-2420-lus-v0.2 # pwm-2420-lus-v0.3 # pwm-2420-lus-v0.3-bl @@ -125,6 +126,17 @@ platform = https://github.com/platformio/platform-ststm32.git lib_ignore = ESP32 extra_scripts = generate_version_file.py +[env:mppt-1210-hus-v0.7-zephyr] +board = mppt_1210_hus_0v7 +framework = zephyr +build_flags = + -std=gnu++17 + -fsingle-precision-constant + -Wl,-Map,memory.map +platform = https://github.com/platformio/platform-ststm32.git +lib_ignore = ESP32 +extra_scripts = generate_version_file.py + [env:mppt-2420-hpx-v0.1-zephyr] board = mppt_2420_hpx framework = zephyr diff --git a/src/pcbs/mppt_1210_hus_0v7.h b/src/pcbs/mppt_1210_hus_0v7.h index 5a5db32..b8aca63 100644 --- a/src/pcbs/mppt_1210_hus_0v7.h +++ b/src/pcbs/mppt_1210_hus_0v7.h @@ -7,13 +7,15 @@ #ifndef MPPT_1210_HUS_0V7_H #define MPPT_1210_HUS_0V7_H -#define DEVICE_TYPE "MPPT-1210-HUS" -#define HARDWARE_VERSION "v0.7.1" - #ifdef __MBED__ #include "mbed.h" +#elif defined(__ZEPHYR__) +#include #endif +#define DEVICE_TYPE "MPPT-1210-HUS" +#define HARDWARE_VERSION "v0.7.1" + // specify features of charge controller #define CONFIG_HAS_DCDC_CONVERTER 1 #define CONFIG_HAS_PWM_SWITCH 0 @@ -67,21 +69,27 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; #define LED_LOAD 3 // LED4 #define LED_RXTX 4 // LED5, used to indicate when sending data -#ifdef __MBED__ // LED pins and pin state configuration to switch above LEDs on #define NUM_LED_PINS 3 + +#ifdef __MBED__ static const PinName led_pins[NUM_LED_PINS] = { // A B C PB_13, PB_2, PB_14 }; -static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { +#elif defined(__ZEPHYR__) +// defined in board definition pinmux.c +extern const char *led_ports[CONFIG_NUM_LED_PINS]; +extern const int led_pins[CONFIG_NUM_LED_PINS]; +#endif // MBED or ZEPHYR + +static const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { { PIN_HIGH, PIN_LOW, PIN_FLOAT }, // LED1 { PIN_LOW, PIN_HIGH, PIN_FLOAT }, // LED2 { PIN_HIGH, PIN_FLOAT, PIN_LOW }, // LED3 { PIN_FLOAT, PIN_HIGH, PIN_LOW }, // LED4 { PIN_FLOAT, PIN_LOW, PIN_HIGH } // LED5 }; -#endif // __MBED__ // pin definition only needed in adc_dma.cpp to detect if they are present on the PCB #define PIN_ADC_TEMP_BAT