From fc71934010a660782d9d80af97884aa5df2bacd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Fri, 5 Feb 2021 17:48:45 +0100 Subject: [PATCH] Add Nucleo G474RE board for testing purposes --- boards/arm/nucleo_g474re/Kconfig.board | 8 + boards/arm/nucleo_g474re/Kconfig.defconfig | 14 ++ boards/arm/nucleo_g474re/board.cmake | 10 + boards/arm/nucleo_g474re/nucleo_g474re.dts | 190 ++++++++++++++++++ boards/arm/nucleo_g474re/nucleo_g474re.yaml | 22 ++ .../arm/nucleo_g474re/nucleo_g474re_defconfig | 68 +++++++ boards/arm/nucleo_g474re/support/openocd.cfg | 7 + boards/nucleo_g474re.json | 42 ++++ platformio.ini | 4 + 9 files changed, 365 insertions(+) create mode 100644 boards/arm/nucleo_g474re/Kconfig.board create mode 100644 boards/arm/nucleo_g474re/Kconfig.defconfig create mode 100644 boards/arm/nucleo_g474re/board.cmake create mode 100644 boards/arm/nucleo_g474re/nucleo_g474re.dts create mode 100644 boards/arm/nucleo_g474re/nucleo_g474re.yaml create mode 100644 boards/arm/nucleo_g474re/nucleo_g474re_defconfig create mode 100644 boards/arm/nucleo_g474re/support/openocd.cfg create mode 100644 boards/nucleo_g474re.json diff --git a/boards/arm/nucleo_g474re/Kconfig.board b/boards/arm/nucleo_g474re/Kconfig.board new file mode 100644 index 0000000..157e93a --- /dev/null +++ b/boards/arm/nucleo_g474re/Kconfig.board @@ -0,0 +1,8 @@ +# STM32G474RE Nucleo board configuration + +# Copyright (c) 2019 STMicroelectronics. +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_NUCLEO_G474RE + bool "Nucleo G474RE Development Board" + depends on SOC_STM32G474XX diff --git a/boards/arm/nucleo_g474re/Kconfig.defconfig b/boards/arm/nucleo_g474re/Kconfig.defconfig new file mode 100644 index 0000000..3deaa0c --- /dev/null +++ b/boards/arm/nucleo_g474re/Kconfig.defconfig @@ -0,0 +1,14 @@ +# STM32G474RE Nucleo board configuration + +# Copyright (c) 2019 STMicroelectronics. +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_NUCLEO_G474RE + +config BOARD + default "nucleo_g474re" + +config LIBRE_SOLAR_TYPE_ID + default 0 + +endif # BOARD_NUCLEO_G431RB diff --git a/boards/arm/nucleo_g474re/board.cmake b/boards/arm/nucleo_g474re/board.cmake new file mode 100644 index 0000000..2e5241a --- /dev/null +++ b/boards/arm/nucleo_g474re/board.cmake @@ -0,0 +1,10 @@ +# 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") + +board_runner_args(jlink "--device=STM32G474RE" "--speed=4000" "--reset-after-load") + +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) diff --git a/boards/arm/nucleo_g474re/nucleo_g474re.dts b/boards/arm/nucleo_g474re/nucleo_g474re.dts new file mode 100644 index 0000000..723612f --- /dev/null +++ b/boards/arm/nucleo_g474re/nucleo_g474re.dts @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2019 STMicroelectronics. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This is a dummy charge controller board for testing new features using the STM32G474 MCU + * + * IMPORTANT: You have to remove the VREF jumper on the Nucleo board to make it work. Otherwise + * the MCU will get stuck while trying to generate a reference voltage at VREF+ pin. + */ + +/dts-v1/; +#include +#include + +/ { + model = "STMicroelectronics STM32G474RE-NUCLEO board"; + compatible = "st,stm32g474re-nucleo"; + + pcb { + compatible = "charge-controller"; + + type = "Nucleo G474 dummy charge controller"; + version-str = "v0.1"; + version-num = <1>; + + hs-voltage-max = <80>; + ls-voltage-max = <32>; + dcdc-current-max = <20>; + }; + + chosen { + zephyr,console = &lpuart1; + zephyr,shell-uart = &lpuart1; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,can-primary = &can1; + }; + + leds { + compatible = "charlieplexing-leds"; + gpios = <&gpioa 5 GPIO_ACTIVE_HIGH>; + + pwr { + states = <1>; + }; + }; + + outputs { + compatible = "outputs"; + + can_en { + label = "CAN disable / standby"; + 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>; + }; + + 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 + }; + }; + + gpio_keys { + compatible = "gpio-keys"; + user_button: button { + label = "User"; + gpios = <&gpioc 13 GPIO_ACTIVE_LOW>; + }; + }; + + aliases { + sw0 = &user_button; + uart-dbg = &lpuart1; + uart-uext = &usart1; + spi-uext = &spi1; + i2c-uext = &i2c1; + }; +}; + +&usart1 { + pinctrl-0 = <&usart1_tx_pc4 &usart1_rx_pc5>; + current-speed = <115200>; + status = "okay"; +}; + +&lpuart1 { + pinctrl-0 = <&lpuart1_tx_pa2 &lpuart1_rx_pa3>; + current-speed = <115200>; + status = "okay"; +}; + +&i2c1 { + pinctrl-0 = <&i2c1_scl_pb8 &i2c1_sda_pb9>; + status = "okay"; +}; + +&spi1 { + pinctrl-0 = <&spi1_nss_pa4 &spi1_sck_pb3 + &spi1_miso_pa6 &spi1_mosi_pa7>; + status = "okay"; +}; + +&timers1 { + status = "okay"; + + halfbridge { + compatible = "half-bridge"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>; + frequency = <70000>; + deadtime = <300>; + }; +}; + +&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"; +}; + +&adc1 { + pinctrl-0 = <&adc1_in1_pa0>; + status = "okay"; +}; + +&can1 { + pinctrl-0 = <&fdcan1_rx_pa11 &fdcan1_tx_pa12>; + bus-speed = <250000>; + bus-speed-data = <250000>; + sjw = <1>; + sjw-data = <1>; + sample-point = <875>; + sample-point-data = <875>; + status = "okay"; +}; diff --git a/boards/arm/nucleo_g474re/nucleo_g474re.yaml b/boards/arm/nucleo_g474re/nucleo_g474re.yaml new file mode 100644 index 0000000..4aa6024 --- /dev/null +++ b/boards/arm/nucleo_g474re/nucleo_g474re.yaml @@ -0,0 +1,22 @@ +identifier: nucleo_g474re +name: ST Nucleo G474RE +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 128 +flash: 512 +supported: + - nvs + - pwm + - i2c + - gpio + - usb device + - counter + - spi + - watchdog + - adc + - can + - canfd diff --git a/boards/arm/nucleo_g474re/nucleo_g474re_defconfig b/boards/arm/nucleo_g474re/nucleo_g474re_defconfig new file mode 100644 index 0000000..86c82bf --- /dev/null +++ b/boards/arm/nucleo_g474re/nucleo_g474re_defconfig @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_STM32G4X=y +CONFIG_SOC_STM32G474XX=y + +# 170MHz system clock only in 'boost power' mode. +# RM0440, section 5.1.5 states that the R1MODE bit +# must be cleared before system can be 170MHz. +CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=170000000 + +# 150MHz system clock in 'normal power' mode +# CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=150000000 + +# enable uart driver +CONFIG_SERIAL=y + +# enable pinmux +CONFIG_PINMUX=y + +# enable GPIO +CONFIG_GPIO=y + +# clock configuration +CONFIG_CLOCK_CONTROL=y + +# Use PLLCLK for SYSCLK +CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y + +# Use HSE (24MHz) to feed into PLL +CONFIG_CLOCK_STM32_PLL_SRC_HSE=y +CONFIG_CLOCK_STM32_HSE_CLOCK=24000000 + +CONFIG_CLOCK_STM32_PLL_P_DIVISOR=7 +CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=2 +CONFIG_CLOCK_STM32_PLL_R_DIVISOR=2 + +# Produce 150MHz clock at PLLCLK output +# CONFIG_CLOCK_STM32_PLL_M_DIVISOR=4 +# CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=75 + +# Produce 170MHz clock at PLLCLK output +CONFIG_CLOCK_STM32_PLL_M_DIVISOR=6 +CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=85 + +# Produce Max (150MHz or 170MHz) HCLK +CONFIG_CLOCK_STM32_AHB_PRESCALER=1 + +# Produce Max (150MHz or 170MHz) APB1 clocks and APB2 clocks +CONFIG_CLOCK_STM32_APB1_PRESCALER=1 +CONFIG_CLOCK_STM32_APB2_PRESCALER=1 + +# Console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable HW stack protection +CONFIG_HW_STACK_PROTECTION=y + +CONFIG_CAN=y +CONFIG_THINGSET_CAN=y + +CONFIG_ISOTP=y +CONFIG_ISOTP_RX_BUF_COUNT=2 +CONFIG_ISOTP_RX_BUF_SIZE=100 +CONFIG_ISOTP_RX_SF_FF_BUF_COUNT=2 diff --git a/boards/arm/nucleo_g474re/support/openocd.cfg b/boards/arm/nucleo_g474re/support/openocd.cfg new file mode 100644 index 0000000..d936f7d --- /dev/null +++ b/boards/arm/nucleo_g474re/support/openocd.cfg @@ -0,0 +1,7 @@ +source [find interface/stlink.cfg] + +transport select hla_swd + +source [find target/stm32g4x.cfg] + +reset_config srst_only diff --git a/boards/nucleo_g474re.json b/boards/nucleo_g474re.json new file mode 100644 index 0000000..90012cd --- /dev/null +++ b/boards/nucleo_g474re.json @@ -0,0 +1,42 @@ +{ + "build": { + "core": "stm32", + "cpu": "cortex-m4", + "extra_flags": "-DSTM32G4xx -DSTM32G474xx", + "f_cpu": "170000000L", + "mcu": "stm32g474ret6", + "product_line": "STM32G474xx", + "variant": "NUCLEO_G474RE" + }, + "connectivity": [ + "can" + ], + "debug": { + "jlink_device": "STM32G474RE", + "openocd_target": "stm32g4x", + "svd_path": "STM32G474xx.svd" + }, + "frameworks": [ + "arduino", + "cmsis", + "mbed", + "libopencm3", + "stm32cube", + "zephyr" + ], + "name": "Nucleo G474RE", + "upload": { + "maximum_ram_size": 131072, + "maximum_size": 524288, + "protocol": "mbed", + "protocols": [ + "jlink", + "stlink", + "cmsis-dap", + "blackmagic", + "mbed" + ] + }, + "url": "https://www.st.com/en/evaluation-tools/nucleo-g474re.html", + "vendor": "ST" +} diff --git a/platformio.ini b/platformio.ini index 9d40fc4..2f0cfdb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -86,6 +86,10 @@ board = mppt_2420_hpx [env:pwm_2420_lus] board = pwm_2420_lus@0.3 +# Nucleo board for testing purposes +[env:nucleo_g474re] +board = nucleo_g474re + [env:unit_test] platform = native framework =