8000 stm32/boards: Add support for Arduino Portenta H7. · micropython/micropython@3fe61a5 · GitHub
[go: up one dir, main page]

Skip to 10000 content

Commit 3fe61a5

Browse files
committed
stm32/boards: Add support for Arduino Portenta H7.
1 parent d242a9b commit 3fe61a5

File tree

10 files changed

+977
-0
lines changed

10 files changed

+977
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Arduino SA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "storage.h"
28+
#include "qspi.h"
29+
30+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
31+
// Shared cache for first and second SPI block devices
32+
STATIC mp_spiflash_cache_t spi_bdev_cache;
33+
#endif
34+
35+
// First external SPI flash uses hardware QSPI interface
36+
const mp_spiflash_config_t spiflash_config = {
37+
.bus_kind = MP_SPIFLASH_BUS_QSPI,
38+
.bus.u_qspi.data = NULL,
39+
.bus.u_qspi.proto = &qspi_proto,
40+
#if MICROPY_HW_SPIFLASH_ENABLE_CACHE
41+
.cache = &spi_bdev_cache,
42+
#endif
43+
};
44+
45+
spi_bdev_t spi_bdev;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"deploy": [
3+
"./deploy.md"
4+
],
5+
"docs": "",
6+
"features": [
7+
"8MB SDRAM",
8+
"16MB Flash",
9+
"Dual-core processor",
10+
"USB High Speed Phy",
11+
"10/100 Ethernet Phy",
12+
"CYW43 WiFi/BT Module",
13+
"DisplayPort over USB-C",
14+
"2x80 pin HD connectors"
15+
],
16+
"images": [
17+
"ABX00042_01.iso_1000x750.jpg"
18+
],
19+
"mcu": "STM32H747",
20+
"product": "Arduino Portenta H7",
21+
"thumbnail": "",
22+
"url": "https://store.arduino.cc/products/portenta-h7",
23+
"vendor": "Arduino"
24+
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Arduino SA
< 3372 /td>7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <string.h>
28+
#include "py/mphal.h"
29+
#include "storage.h"
30+
#include "sdram.h"
31+
#include "eth.h"
32+
#if MICROPY_HW_USB_HS_ULPI3320
33+
#include "ulpi.h"
34+
#endif
35+
#define PORTENTA_PMIC_ERRATA (1)
36+
37+
void PORTENTA_board_startup(void) {
38+
39+
}
40+
41+
void PORTENTA_board_early_init(void) {
42+
43+
HAL_InitTick(0);
44+
45+
// Enable oscillator pin
46+
// This is enabled in the bootloader anyway.
47+
PORTENTA_board_osc_enable(true);
48+
49+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
50+
// The Arduino/mbed bootloader uses the MPU to protect sector 1
51+
// which is used for the flash filesystem. The following code
52+
// resets and disables all MPU regions configured in the bootloader.
53+
HAL_MPU_Disable();
54+
MPU_Region_InitTypeDef MPU_InitStruct;
55+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
56+
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
57+
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
58+
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
59+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
60+
MPU_InitStruct.SubRegionDisable = 0x00;
61+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
62+
63+
for (int i = MPU_REGION_NUMBER0; i < MPU_REGION_NUMBER15; i++) {
64+
MPU_InitStruct.Number = i;
65+
MPU_InitStruct.Enable = MPU_REGION_DISABLE;
66+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
67+
}
68+
#endif
69+
70+
#if PORTENTA_PMIC_ERRATA
71+
// PMIC SW1 current limit fix
72+
// Configure PMIC I2C GPIOs
73+
mp_hal_pin_config(pyb_pin_I2C1_SCL, MP_HAL_PIN_MODE_ALT_OPEN_DRAIN, MP_HAL_PIN_PULL_NONE, GPIO_AF4_I2C1);
74+
mp_hal_pin_config_speed(pyb_pin_I2C1_SCL, MP_HAL_PIN_SPEED_LOW);
75+
76+
mp_hal_pin_config(pyb_pin_I2C1_SDA, MP_HAL_PIN_MODE_ALT_OPEN_DRAIN, MP_HAL_PIN_PULL_NONE, GPIO_AF4_I2C1);
77+
mp_hal_pin_config_speed(pyb_pin_I2C1_SDA, MP_HAL_PIN_SPEED_LOW);
78+
79+
// Configure PMIC I2C
80+
I2C_HandleTypeDef i2c;
81+
i2c.Instance = I2C1;
82+
i2c.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
83+
i2c.Init.Timing = 0x20D09DE7;
84+
i2c.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
85+
i2c.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
86+
i2c.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
87+
i2c.Init.OwnAddress1 = 0xFE;
88+
i2c.Init.OwnAddress2 = 0xFE;
89+
i2c.Init.OwnAddress2Masks = 0;
90+
91+
__HAL_RCC_I2C1_CLK_ENABLE();
92+
__HAL_RCC_I2C1_FORCE_RESET();
93+
__HAL_RCC_I2C1_RELEASE_RESET();
94+
HAL_I2C_Init(&i2c);
95+
96+
// Set SW1 current limit to 1.5A
97+
// Fixes power glitches with Eth and SDRAM.
98+
uint8_t buf[] = {0x36, 0x02};
99+
HAL_I2C_Master_Transmit(&i2c, 0x08 << 1, buf, 2, 1000);
100+
101+
HAL_I2C_DeInit(&i2c);
102+
__HAL_RCC_I2C1_FORCE_RESET();
103+
__HAL_RCC_I2C1_RELEASE_RESET();
104+
__HAL_RCC_I2C1_CLK_DISABLE();
105+
106+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
107+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
108+
__HAL_RCC_GPIOB_CLK_DISABLE();
109+
#endif // PORTENTA_PMIC_ERRATA
110+
111+
// Reset ETH Phy
112+
mp_hal_pin_config(pyb_pin_ETH_RST, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_UP, 0);
113+
mp_hal_pin_config_speed(pyb_pin_ETH_RST, MP_HAL_PIN_SPEED_LOW);
114+
mp_hal_pin_write(pyb_pin_ETH_RST, 0);
115+
HAL_Delay(100);
116+
mp_hal_pin_write(pyb_pin_ETH_RST, 1);
117+
118+
// Put Eth in low-power mode
119+
eth_init(&eth_instance, MP_HAL_MAC_ETH0);
120+
eth_low_power_mode(&eth_instance, true);
121+
122+
#if MICROPY_HW_USB_HS_ULPI3320
123+
// Make sure UPLI is Not in low-power mode.
124+
ulpi_leave_low_power();
125+
#endif
126+
}
127+
128+
void PORTENTA_reboot_to_bootloader(void) {
129+
RTC_HandleTypeDef RTCHandle;
130+
RTCHandle.Instance = RTC;
131+
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0xDF59);
132+
NVIC_SystemReset();
133+
}
134+
135+
void PORTENTA_board_osc_enable(int enable) {
136+
mp_hal_pin_config(pyb_pin_OSCEN, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_UP, 0);
137+
mp_hal_pin_config_speed(pyb_pin_OSCEN, MP_HAL_PIN_SPEED_LOW);
138+
mp_hal_pin_write(pyb_pin_OSCEN, enable);
139+
}
140+
141+
void PORTENTA_board_low_power(int mode) {
142+
switch (mode) {
143+
case 0: // Leave stop mode.
144+
#if MICROPY_HW_USB_HS_ULPI3320
145+
ulpi_leave_low_power();
146+
#endif
147+
eth_low_power_mode(NULL, false);
148+
sdram_leave_low_power();
149+
break;
150+
case 1: // Enter stop mode.
151+
#if MICROPY_HW_USB_HS_ULPI3320
152+
ulpi_enter_low_power();
153+
#endif
154+
eth_low_power_mode(NULL, true);
155+
sdram_enter_low_power();
156+
break;
157+
case 2: // Enter standby mode.
158+
#if MICROPY_HW_USB_HS_ULPI3320
159+
ulpi_enter_low_power();
160+
#endif
161+
eth_low_power_mode(NULL, true);
162+
sdram_enter_power_down();
163+
break;
164+
}
165+
166+
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
167+
// Enable QSPI deepsleep for modes 1 and 2
168+
mp_spiflash_deepsleep(&spi_bdev.spiflash, (mode != 0));
169+
#endif
170+
171+
#if defined(M4_APP_ADDR)
172+
// Signal Cortex-M4 to go to Standby mode.
173+
if (mode == 2) {
174+
__HAL_RCC_HSEM_CLK_ENABLE();
175+
HAL_HSEM_FastTake(0);
176+
HAL_HSEM_Release(0, 0);
177+
__HAL_RCC_HSEM_CLK_DISABLE();
178+
HAL_Delay(100);
179+
}
180+
#endif
181+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Via dfu-util
2+
3+
This board can programmed via DFU bootloader, using e.g. [dfu-util](http://dfu-util.sourceforge.net/). To enter the DFU bootloader, double tap the reset (blue) button, or you can use `machine.bootloader()` from the MicroPython REPL.
4+
5+
```bash
6+
dfu-util -w -d 2341:035b -a 0 -d 0x8040000 -D firmware.dfu
7+
```
8+
9+
Or from Micropython source repository:
10+
11+
```bash
12+
make BOARD=ARDUINO_PORTENTA_H7 deploy
13+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include("$(PORT_DIR)/boards/manifest.py")
2+
include("$(MPY_DIR)/extmod/webrepl/manifest.py")
3+
include(
4+
"$(MPY_LIB_DIR)/micropython/bluetooth/aioble/manifest.py",
5+
client=True,
6+
central=True,
7+
l2cap=True,
8+
security=True,
9+
)

0 commit comments

Comments
 (0)
0