Zephyr: MPPT 2420 LC board added

This commit is contained in:
Martin Jaeger
2020-01-29 11:03:09 +01:00
parent 81c0764f2c
commit e078b87553
18 changed files with 381 additions and 9 deletions
+7
View File
@@ -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()
+5
View File
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
# include generic charge controller Kconfig
rsource "../../Kconfig"
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
config BOARD_MPPT_2420_LC_0V10
bool "Libre Solar MPPT 2420 LC v0.10"
depends on SOC_STM32F072XB
+48
View File
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2019 Martin Jäger / Libre Solar
if BOARD_MPPT_2420_LC_0V10
config BOARD
default "mppt_2420_lc_0v10"
config HAS_DCDC_CONVERTER
default y
config DCDC_PWM_FREQUENCY_KHZ
default 70
config DCDC_PWM_DEADTIME_NS
default 300
config HAS_LOAD_OUTPUT
default y
config NUM_LED_PINS
default 2
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_2420_LC_0V10
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=STM32F072CB" "--speed=4000")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
+78
View File
@@ -0,0 +1,78 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
/dts-v1/;
#include <st/f0/stm32f072Xb.dtsi>
/ {
model = "Libre Solar MPPT 2420 LC v0.10";
compatible = "st,stm32f072";
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "gpio-leds";
pwr {
gpios = <&gpiob 14 GPIO_INT_ACTIVE_LOW>;
label = "LED GND";
};
load {
gpios = <&gpiob 15 GPIO_INT_ACTIVE_HIGH>;
label = "LED Load";
};
};
switches {
compatible = "switch";
load-dis {
gpios = <&gpiob 2 GPIO_DIR_IN>;
label = "Load disable";
};
uext-dis {
gpios = <&gpioc 14 GPIO_DIR_IN>;
label = "UEXT disable";
};
};
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 = <I2C_BITRATE_FAST>;
};
&spi1 {
status = "okay";
};
&iwdg {
status = "okay";
};
&adc1 {
status = "okay";
};
+17
View File
@@ -0,0 +1,17 @@
identifier: mppt_2420_LC_0v10
name: MPPT-2420-LC-0V10
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 16
flash: 128
supported:
- arduino_i2c
- gpio
- i2c
- spi
- watchdog
- adc
+36
View File
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: Apache-2.0
# Zephyr Kernel Configuration
CONFIG_ARM=y
CONFIG_SOC_SERIES_STM32F0X=y
# Platform Configuration
CONFIG_SOC_STM32F072XB=y
# General Kernel Options
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=48000000
# 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_HSE_CLOCK=8000000
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# PLL configuration
CONFIG_CLOCK_STM32_PLL_SRC_HSE=y
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=6
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
+70
View File
@@ -0,0 +1,70 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
// preliminary fix, as Zephyr doesn't yet include all possible pinmuxes
#ifndef STM32F0_PINMUX_FUNC_PB6_I2C1_SCL
#define STM32F0_PINMUX_FUNC_PB6_I2C1_SCL \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
#ifndef STM32F0_PINMUX_FUNC_PB7_I2C1_SDA
#define STM32F0_PINMUX_FUNC_PB7_I2C1_SDA \
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
#endif
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_1
{STM32_PIN_PA9, STM32F0_PINMUX_FUNC_PA9_USART1_TX},
{STM32_PIN_PA10, STM32F0_PINMUX_FUNC_PA10_USART1_RX},
#endif /* CONFIG_UART_1 */
#ifdef CONFIG_UART_2
{STM32_PIN_PA2, STM32F0_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F0_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_2 */
#ifdef CONFIG_I2C_1
{STM32_PIN_PB6, STM32F0_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32F0_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C_1 */
#ifdef CONFIG_SPI_1
{STM32_PIN_PB3, STM32F0_PINMUX_FUNC_PB3_SPI1_SCK},
{STM32_PIN_PB4, STM32F0_PINMUX_FUNC_PB4_SPI1_MISO},
{STM32_PIN_PB5, STM32F0_PINMUX_FUNC_PB5_SPI1_MOSI},
#endif /* CONFIG_SPI_1 */
#ifdef CONFIG_ADC_1
{STM32_PIN_PA0, STM32F0_PINMUX_FUNC_PA0_ADC_IN0},
#endif /* CONFIG_ADC_1 */
#ifdef CONFIG_DAC_1
{STM32_PIN_PA4, STM32F0_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_PWR_GPIOS_CONTROLLER,
DT_GPIO_LEDS_LOAD_GPIOS_CONTROLLER
};
const int led_pins[CONFIG_NUM_LED_PINS] = {
DT_GPIO_LEDS_PWR_GPIOS_PIN,
DT_GPIO_LEDS_LOAD_GPIOS_PIN
};
+12
View File
@@ -0,0 +1,12 @@
source [find board/st_nucleo_f0.cfg]
$_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
}
+41
View File
@@ -0,0 +1,41 @@
{
"build": {
"cpu": "cortex-m0",
"extra_flags": "-DSTM32F072xB",
"f_cpu": "48000000L",
"mcu": "stm32f072rbt6"
},
"connectivity": [
"can"
],
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32F072RB",
"onboard_tools": [
"stlink"
],
"openocd_board": "st_nucleo_f0",
"svd_path": "STM32F072x.svd"
},
"frameworks": [
"mbed",
"stm32cube",
"zephyr"
],
"name": "Libre Solar MPPT 2420 LC v0.10",
"upload": {
"maximum_ram_size": 16384,
"maximum_size": 131072,
"protocol": "stlink",
"protocols": [
"jlink",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "http://libre.solar/",
"vendor": "Libre Solar"
}
+12
View File
@@ -10,6 +10,7 @@
# Select the charge controller hardware by uncommenting one of the following lines
default_envs =
# mppt-2420-lc-v0.10
# mppt-2420-lc-v0.10-zephyr
# mppt-2420-hpx-v0.1-zephyr
# mppt-1210-hus-v0.2
# mppt-1210-hus-v0.4
@@ -78,6 +79,17 @@ board = nucleo_f072rb
build_flags = ${env.build_flags}
-D CONFIG_BOARD_MPPT_2420_LC_0V10
[env:mppt-2420-lc-v0.10-zephyr]
board = mppt_2420_lc_0v10
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
# https://github.com/LibreSolar/MPPT-1210-HUS/tree/586626f3d8
[env:mppt-1210-hus-v0.2]
board = nucleo_f072rb
+9 -1
View File
@@ -20,6 +20,12 @@
#include <stm32l0xx_ll_dac.h>
#include <stm32l0xx_ll_dma.h>
#include <stm32l0xx_ll_bus.h>
#elif defined(CONFIG_SOC_SERIES_STM32F0X)
#include <stm32f0xx_ll_system.h>
#include <stm32f0xx_ll_adc.h>
#include <stm32f0xx_ll_dac.h>
#include <stm32f0xx_ll_dma.h>
#include <stm32f0xx_ll_bus.h>
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
#include <stm32g4xx_ll_system.h>
#include <stm32g4xx_ll_dac.h>
@@ -99,7 +105,9 @@ static void adc_setup()
struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1,
.reference = ADC_REF_INTERNAL,
#if defined(CONFIG_SOC_SERIES_STM32F0X) || defined(CONFIG_SOC_SERIES_STM32L0X)
#if defined(CONFIG_SOC_SERIES_STM32F0X)
.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 240),
#elif defined(CONFIG_SOC_SERIES_STM32L0X)
.acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 161),
#elif defined(CONFIG_SOC_SERIES_STM32G4X)
// ToDo: channel-specific acquisition time. Only internal reference voltage
+1 -1
View File
@@ -63,7 +63,7 @@ uint32_t _calc_crc(const uint8_t *buf, size_t len)
#endif // UNIT_TEST
#if defined(EEPROM_24AA01) || defined(EEPROM_24AA32)
#if (defined(EEPROM_24AA01) || defined(EEPROM_24AA32)) && defined(__MBED__)
#ifdef EEPROM_24AA01
#define EEPROM_PAGE_SIZE 8 // see datasheet of 24AA01
+14 -1
View File
@@ -15,6 +15,12 @@
#include <math.h>
#include <stdio.h>
#if defined(__ZEPHYR__)
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#endif
#include "main.h"
#include "pcb.h"
#include "oled_ssd1306.h"
@@ -59,11 +65,18 @@ OledSSD1306 oled(i2c_dev);
void ExtOled::enable()
{
#ifdef PIN_UEXT_DIS
#if defined(PIN_UEXT_DIS) && defined(__MBED__)
DigitalOut uext_dis(PIN_UEXT_DIS);
uext_dis = 0;
#endif
#if defined(DT_SWITCH_UEXT_DIS_GPIOS_CONTROLLER) && defined(__ZEPHYR__)
struct device *dev_uext_dis =
device_get_binding(DT_SWITCH_UEXT_DIS_GPIOS_CONTROLLER);
gpio_pin_configure(dev_uext_dis, DT_SWITCH_UEXT_DIS_GPIOS_PIN, GPIO_DIR_OUT);
gpio_pin_write(dev_uext_dis, DT_SWITCH_UEXT_DIS_GPIOS_PIN, 0);
#endif
#ifdef OLED_BRIGHTNESS
oled.init(OLED_BRIGHTNESS);
#else
+2 -2
View File
@@ -14,7 +14,7 @@
#define STM32L073
#endif
#ifdef CONFIG_SOC_STM32F072XX
#ifdef CONFIG_SOC_STM32F072XB
#define STM32F0
#define STM32F072
#endif
@@ -29,7 +29,7 @@
#endif
#ifdef STM32F072
#include "stm32f072xx.h"
#include "stm32f072xb.h"
#endif
#ifdef STM32G431
+13 -1
View File
@@ -10,7 +10,11 @@
#define DEVICE_TYPE "MPPT-2420-LC"
#define HARDWARE_VERSION "v0.10"
#ifdef __MBED__
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#endif
// specify features of charge controller
#define CONFIG_HAS_DCDC_CONVERTER 1
@@ -71,11 +75,19 @@ enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT };
// LED pins and pin state configuration to switch above LEDs on
#define NUM_LED_PINS 2
#ifdef __MBED__
static const PinName led_pins[NUM_LED_PINS] = {
// PWR LOAD
PB_14, PB_15
};
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 }, // LED1
{ PIN_LOW, PIN_HIGH } // LED2
};
+4 -3
View File
@@ -1,8 +1,8 @@
# direct printf calls to console
CONFIG_STDOUT_CONSOLE=y
# default is 1024
CONFIG_HEAP_MEM_POOL_SIZE=1024
# default is 1024, but we need just a few bytes for ExtManager
CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_GPIO=y
CONFIG_SERIAL=y
@@ -12,7 +12,8 @@ CONFIG_I2C_1=y
CONFIG_ADC=y
CONFIG_ADC_1=y
CONFIG_LOG=y
# disable log by default to save memory for STM32F0 with little RAM
CONFIG_LOG=n
#CONFIG_NEWLIB_LIBC_NANO=y
CONFIG_NEWLIB_LIBC=y