diff --git a/boards/arm/arduino_portenta_h7/CMakeLists.txt b/boards/arm/arduino_portenta_h7/CMakeLists.txt new file mode 100644 index 0000000000000..6aaa80fcf41d7 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2022 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_BOARD_ARDUINO_PORTENTA_H7_M7) + +zephyr_library() +zephyr_library_sources(board.c) + +endif() diff --git a/boards/arm/arduino_portenta_h7/Kconfig.board b/boards/arm/arduino_portenta_h7/Kconfig.board new file mode 100644 index 0000000000000..75e401c5d4b65 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/Kconfig.board @@ -0,0 +1,14 @@ +# Arduino Portenta H7 board configuration + +# Copyright (c) 2022 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_ARDUINO_PORTENTA_H7_M7 + bool "Arduino Portenta H7 Board" + depends on SOC_STM32H747XX + select CPU_CORTEX_M7 + +config BOARD_ARDUINO_PORTENTA_H7_M4 + bool "Arduino Portenta H7 Board" + depends on SOC_STM32H747XX + select CPU_CORTEX_M4 diff --git a/boards/arm/arduino_portenta_h7/Kconfig.defconfig b/boards/arm/arduino_portenta_h7/Kconfig.defconfig new file mode 100644 index 0000000000000..4b7847cce059c --- /dev/null +++ b/boards/arm/arduino_portenta_h7/Kconfig.defconfig @@ -0,0 +1,15 @@ +# Arduino Portenta H7 board configuration + +# Copyright (c) 2022 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_ARDUINO_PORTENTA_H7_M7 || BOARD_ARDUINO_PORTENTA_H7_M4 + +config BOARD + default "arduino_portenta_h7_m7" if BOARD_ARDUINO_PORTENTA_H7_M7 + default "arduino_portenta_h7_m4" if BOARD_ARDUINO_PORTENTA_H7_M4 + +config STM32H7_DUAL_CORE + default y + +endif # BOARD_ARDUINO_PORTENTA_H7_M7 || BOARD_ARDUINO_PORTENTA_H7_M4 diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7-common.dtsi b/boards/arm/arduino_portenta_h7/arduino_portenta_h7-common.dtsi new file mode 100644 index 0000000000000..e8630e6bc0520 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7-common.dtsi @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + leds { + compatible = "gpio-leds"; + red_led: led_0 { + gpios = <&gpiok 5 GPIO_ACTIVE_LOW>; + }; + green_led: led_1 { + gpios = <&gpiok 6 GPIO_ACTIVE_LOW>; + }; + blue_led: led_2 { + gpios = <&gpiok 7 GPIO_ACTIVE_LOW>; + }; + }; + + aliases { + led0 = &red_led; + led1 = &green_led; + led2 = &blue_led; + }; +}; + +&rcc { + d1cpre = <1>; + hpre = <1>; + d1ppre = <1>; + d2ppre1 = <1>; + d2ppre2 = <2>; + d3ppre = <1>; +}; + +/* UART0 in datasheet */ +&uart4 { + pinctrl-0 = <&uart4_tx_pa0 &uart4_rx_pi9>; + pinctrl-names = "default"; + current-speed = <115200>; +}; + +/* UART1 in datasheet */ +&usart1 { + pinctrl-0 = <&usart1_tx_pa9 &usart1_rx_pa10>; + pinctrl-names = "default"; + current-speed = <115200>; +}; + +/* UART2 in datasheet */ +&usart6 { + pinctrl-0 = <&usart6_tx_pg14 &usart6_rx_pg9>; + pinctrl-names = "default"; + current-speed = <115200>; +}; + +/* UART3 in datasheet */ +&uart8 { + pinctrl-0 = <&uart8_tx_pj8 &uart8_rx_pj9>; + pinctrl-names = "default"; + current-speed = <115200>; +}; + +/* I2C0 in datasheet */ +&i2c3 { + pinctrl-0 = <&i2c3_scl_ph7 &i2c3_sda_ph8>; + pinctrl-names = "default"; + clock-frequency = ; +}; + +/* I2C1 in datasheet */ +&i2c1 { + pinctrl-0 = <&i2c1_scl_pb6 &i2c1_sda_pb7>; + pinctrl-names = "default"; + clock-frequency = ; +}; + +/* I2C2 in datasheet */ +&i2c4 { + pinctrl-0 = <&i2c4_scl_ph11 &i2c4_sda_ph12>; + pinctrl-names = "default"; + clock-frequency = ; +}; + +/* I2C3 in datasheet */ +&i2c3 { + pinctrl-0 = <&i2c3_scl_ph7 &i2c3_sda_ph8>; + pinctrl-names = "default"; + clock-frequency = ; +}; + +/* SPI1 in datasheet */ +&spi2 { + pinctrl-0 = <&spi2_nss_pi0 &spi2_sck_pi1 + &spi2_miso_pc2 &spi2_mosi_pc3>; + pinctrl-names = "default"; +}; + +&can1 { + pinctrl-0 = <&fdcan1_rx_pb8 &fdcan1_tx_ph13>; + pinctrl-names = "default"; +}; + +&rtc { + status = "okay"; +}; + +zephyr_udc0: &usbotg_fs { + pinctrl-0 = <&usb_otg_fs_dm_pa11 &usb_otg_fs_dp_pa12>; + pinctrl-names = "default"; + status = "disabled"; +}; diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.dts b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.dts new file mode 100644 index 0000000000000..e214fbdecd4d4 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.dts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include +#include "arduino_portenta_h7-common.dtsi" + +/ { + model = "Arduino Portenta H7 board"; + compatible = "arduino,portenta-h7"; + + /* HW resources are split between CM7 and CM4 */ + + chosen { + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + zephyr,sram = &sram1; + zephyr,flash = &flash1; + }; +}; + +&rcc { + clock-frequency = ; +}; + +&usart1 { + status = "disabled"; +}; diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.yaml b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.yaml new file mode 100644 index 0000000000000..aa685f97db1b8 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4.yaml @@ -0,0 +1,16 @@ +identifier: arduino_portenta_h7_m4 +name: Arduino Portenta H7 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 288 +flash: 1024 +supported: + - gpio +testing: + ignore_tags: + - mpu + - nfc diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4_defconfig b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4_defconfig new file mode 100644 index 0000000000000..bb6c8c9995139 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m4_defconfig @@ -0,0 +1,30 @@ +# Copyright (c) 2022 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_STM32H7X=y +CONFIG_SOC_STM32H747XX=y + +# Board config should be specified since there are 2 possible targets +CONFIG_BOARD_ARDUINO_PORTENTA_H7_M4=y + +# Enable GPIO +CONFIG_GPIO=y + +# Clock configuration +CONFIG_CLOCK_CONTROL=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable HW stack protection +CONFIG_HW_STACK_PROTECTION=y + +# Enable pin controller +CONFIG_PINCTRL=y + +# Enable uart driver +# CONFIG_SERIAL=y + +# By default CONSOLE is assigned to m7 +# CONFIG_CONSOLE=y +# CONFIG_UART_CONSOLE=y diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.dts b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.dts new file mode 100644 index 0000000000000..30d717c39dd2a --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.dts @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/dts-v1/; +#include +#include +#include "arduino_portenta_h7-common.dtsi" + +/ { + model = "Arduino Portenta H7 board"; + compatible = "arduino,portenta-h7"; + + /* HW resources are split between CM7 and CM4 */ + chosen { + zephyr,console = &usart1; + zephyr,shell-uart = &usart1; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &code_partition; + }; + + oscen: oscen { + compatible = "regulator-fixed-sync", "regulator-fixed"; + regulator-name = "oscen"; + enable-gpios = <&gpioh 1 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; +}; + +&clk_hsi { + hsi-div = <8>; + status = "okay"; +}; + +&pll { + div-m = <1>; + mul-n = <24>; + div-p = <2>; + div-q = <4>; + div-r = <2>; + clocks = <&clk_hsi>; + status = "okay"; +}; + +&rcc { + clocks = <&pll>; + clock-frequency = ; +}; + + +&usart1 { + status = "okay"; +}; + +&i2c1 { + status = "okay"; +}; + +&usbotg_fs { + status = "okay"; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "bootloader"; + reg = <0x0 0x00040000>; + read-only; + }; + + code_partition: partition@40000 { + label = "code"; + reg = <0x40000 0x000c0000>; + read-only; + }; + + /* + * The flash starting at 0x000f8000 and ending at + * 0x000fffff is reserved for use by the application. + * + * Storage partition will be used by FCB/LittleFS/NVS + * if enabled. + */ + storage_partition: partition@f8000 { + label = "storage"; + reg = <0x000f8000 0x00008000>; + }; + }; +}; diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.yaml b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.yaml new file mode 100644 index 0000000000000..4f166911d1ad4 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7.yaml @@ -0,0 +1,12 @@ +identifier: arduino_portenta_h7_m7 +name: Arduino Portenta H7 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 512 +flash: 1024 +supported: + - gpio diff --git a/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7_defconfig b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7_defconfig new file mode 100644 index 0000000000000..f7e1a108631ce --- /dev/null +++ b/boards/arm/arduino_portenta_h7/arduino_portenta_h7_m7_defconfig @@ -0,0 +1,42 @@ +# Copyright (c) 2022 Benjamin Björnsson . +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_STM32H7X=y +CONFIG_SOC_STM32H747XX=y + +# Board config should be specified since there are 2 possible targets +CONFIG_BOARD_ARDUINO_PORTENTA_H7_M7=y + +# Enable the internal SMPS regulator +CONFIG_POWER_SUPPLY_DIRECT_SMPS=y + +# Enable GPIO +CONFIG_GPIO=y + +# Enable clocks +CONFIG_CLOCK_CONTROL=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable HW stack protection +CONFIG_HW_STACK_PROTECTION=y + +# enable pin controller +CONFIG_PINCTRL=y + +# Use zephyr,code-partition as flash offset +CONFIG_USE_DT_CODE_PARTITION=y + +# Disable following to assign serial ports to m4 core + +# Enable uart driver +CONFIG_SERIAL=y + +# Enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# Enable regulator +CONFIG_REGULATOR=y +CONFIG_REGULATOR_FIXED=y diff --git a/boards/arm/arduino_portenta_h7/board.c b/boards/arm/arduino_portenta_h7/board.c new file mode 100644 index 0000000000000..3cef340c16501 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/board.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Benjamin Björnsson . + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +static int board_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + /* Set led1 inactive since the Arduino bootloader leaves it active */ + const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios); + + if (!device_is_ready(led1.port)) { + return -ENODEV; + } + + return gpio_pin_configure_dt(&led1, GPIO_OUTPUT_INACTIVE); +} + +SYS_INIT(board_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); diff --git a/boards/arm/arduino_portenta_h7/board.cmake b/boards/arm/arduino_portenta_h7/board.cmake new file mode 100644 index 0000000000000..fe5f1c85220d3 --- /dev/null +++ b/boards/arm/arduino_portenta_h7/board.cmake @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_runner_args(dfu-util "--pid=2341:035b" "--alt=0" "--dfuse") + +include(${ZEPHYR_BASE}/boards/common/dfu-util.board.cmake) diff --git a/boards/arm/arduino_portenta_h7/doc/img/arduino_portenta_h7.jpeg b/boards/arm/arduino_portenta_h7/doc/img/arduino_portenta_h7.jpeg new file mode 100644 index 0000000000000..7218abdf1ce85 Binary files /dev/null and b/boards/arm/arduino_portenta_h7/doc/img/arduino_portenta_h7.jpeg differ diff --git a/boards/arm/arduino_portenta_h7/doc/index.rst b/boards/arm/arduino_portenta_h7/doc/index.rst new file mode 100644 index 0000000000000..9b0543c3d07ee --- /dev/null +++ b/boards/arm/arduino_portenta_h7/doc/index.rst @@ -0,0 +1,144 @@ +.. _arduino_portenta_h7_board: + +Arduino Portenta H7 +####################### + +Overview +******** + +The Portenta H7 enables a wide diversity of applications taking benefit +from Computer Vision, PLCs, Robotics controller, High-end industrial machinery +and high-speed booting computation (ms). + +The board includes an STM32H747XI SoC with a high-performance DSP, Arm Cortex-M7 + Cortex-M4 MCU, +with 2MBytes of Flash memory, 1MB RAM, 480 MHz CPU, Art Accelerator, L1 cache, external memory interface, +large set of peripherals, SMPS, and MIPI-DSI. + +Additionally, the board features: +- USB OTG FS +- 3 color user LEDs + +.. image:: img/arduino_portenta_h7.jpeg + :width: 500px + :align: center + :height: 325px + :alt: ARDUINO_PORTENTA_H7 + +More information about the board can be found at the `ARDUINO_PORTENTA_H7 website`_. +More information about STM32H747XIH6 can be found here: + +- `STM32H747XI on www.st.com`_ +- `STM32H747xx reference manual`_ +- `STM32H747xx datasheet`_ + +Supported Features +================== + +The current Zephyr arduino_portenta_h7 board configuration supports the following hardware features: + ++-----------+------------+-------------------------------------+ +| Interface | Controller | Driver/Component | ++===========+============+=====================================+ +| NVIC | on-chip | nested vector interrupt controller | ++-----------+------------+-------------------------------------+ +| UART | on-chip | serial port-polling; | +| | | serial port-interrupt | ++-----------+------------+-------------------------------------+ +| PINMUX | on-chip | pinmux | ++-----------+------------+-------------------------------------+ +| GPIO | on-chip | gpio | ++-----------+------------+-------------------------------------+ +| FLASH | on-chip | flash memory | ++-----------+------------+-------------------------------------+ +| RNG | on-chip | True Random number generator | ++-----------+------------+-------------------------------------+ +| SPI | on-chip | spi | ++-----------+------------+-------------------------------------+ +| IPM | on-chip | virtual mailbox based on HSEM | ++-----------+------------+-------------------------------------+ + +Other hardware features are not yet supported on Zephyr porting. + +Resources sharing +================= + +The dual core nature of STM32H747 SoC requires sharing HW resources between the +two cores. This is done in 3 ways: + +- **Compilation**: Clock configuration is only accessible to M7 core. M4 core only + has access to bus clock activation and deactivation. +- **Static pre-compilation assignment**: Peripherals such as a UART are assigned in + devicetree before compilation. The user must ensure peripherals are not assigned + to both cores at the same time. +- **Run time protection**: Interrupt-controller and GPIO configurations could be + accessed by both cores at run time. Accesses are protected by a hardware semaphore + to avoid potential concurrent access issues. + +Building and Flashing +************************* + +Applications for the ``arduino_portenta_h7`` board should be built per core target, +using either ``arduino_portenta_h7_m7`` or ``arduino_portenta_h7_m4`` as the target. +See :ref:`build_an_application` for more information about application builds. + + +Flashing +======== + +Installing dfu-util +------------------- + +This board requires dfu-utils for flashing. It is recommended to use at least +v0.8 of `dfu-util`_. The package available in debian/ubuntu can be quite old, so you might +have to build dfu-util from source. + +Flashing an application to STM32H747I M7 Core +--------------------------------------------- + +First, connect the Arduino Portenta H7 board to your host computer using +the USB port to prepare it for flashing. Double tap the button to put the board +into the Arduino Bootloader mode. Then build and flash your application. + +Here is an example for the :ref:`hello_world` application. + +.. zephyr-app-commands:: + :zephyr-app: samples/hello_world + :board: arduino_portenta_h7_m7 + :goals: build flash + +Run a serial host program to connect with your board: + +code-block:: console + + $ minicom -D /dev/ttyACM0 + +You should see the following message on the console: + +.. code-block:: console + + Hello World! arduino_portenta_m7 + +Similarly, you can build and flash samples on the M4 target. For this, please +take care of the resource sharing (UART port used for console for instance). + +Here is an example for the :ref:`blinky-sample` application on M4 core. + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/blinky + :board: arduino_portenta_h7_m4 + :goals: build flash + +.. _ARDUINO_PORTENTA_H7 website: + https://docs.arduino.cc/hardware/portenta-h7 + +.. _STM32H747XI on www.st.com: + https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-high-performance-mcus/stm32h7-series/stm32h747-757/stm32h747xi.html + +.. _STM32H747xx reference manual: + http://www.st.com/resource/en/reference_manual/dm00176879.pdf + +.. _STM32H747xx datasheet: + https://www.st.com/resource/en/datasheet/stm32h747xi.pdf + +.. _dfu-util: + http://dfu-util.sourceforge.net/build.html diff --git a/dts/arm/st/h7/stm32h745.dtsi b/dts/arm/st/h7/stm32h745.dtsi index 7eefb64bf7e33..4236b135a3802 100644 --- a/dts/arm/st/h7/stm32h745.dtsi +++ b/dts/arm/st/h7/stm32h745.dtsi @@ -38,6 +38,19 @@ clocks = <&rcc STM32_CLOCK_BUS_APB3 0x00000008>; status = "disabled"; }; + + usbotg_fs: usb@40080000 { + compatible = "st,stm32-otgfs"; + reg = <0x40080000 0x40000>; + interrupts = <98 0>, <99 0>, <100 0>, <101 0>; + interrupt-names = "ep1_out", "ep1_in", "wkup", "otgfs"; + num-bidir-endpoints = <9>; + ram-size = <4096>; + maximum-speed = "full-speed"; + clocks = <&rcc STM32_CLOCK_BUS_AHB1 0x08000000>; + phys = <&otghs_fs_phy>; + status = "disabled"; + }; }; /* * The RAM memories placed here can be used by both cores M4/M7 @@ -78,4 +91,9 @@ compatible = "zephyr,memory-region", "mmio-sram"; zephyr,memory-region = "SRAM4"; }; + + otghs_fs_phy: otghs_fs_phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0>; + }; }; diff --git a/samples/drivers/flash_shell/sample.yaml b/samples/drivers/flash_shell/sample.yaml index 3f41e92c665c5..ee8eaba26607d 100644 --- a/samples/drivers/flash_shell/sample.yaml +++ b/samples/drivers/flash_shell/sample.yaml @@ -6,6 +6,6 @@ tests: sample.drivers.flash.shell: tags: flash shell filter: CONFIG_FLASH_HAS_DRIVER_ENABLED - platform_exclude: nucleo_h745zi_q_m4 stm32h747i_disco_m4 gd32f350r_eval + platform_exclude: nucleo_h745zi_q_m4 stm32h747i_disco_m4 gd32f350r_eval arduino_portenta_h7_m4 harness: keyboard min_ram: 12