Zephyr: Added PWM 2420 LUS board
This commit is contained in:
@@ -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()
|
||||
@@ -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"
|
||||
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Martin Jäger / Libre Solar
|
||||
|
||||
config BOARD_PWM_2420_LUS_0V3
|
||||
bool "Libre Solar PWM 2420 LUS v0.3"
|
||||
depends on SOC_STM32L073XX
|
||||
@@ -0,0 +1,42 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Martin Jäger / Libre Solar
|
||||
|
||||
if BOARD_PWM_2420_LUS_0V3
|
||||
|
||||
config BOARD
|
||||
default "pwm_2420_lus_0v3"
|
||||
|
||||
config HAS_PWM_SWITCH
|
||||
default y
|
||||
|
||||
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_PWM_2420_LUS_0V3
|
||||
@@ -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)
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Ilya Tagunov <tagunil@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#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 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
|
||||
#define STM32L0_PINMUX_FUNC_PB6_I2C1_SCL \
|
||||
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
|
||||
#define STM32L0_PINMUX_FUNC_PB7_I2C1_SDA \
|
||||
(STM32_PINMUX_ALT_FUNC_1 | STM32_OPENDRAIN_PULLUP)
|
||||
|
||||
/* 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 */
|
||||
};
|
||||
|
||||
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_ALIAS_LED_A_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_B_GPIOS_CONTROLLER,
|
||||
DT_ALIAS_LED_C_GPIOS_CONTROLLER,
|
||||
};
|
||||
const int led_pins[CONFIG_NUM_LED_PINS] = {
|
||||
DT_ALIAS_LED_A_GPIOS_PIN,
|
||||
DT_ALIAS_LED_B_GPIOS_PIN,
|
||||
DT_ALIAS_LED_C_GPIOS_PIN,
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2019 Martin Jäger / Libre Solar
|
||||
*/
|
||||
|
||||
/dts-v1/;
|
||||
#include <st/l0/stm32l073Xz.dtsi>
|
||||
|
||||
/ {
|
||||
model = "Libre Solar PWM 2420 LUS v0.3";
|
||||
compatible = "st,stm32l073";
|
||||
|
||||
chosen {
|
||||
zephyr,console = &usart1;
|
||||
zephyr,shell-uart = &usart1;
|
||||
zephyr,sram = &sram0;
|
||||
zephyr,flash = &flash0;
|
||||
};
|
||||
|
||||
leds {
|
||||
compatible = "gpio-leds";
|
||||
led_pin_a: led_pin_a {
|
||||
gpios = <&gpiob 13 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin A";
|
||||
};
|
||||
led_pin_b: led_pin_b {
|
||||
gpios = <&gpiob 14 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin B";
|
||||
};
|
||||
led_pin_c: led_pin_c {
|
||||
gpios = <&gpiob 15 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "LED pin C";
|
||||
};
|
||||
// normal GPIO pins also configured as LEDs to be
|
||||
// able to assign aliases
|
||||
pin_load_dis: pin_load_dis {
|
||||
gpios = <&gpiob 2 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "Load disable";
|
||||
};
|
||||
pin_usb_pwr_dis: pin_usb_pwr_dis {
|
||||
gpios = <&gpiob 5 GPIO_INT_ACTIVE_HIGH>;
|
||||
label = "USB power disable";
|
||||
};
|
||||
};
|
||||
|
||||
aliases {
|
||||
led-a = &led_pin_a;
|
||||
led-b = &led_pin_b;
|
||||
led-c = &led_pin_c;
|
||||
|
||||
/* WARNING: this one is DISable and not ENable... change name
|
||||
and implement proper handling! */
|
||||
load-en = &pin_load_dis;
|
||||
usb-pwr-en = &pin_usb_pwr_dis;
|
||||
};
|
||||
};
|
||||
|
||||
&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";
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
identifier: pwm_2420_lus_0v3
|
||||
name: PWM-2420-LUS-0V3
|
||||
type: mcu
|
||||
arch: arm
|
||||
toolchain:
|
||||
- zephyr
|
||||
- gnuarmemb
|
||||
- xtools
|
||||
ram: 20
|
||||
flash: 192
|
||||
supported:
|
||||
- arduino_i2c
|
||||
- gpio
|
||||
- i2c
|
||||
- spi
|
||||
- watchdog
|
||||
- adc
|
||||
@@ -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
|
||||
@@ -0,0 +1,27 @@
|
||||
# This is an ST NUCLEO-L073RZ board with single STM32L073RZ chip.
|
||||
# http://www.st.com/en/evaluation-tools/nucleo-l073rz.html
|
||||
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
|
||||
}
|
||||
@@ -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": "PWM-2420-LUS"
|
||||
},
|
||||
"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 PWM 2420 LUS",
|
||||
"upload": {
|
||||
"maximum_ram_size": 20480,
|
||||
"maximum_size": 196608,
|
||||
"protocol": "stlink",
|
||||
"protocols": [
|
||||
"jlink",
|
||||
"stlink",
|
||||
"blackmagic",
|
||||
"mbed"
|
||||
]
|
||||
},
|
||||
"url": "http://libre.solar/",
|
||||
"vendor": "Libre Solar"
|
||||
}
|
||||
@@ -120,6 +120,17 @@ board = nucleo_l073rz
|
||||
build_flags = ${env.build_flags}
|
||||
-D CONFIG_BOARD_PWM_2420_LUS_0V3
|
||||
|
||||
[env:pwm-2420-lus-v0.3-zephyr]
|
||||
board = pwm_2420_lus_0v3
|
||||
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:pwm-2420-lus-v0.3-bl]
|
||||
board = nucleo_l073rz
|
||||
build_flags = ${env.build_flags}
|
||||
|
||||
+6
-2
@@ -13,11 +13,15 @@
|
||||
#include "device_status.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef __ZEPHYR__
|
||||
#include <stm32l0xx_ll_system.h>
|
||||
#endif
|
||||
|
||||
extern DeviceStatus dev_stat;
|
||||
|
||||
extern LoadOutput load; // necessary to call emergency stop function
|
||||
|
||||
#if defined(PIN_I_LOAD_COMP) && PIN_LOAD_DIS == PB_2
|
||||
#if defined(__MBED__) && defined(PIN_I_LOAD_COMP) && PIN_LOAD_DIS == PB_2
|
||||
static void lptim_init()
|
||||
{
|
||||
// Enable peripheral clock of GPIOB
|
||||
@@ -69,7 +73,7 @@ static void lptim_init()
|
||||
|
||||
static void short_circuit_comp_init()
|
||||
{
|
||||
#ifdef PIN_I_LOAD_COMP
|
||||
#if defined(__MBED__) && defined(PIN_I_LOAD_COMP)
|
||||
MBED_ASSERT(PIN_I_LOAD_COMP == PB_4);
|
||||
|
||||
// set GPIO pin to analog
|
||||
|
||||
@@ -69,7 +69,7 @@ static const PinName led_pins[NUM_LED_PINS] = {
|
||||
PB_14, PB_13, PB_2, PB_11, PB_10
|
||||
};
|
||||
#elif defined(__ZEPHYR__)
|
||||
// defined in boar definition pinmux.c
|
||||
// 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
|
||||
|
||||
+13
-2
@@ -7,6 +7,12 @@
|
||||
#ifndef PWM_2420_LUS_H
|
||||
#define PWM_2420_LUS_H
|
||||
|
||||
#ifdef __MBED__
|
||||
#include "mbed.h"
|
||||
#elif defined(__ZEPHYR__)
|
||||
#include <zephyr.h>
|
||||
#endif
|
||||
|
||||
#define DEVICE_TYPE "PWM-2420-LUS"
|
||||
|
||||
#ifdef CONFIG_BOARD_PWM_2420_LUS_0V2
|
||||
@@ -15,8 +21,6 @@
|
||||
#define HARDWARE_VERSION "v0.3"
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
// specify features of charge controller
|
||||
#define CONFIG_HAS_DCDC_CONVERTER 0
|
||||
#define CONFIG_HAS_PWM_SWITCH 1
|
||||
@@ -76,10 +80,17 @@ 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 3
|
||||
|
||||
#ifdef __MBED__
|
||||
static const PinName led_pins[NUM_LED_PINS] = {
|
||||
// A B C
|
||||
PB_13, PB_14, PB_15
|
||||
};
|
||||
#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
|
||||
|
||||
#ifndef LEDS_WRONG_POLARITY
|
||||
static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
|
||||
static bool _pwm_active;
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#if defined(__MBED__) && !defined(UNIT_TEST)
|
||||
|
||||
static int _pwm_resolution;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user