Commit 7a02c5f6 authored by Clément Foucher's avatar Clément Foucher
Browse files

Create a custom board for OwnTech Power Converter.

Align device tree defines to ***_DEVICE nomenclature.
parent 65b24af4
......@@ -10,6 +10,7 @@
default_envs = owntech_power_converter
extra_configs = src/owntech.ini
boards_dir = zephyr/boards
#### COMMON ENVIRONMENT DEFINITIONS ###########################################
......@@ -35,10 +36,8 @@ extra_scripts = zephyr/platformio-extra.py
#### BOARD-SPECIFIC DEFINITIONS ###############################################
[env:owntech_power_converter]
[env:nucleo_g474re]
board = nucleo_g474re
# Supported upload protocols: mbed, stlink, jlink
upload_protocol = stlink
debug_tool = stlink
[env:owntech_power_converter]
board = owntech_board
......@@ -16,6 +16,9 @@ SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules)
# Append found modules to zephyr extra modules variable
list(APPEND ZEPHYR_EXTRA_MODULES ${SUBDIRS})
# Board
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
# Configure Zephyr
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
......
# OwnTech board configuration
config BOARD_OWNTECH_BOARD
bool "OwnTech Power Converter board"
depends on SOC_STM32G474XX
# OwnTech board configuration
if BOARD_OWNTECH_BOARD
config BOARD
default "owntech_board"
config SPI_STM32_INTERRUPT
default y
depends on SPI
endif # BOARD_OWNTECH_BOARD
# SPDX-License-Identifier: Apache-2.0
# use target=stm32g474rbtx instead of stm32g474retx
# to allow board re-flashing (see PR #23230)
board_runner_args(pyocd "--target=stm32g474rbtx")
include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
/ {
ngnd-switch {
ngnd: ngnd-switch {
compatible = "ngnd-switch";
ngnd_pin: ngnd-gpio-pin {
label = "NGND";
ngnd-gpio-pin {
ngnd-gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>;
label = "Neutral to GND shunt";
};
};
aliases {
ngnd = &ngnd_pin;
};
};
\ No newline at end of file
/*
* The first part of this file is based on Nucleo G474RE dts original file.
* All changes from the originl file are indicated with comments "Edited".
*
* Copyright (c) 2019 STMicroelectronics.
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/g4/stm32g474Xe.dtsi>
#include <st/g4/stm32g474r(b-c-e)tx-pinctrl.dtsi>
/ {
// Edited for OwnTech Power Converter board:
model = "OwnTech Power Converter board";
compatible = "owntech,owntech-board", "st,stm32g474re-nucleo";
chosen {
zephyr,console = &lpuart1;
zephyr,shell-uart = &lpuart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,can-primary = &can1;
};
leds {
compatible = "gpio-leds";
green_led: led_0 {
gpios = <&gpioa 5 GPIO_ACTIVE_HIGH>;
label = "User LD2";
};
};
pwmleds {
compatible = "pwm-leds";
green_pwm_led: green_pwm_led {
pwms = <&pwm2 1 4 PWM_POLARITY_NORMAL>;
};
};
gpio_keys {
compatible = "gpio-keys";
user_button: button {
label = "User";
gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
};
};
aliases {
led0 = &green_led;
pwm-led0 = &green_pwm_led;
sw0 = &user_button;
};
};
&clk_hse {
clock-frequency = <DT_FREQ_M(24)>;
status = "okay";
};
&pll {
div-m = <6>;
mul-n = <85>;
div-p = <7>;
div-q = <2>;
div-r = <2>;
clocks = <&clk_hse>;
status = "okay";
};
&rcc {
clocks = <&pll>;
clock-frequency = <DT_FREQ_M(170)>;
ahb-prescaler = <1>;
apb1-prescaler = <1>;
apb2-prescaler = <1>;
};
// Edited for OwnTech Power Converter board:
// &usart1_rx_pc5 conflict with &adc2_in11_pc5
&usart1 {
pinctrl-0 = <&usart1_tx_pc4 &usart1_rx_pb7>;
current-speed = <115200>;
status = "okay";
};
&lpuart1 {
pinctrl-0 = <&lpuart1_tx_pa2 &lpuart1_rx_pa3>;
current-speed = <115200>;
status = "okay";
};
// Edited for OwnTech Power Converter board:
// &i2c1_scl_pb8 &i2c1_sda_pb9 will conflict with can1
&i2c1 {
status = "disabled";
};
// Edited for OwnTech Power Converter board:
// &spi1_miso_pa6 &spi1_mosi_pa7 conflict with &adc2_in3_pa6 &adc2_in4_pa7
&spi1 {
status = "disabled";
};
// Edited for OwnTech Power Converter board:
// &spi2_nss_pb12 conflict with $fdcan2_rx_pb12, &spi2_nss_pc6 AF does not exist
&spi2 {
status = "disabled";
};
// Edited for OwnTech Power Converter board:
// &spi3_nss_pa15 &spi3_miso_pc11 &spi3_mosi_pc12 conflict with hrtim
&spi3 {
pinctrl-0 = <&spi3_nss_pa4 &spi3_sck_pc10 &spi3_miso_pb4 &spi3_mosi_pb5>;
status = "okay";
};
&timers2 {
status = "okay";
pwm2: pwm {
status = "okay";
pinctrl-0 = <&tim2_ch1_pa5>;
};
};
&rtc {
status = "okay";
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Set 2Kb of storage at the end of the 128Kb of flash */
storage_partition: partition@1f800 {
label = "storage";
reg = <0x0001f800 0x00000800>;
};
};
};
&iwdg {
status = "okay";
};
&rng {
status = "okay";
};
// Edited for OwnTech Power Converter board
&adc1 {
pinctrl-0 = <&adc1_in6_pc0 &adc1_in7_pc1 &adc1_in8_pc2 &adc1_in9_pc3>;
status = "okay";
};
&can1 {
pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>;
bus-speed = <125000>;
sjw = <1>;
sample-point = <875>;
bus-speed-data = <1000000>;
sjw-data = <1>;
sample-point-data = <875>;
status = "okay";
};
/*
* The following part is addition to the original Nucleo device tree file.
*
* Copyright (c) 2022 OwnTech.
*/
#include "dts/pinout.dtsi"
#include "dts/hrtim.dtsi"
#include "dts/adc-channels.dtsi"
#include "dts/ngnd.dtsi"
/*********/
/* Timer */
/*********/
&timers4 {
pinctrl-0 = <&tim4_etr_pb3 &tim4_ch1_pb6 &tim4_ch2_pb7 >;
status = "okay";
};
&timers6 {
status = "okay";
};
&timers7 {
status = "okay";
};
/*******/
/* DMA */
/*******/
&dma1 {
status = "okay";
};
&dmamux1 {
status = "okay";
};
/*******/
/* ADC */
/*******/
&adc2 {
pinctrl-0 = <&adc2_in1_pa0 &adc2_in2_pa1 &adc2_in3_pa6>;
status = "okay";
};
/*
&adc3 {
pinctrl-0 = <&adc3_in1_pb1 >;
status = "okay";
};
*/
/*******/
/* DAC */
/*******/
&dac1 {
status = "okay";
};
&dac2 {
status = "okay";
};
&dac3 {
status = "okay";
};
/********/
/* NGND */
/********/
&ngnd {
status = "okay";
};
identifier: owntech_board
name: OwnTech Board
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 128
flash: 512
supported:
- arduino_gpio
- arduino_i2c
- arduino_spi
- nvs
- pwm
- i2c
- gpio
- usb device
- counter
- spi
- watchdog
- adc
- dma
- can
- canfd
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32G4X=y
CONFIG_SOC_STM32G474XX=y
# enable uart driver
CONFIG_SERIAL=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# Enable Clocks
CONFIG_CLOCK_CONTROL=y
# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
# Enable MPU
CONFIG_ARM_MPU=y
# Enable HW stack protection
CONFIG_HW_STACK_PROTECTION=y
......@@ -6,37 +6,38 @@
"f_cpu": "170000000L",
"mcu": "stm32g474ret6",
"product_line": "STM32G474xx",
"variant": "NUCLEO_G474RE"
"variant": "STM32G4xx/G473R(B-C-E)T_G474R(B-C-E)T_G483RET_G484RET"
},
"connectivity": [
"can"
],
"debug": {
"jlink_device": "STM32G474RE",
"openocd_target": "stm32g4x",
"svd_path": "STM32G474xx.svd"
"default_tools": [
"stlink"
],
"jlink_device": "STM32G474RE",
"onboard_tools": [
"stlink"
],
"openocd_target": "stm32g4x",
"svd_path": "STM32G474xx.svd"
},
"frameworks": [
"arduino",
"cmsis",
"mbed",
"libopencm3",
"stm32cube",
"zephyr"
],
"name": "Nucleo G474RE",
"name": "OwnTech Board",
"upload": {
"maximum_ram_size": 131072,
"maximum_size": 524288,
"protocol": "mbed",
"protocol": "stlink",
"protocols": [
"jlink",
"stlink",
"cmsis-dap",
"blackmagic",
"mbed"
]
"stlink",
"jlink",
"cmsis-dap",
"blackmagic",
"mbed"
]
},
"url": "https://www.st.com/en/evaluation-tools/nucleo-g474re.html",
"vendor": "ST"
"url": "https://www.owntech.org",
"vendor": "OwnTech"
}
This folder is shared between Zephyr and PlatformIO.
While embedding PlatformIO content in Zephyr directory may be troubling, this choice has been made in order to reduce the number of directories at the root of the project, reducing the complexity of the project for the end-user.
- As per location (within `Zephyr` folder), this is the default board directory for Zephyr OS, which will use its sub-directory `arm/owntech_board`.
- As per `boards_dir` variable defined in `platformio.ini`, this is the board directory for PlatformIO, which will use its file `owntech_board.json`.
Help links:
- [PlatformIO Custom Boards](https://docs.platformio.org/en/latest/platforms/creating_board.html)
- [Zephyr OS Board Porting Guide](https://docs.zephyrproject.org/latest/guides/porting/board_porting.html)
- [Zephyr OS Application Development Custom Board](https://docs.zephyrproject.org/latest/application/index.html#custom-board-definition)
......@@ -34,6 +34,15 @@ extern "C" {
#endif
/////
// Public devices names
#define DAC1_DEVICE DT_LABEL(DT_NODELABEL(dac1))
#define DAC2_DEVICE DT_LABEL(DT_NODELABEL(dac2))
#define DAC3_DEVICE DT_LABEL(DT_NODELABEL(dac3))
/////
// Configuration types
typedef enum
......@@ -60,6 +69,7 @@ typedef struct
} dac_pin_config_t;
/////
// API
typedef void (*dac_api_setconstvalue) (const struct device* dev, uint8_t channel, uint32_t value);
......@@ -133,10 +143,6 @@ static inline void dac_stop(const struct device* dev, uint8_t channel)
/////
// Owntech-specific config
#define DAC1_LABEL DT_PROP(DT_NODELABEL(dac1), label)
#define DAC2_LABEL DT_PROP(DT_NODELABEL(dac2), label)
#define DAC3_LABEL DT_PROP(DT_NODELABEL(dac3), label)
void owntech_dac_dac2_constant_init();
void owntech_dac_dac1_dac3_current_mode_init();
......
......@@ -36,7 +36,7 @@
// Write a driver to load on startup without user action?
void owntech_dac_dac2_constant_init()
{
const struct device* dac2 = device_get_binding(DAC2_LABEL);
const struct device* dac2 = device_get_binding(DAC2_DEVICE);
dac_pin_config_t pin_config =
{
......@@ -51,8 +51,8 @@ void owntech_dac_dac2_constant_init()
void owntech_dac_dac1_dac3_current_mode_init()
{
const struct device* dac1 = device_get_binding(DAC1_LABEL);
const struct device* dac3 = device_get_binding(DAC3_LABEL);
const struct device* dac1 = device_get_binding(DAC1_DEVICE);
const struct device* dac3 = device_get_binding(DAC3_DEVICE);
dac_function_config_t function_config =
{
......
......@@ -232,7 +232,7 @@ static void dac_stm32_stop(const struct device* dev, uint8_t channel)
// Device definitions
// DAC 1
#if DT_NODE_HAS_STATUS(DAC1_NODELABEL, okay)
#if DT_NODE_HAS_STATUS(DAC1_NODE, okay)
struct stm32_dac_driver_data dac1_data =
{
......@@ -241,7 +241,7 @@ struct stm32_dac_driver_data dac1_data =
.started = {0, 0}
};
DEVICE_DT_DEFINE(DAC1_NODELABEL,
DEVICE_DT_DEFINE(DAC1_NODE,
dac_stm32_init,
NULL,
&dac1_data,
......@@ -254,7 +254,7 @@ DEVICE_DT_DEFINE(DAC1_NODELABEL,
#endif // DAC 1
// DAC 2
#if DT_NODE_HAS_STATUS(DAC2_NODELABEL, okay)
#if DT_NODE_HAS_STATUS(DAC2_NODE, okay)
struct stm32_dac_driver_data dac2_data =
{
......@@ -263,7 +263,7 @@ struct stm32_dac_driver_data dac2_data =
.started = {0, 0}
};
DEVICE_DT_DEFINE(DAC2_NODELABEL,
DEVICE_DT_DEFINE(DAC2_NODE,
dac_stm32_init,
NULL,
&dac2_data,
......@@ -276,7 +276,7 @@ DEVICE_DT_DEFINE(DAC2_NODELABEL,
#endif // DAC 2
// DAC 3
#if DT_NODE_HAS_STATUS(DAC3_NODELABEL, okay)
#if DT_NODE_HAS_STATUS(DAC3_NODE, okay)
struct stm32_dac_driver_data dac3_data =
{
......@@ -285,7 +285,7 @@ struct stm32_dac_driver_data dac3_data =
.started = {0, 0}
};
DEVICE_DT_DEFINE(DAC3_NODELABEL,
DEVICE_DT_DEFINE(DAC3_NODE,
dac_stm32_init,
NULL,
&dac3_data,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment