diff --git a/boards/libresolar/mppt_2420_solaris/Kconfig.defconfig b/boards/libresolar/mppt_2420_solaris/Kconfig.defconfig new file mode 100644 index 0000000..da8bae4 --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/Kconfig.defconfig @@ -0,0 +1,9 @@ +# Copyright (c) The Libre Solar Project Contributors +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_MPPT_2420_SOLARIS + +config LIBRE_SOLAR_TYPE_ID + default 8 + +endif # BOARD_MPPT_2420_SOLARIS diff --git a/boards/libresolar/mppt_2420_solaris/Kconfig.mppt_2420_solaris b/boards/libresolar/mppt_2420_solaris/Kconfig.mppt_2420_solaris new file mode 100644 index 0000000..025591d --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/Kconfig.mppt_2420_solaris @@ -0,0 +1,5 @@ +# Copyright (c) The Libre Solar Project Contributors +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_MPPT_2420_SOLARIS + select SOC_STM32G491XX diff --git a/boards/libresolar/mppt_2420_solaris/board.cmake b/boards/libresolar/mppt_2420_solaris/board.cmake new file mode 100644 index 0000000..e38a08b --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/board.cmake @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(pyocd "--target=stm32g491cctx") +board_runner_args(jlink "--device=STM32G491CC" "--speed=4000" "--reset-after-load") + +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) diff --git a/boards/libresolar/mppt_2420_solaris/board.yml b/boards/libresolar/mppt_2420_solaris/board.yml new file mode 100644 index 0000000..3c2f5d3 --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/board.yml @@ -0,0 +1,6 @@ +board: + name: mppt_2420_solaris + full_name: Libre Solar MPPT 2420 SOLARIS + vendor: libresolar + socs: + - name: stm32g491xx diff --git a/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.dts b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.dts new file mode 100644 index 0000000..f17e769 --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.dts @@ -0,0 +1,233 @@ +/* + * Copyright (c) The Libre Solar Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include + +/ { + model = "Libre Solar MPPT 2420 SOLARIS"; + compatible = "st,stm32g491"; + + pcb { + compatible = "charge-controller"; + + type = "MPPT 2420 SOLARIS"; + version-str = "v0.1"; + version-num = <1>; + + hs-voltage-max = <90>; + ls-voltage-max = <32>; + dcdc-current-max = <20>; + }; + + chosen { + thingset,can = &fdcan1; + thingset,serial = &usart2; + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &slot0_partition; + }; + + /* temporary solution only using green color LED */ + leds { + compatible = "charlieplexing-leds"; + gpios = <&gpioa 6 GPIO_ACTIVE_LOW>, /* chg red */ + <&gpioc 14 GPIO_ACTIVE_LOW>, /* chg green */ + <&gpiob 9 GPIO_ACTIVE_LOW>, /* dis red */ + <&gpioc 15 GPIO_ACTIVE_LOW>; /* dis green */ + + pwr { + states = <0 1 0 0>; + }; + }; + + outputs { + compatible = "outputs"; + + can_en { + gpios = <&gpiob 11 GPIO_ACTIVE_LOW>; + }; + }; + + adc-inputs { + compatible = "adc-inputs"; + + v-low { + io-channels = <&adc1 12>; + multiplier = <105600>; + divider = <5600>; + }; + + v-high { + io-channels = <&adc1 15>; + multiplier = <102200>; + divider = <2200>; + }; + + temp-fets { + io-channels = <&adc1 11>; + multiplier = <10000>; // 10k NTC series resistor + divider = <1>; + }; + + vref-mcu { + io-channels = <&adc1 18>; + multiplier = <1>; + divider = <1>; + }; + + temp-mcu { + io-channels = <&adc1 16>; + multiplier = <1>; + divider = <1>; + }; + + i-dcdc { + io-channels = <&adc2 1>; + // amp gain: 25, resistor: 2 mOhm + multiplier = <1000>; // 1000 + divider = <50>; // 2*25 + }; + }; + + aliases { + uart-dbg = &usart1; + uart-uext = &usart2; + spi-uext = &spi1; + i2c-uext = &i2c1; + }; +}; + +&clk_hse { + clock-frequency = ; + status = "okay"; +}; + +&clk_hsi48 { + status = "okay"; +}; + +&pll { + div-m = <2>; + mul-n = <75>; + div-p = <7>; + div-q = <2>; + div-r = <2>; + clocks = <&clk_hse>; + status = "okay"; +}; + +&rcc { + clocks = <&pll>; + clock-frequency = ; + ahb-prescaler = <1>; + apb1-prescaler = <1>; + apb2-prescaler = <1>; +}; + +&rng { + clocks = <&rcc STM32_CLOCK(AHB2, 26)>, + <&rcc STM32_SRC_HSI48 CLK48_SEL(0)>; + status = "okay"; +}; + +&usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; + pinctrl-names = "default"; + current-speed = <115200>; + status = "okay"; +}; + +&usart1_rx_pa10 { + bias-pull-up; // avoid junk characters if pin is left floating +}; + +&usart2 { + pinctrl-0 = <&usart2_tx_pa2 &usart2_rx_pa3>; + pinctrl-names = "default"; + current-speed = <115200>; + status = "okay"; +}; + +&usart2_rx_pa3 { + bias-pull-up; // avoid junk characters if pin is left floating +}; + +&i2c1 { + pinctrl-0 = <&i2c1_scl_pa15 &i2c1_sda_pb7>; + pinctrl-names = "default"; + clock-frequency = ; + status = "okay"; +}; + +&spi1 { + pinctrl-0 = <&spi1_sck_pb3 &spi1_miso_pb4 &spi1_mosi_pb5>; + pinctrl-names = "default"; + cs-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>; + status = "okay"; +}; + +&iwdg { + status = "okay"; +}; + +&timers1 { + status = "okay"; + + halfbridge: halfbridge { + compatible = "half-bridge"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pc13>; + pinctrl-names = "default"; + frequency = <70000>; + deadtime = <300>; + }; +}; + +&fdcan1 { + clocks = <&rcc STM32_CLOCK(APB1, 25)>, + <&rcc STM32_SRC_PLL_Q FDCAN_SEL(1)>; + pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>; + pinctrl-names = "default"; + bitrate = <500000>; + bitrate-data = <2000000>; + status = "okay"; +}; + +/* + * Below partition layout allows to use MCUboot if CONFIG_BOOTLOADER_MCUBOOT is enabled. Otherwise, + * the code will just use the entire available flash of the MCU. + */ +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 DT_SIZE_K(32)>; + }; + + slot0_partition: partition@8000 { + label = "image-0"; + reg = <0x00008000 DT_SIZE_K(112)>; + }; + + slot1_partition: partition@24000 { + label = "image-1"; + reg = <0x00024000 DT_SIZE_K(108)>; + }; + + /* Set 4Kb of storage at the end of the 256Kb of flash */ + storage_partition: partition@3f000 { + label = "storage"; + reg = <0x0003f000 DT_SIZE_K(4)>; + }; + }; +}; diff --git a/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.yaml b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.yaml new file mode 100644 index 0000000..62b112b --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris.yaml @@ -0,0 +1,18 @@ +identifier: mppt_2420_solaris +name: MPPT-2420-SOLARIS +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 112 +flash: 256 +supported: + - nvs + - pwm + - i2c + - gpio + - usb device + - counter + - spi diff --git a/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris_defconfig b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris_defconfig new file mode 100644 index 0000000..83c6272 --- /dev/null +++ b/boards/libresolar/mppt_2420_solaris/mppt_2420_solaris_defconfig @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_ARM_MPU=y +CONFIG_HW_STACK_PROTECTION=y +CONFIG_MPU_ALLOW_FLASH_WRITE=y + +CONFIG_CLOCK_CONTROL=y + +CONFIG_PINCTRL=y + +CONFIG_GPIO=y + +CONFIG_SERIAL=y + +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# RNG required for automatic CAN node address assignment +CONFIG_ENTROPY_GENERATOR=y +CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y + +CONFIG_CAN=y +CONFIG_ISOTP=y +CONFIG_ISOTP_FAST=y +CONFIG_THINGSET_CAN=y + +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_LOG_LEVEL_WRN=y + +CONFIG_NVS=y +CONFIG_NVS_LOG_LEVEL_WRN=y