Skip to content

Commit 7dde5d8

Browse files
dpgeorgeiabdalkader
authored andcommitted
ports/stm32: Add N6 port.
Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent aecbcdc commit 7dde5d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1314
-73
lines changed

ports/stm32/Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
125125
CFLAGS += -DMBOOT_VTOR=$(MBOOT_TEXT0_ADDR)
126126
CFLAGS += -DMICROPY_HW_VTOR=$(TEXT0_ADDR)
127127

128+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6))
129+
# as doesn't recognise -mcpu=cortex-m55
130+
AFLAGS += -march=armv8.1-m.main
131+
else
128132
AFLAGS += $(filter -mcpu=%,$(CFLAGS_MCU_$(MCU_SERIES)))
133+
endif
129134

130135
# Configure for nan-boxing object model if requested
131136
ifeq ($(NANBOX),1)
@@ -328,8 +333,6 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
328333
hal_adc_ex.c \
329334
hal_cortex.c \
330335
hal_dma.c \
331-
hal_flash.c \
332-
hal_flash_ex.c \
333336
hal_gpio.c \
334337
hal_i2c.c \
335338
hal_pwr.c \
@@ -346,14 +349,21 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
346349
ll_utils.c \
347350
)
348351

349-
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 wb))
352+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 n6 wb))
350353
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
351354
hal_pcd.c \
352355
hal_pcd_ex.c \
353356
ll_usb.c \
354357
)
355358
endif
356359

360+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6))
361+
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
362+
hal_bsec.c \
363+
hal_xspi.c \
364+
)
365+
endif
366+
357367
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h5 h7 l4))
358368
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
359369
hal_sd.c \
@@ -608,6 +618,13 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
608618
$(BUILD)/firmware.elf: $(OBJ)
609619
$(call GENERATE_ELF,$@,$^)
610620

621+
$(BUILD)/firmware-trusted.bin: $(BUILD)/firmware.bin
622+
/bin/rm -f $@
623+
$(CUBE_PROG_BASE)/bin/STM32MP_SigningTool_CLI -bin $^ -nk -of 0x80000000 -t fsbl -o $@ -hv $(STM32_N6_HEADER_VERSION) #-dump $@
624+
625+
deploy-n6: $(BUILD)/firmware-trusted.bin
626+
$(CUBE_PROG_BASE)/bin/STM32_Programmer.sh -c port=SWD mode=HOTPLUG ap=1 -el $(DKEL) -w $^ 0x70000000 -hardRst
627+
611628
# List of sources for qstr extraction
612629
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(GEN_PINS_SRC)
613630

ports/stm32/adc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
#define ADC_CAL2 (TEMPSENSOR_CAL2_ADDR)
140140
#define ADC_CAL_BITS (12)
141141

142+
#elif defined(STM32N6)
143+
142144
#else
143145

144146
#error Unsupported processor
@@ -182,6 +184,7 @@
182184
#define VBAT_DIV (3)
183185
#elif defined(STM32L152xE)
184186
// STM32L152xE does not have vbat.
187+
#elif defined(STM32N6)
185188
#else
186189
#error Unsupported processor
187190
#endif
@@ -267,6 +270,8 @@ static bool is_adcx_channel(int channel) {
267270
// The first argument to the IS_ADC_CHANNEL macro is unused.
268271
return __HAL_ADC_IS_CHANNEL_INTERNAL(channel)
269272
|| IS_ADC_CHANNEL(NULL, __HAL_ADC_DECIMAL_NB_TO_CHANNEL(channel));
273+
#elif defined(STM32N6)
274+
return 0; // TODO
270275
#else
271276
#error Unsupported processor
272277
#endif
@@ -278,6 +283,9 @@ static void adc_wait_for_eoc_or_timeout(ADC_HandleTypeDef *adcHandle, int32_t ti
278283
while ((adcHandle->Instance->SR & ADC_FLAG_EOC) != ADC_FLAG_EOC) {
279284
#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
280285
while (READ_BIT(adcHandle->Instance->ISR, ADC_FLAG_EOC) != ADC_FLAG_EOC) {
286+
#elif defined(STM32N6)
287+
while (READ_BIT(adcHandle->Instance->ISR, ADC_FLAG_EOC) != ADC_FLAG_EOC) {
288+
//while (0) { // TODO
281289
#else
282290
#error Unsupported processor
283291
#endif
@@ -311,6 +319,8 @@ static void adcx_clock_enable(ADC_HandleTypeDef *adch) {
311319
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
312320
}
313321
__HAL_RCC_ADC_CLK_ENABLE();
322+
#elif defined(STM32N6)
323+
// TODO
314324
#else
315325
#error Unsupported processor
316326
#endif
@@ -368,6 +378,8 @@ static void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) {
368378
adch->Init.OversamplingMode = DISABLE;
369379
adch->Init.DataAlign = ADC_DATAALIGN_RIGHT;
370380
adch->Init.DMAContinuousRequests = DISABLE;
381+
#elif defined(STM32N6)
382+
// TODO
371383
#else
372384
#error Unsupported processor
373385
#endif
@@ -449,6 +461,8 @@ static void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel)
449461
sConfig.SingleDiff = ADC_SINGLE_ENDED;
450462
sConfig.OffsetNumber = ADC_OFFSET_NONE;
451463
sConfig.Offset = 0;
464+
#elif defined(STM32N6)
465+
// TODO
452466
#else
453467
#error Unsupported processor
454468
#endif
@@ -669,6 +683,8 @@ static mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
669683
self->handle.Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
670684
#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
671685
SET_BIT(self->handle.Instance->CR, ADC_CR_ADSTART);
686+
#elif defined(STM32N6)
687+
// TODO
672688
#else
673689
#error Unsupported processor
674690
#endif
@@ -779,6 +795,8 @@ static mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
779795
adc->handle.Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
780796
#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
781797
SET_BIT(adc->handle.Instance->CR, ADC_CR_ADSTART);
798+
#elif defined(STM32N6)
799+
// TODO
782800
#else
783801
#error Unsupported processor
784802
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#define MICROPY_HW_BOARD_NAME "NUCLEO-N657X0"
2+
#define MICROPY_HW_MCU_NAME "STM32N657X0"
3+
4+
#define MICROPY_HW_HAS_SWITCH (1)
5+
#define MICROPY_HW_HAS_FLASH (0)
6+
#define MICROPY_HW_ENABLE_RNG (0)
7+
#define MICROPY_HW_ENABLE_RTC (0)
8+
#define MICROPY_HW_ENABLE_ADC (0)
9+
#define MICROPY_HW_ENABLE_DAC (0)
10+
#define MICROPY_HW_ENABLE_USB (1)
11+
#define MICROPY_PY_PYB_LEGACY (0)
12+
13+
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
14+
15+
// HSE is 48MHz, this gives a CPU frequency of 800MHz.
16+
#define MICROPY_HW_CLK_PLLM (6)
17+
#define MICROPY_HW_CLK_PLLN (100)
18+
#define MICROPY_HW_CLK_PLLP1 (1)
19+
#define MICROPY_HW_CLK_PLLP2 (1)
20+
#define MICROPY_HW_CLK_PLLFRAC (0)
21+
22+
// USART1 config
23+
#define MICROPY_HW_UART1_TX (pyb_pin_UART1_TX)
24+
#define MICROPY_HW_UART1_RX (pyb_pin_UART1_RX)
25+
// USART1 is connected to the virtual com port on the ST-Link
26+
#define MICROPY_HW_UART_REPL PYB_UART_1
27+
#define MICROPY_HW_UART_REPL_BAUD 115200
28+
29+
// USER2 is floating, and pressing the button makes the input go high.
30+
#define MICROPY_HW_USRSW_PIN (pyb_pin_BUTTON)
31+
#define MICROPY_HW_USRSW_PULL (GPIO_PULLDOWN)
32+
#define MICROPY_HW_USRSW_EXTI_MODE (GPIO_MODE_IT_RISING)
33+
#define MICROPY_HW_USRSW_PRESSED (1)
34+
35+
// LEDs
36+
#define MICROPY_HW_LED1 (pyb_pin_LED_BLUE)
37+
#define MICROPY_HW_LED2 (pyb_pin_LED_RED)
38+
#define MICROPY_HW_LED3 (pyb_pin_LED_GREEN)
39+
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))
40+
#define MICROPY_HW_LED_OFF(pin) (mp_hal_pin_high(pin))
41+
42+
// USB config
43+
#define MICROPY_HW_USB_HS (1)
44+
#define MICROPY_HW_USB_HS_IN_FS (1)
45+
#define MICROPY_HW_USB_MAIN_DEV (USB_PHY_HS_ID)
46+
#define MICROPY_HW_USB_MSC (0)
47+
#define MICROPY_HW_USB_HID (0)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MCU_SERIES = n6
2+
CMSIS_MCU = STM32N657xx
3+
AF_FILE = boards/stm32n657_af.csv
4+
SYSTEM_FILE = $(STM32LIB_CMSIS_BASE)/Source/Templates/system_stm32$(MCU_SERIES)xx_fsbl.o
5+
STM32_N6_HEADER_VERSION = 2.1
6+
DKEL = $(CUBE_PROG_BASE)/bin/ExternalLoader/MX25UM51245G_STM32N6570-NUCLEO.stldr
7+
8+
ifeq ($(USE_MBOOT),1)
9+
LD_FILES = boards/stm32n657x0.ld boards/common_bl.ld
10+
TEXT0_ADDR = 0x08008000
11+
else
12+
LD_FILES = boards/stm32n657x0.ld boards/common_basic.ld
13+
TEXT0_ADDR = 0x34180400
14+
endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-UART1_TX,PE5
2+
-UART1_RX,PE6
3+
-BUTTON,PC13
4+
LED_BLUE,PG8
5+
LED_RED,PG10
6+
LED_GREEN,PG0
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* This file is part of the MicroPython project, http://micropython.org/
2+
* The MIT License (MIT)
3+
* Copyright (c) 2019 Damien P. George
4+
*/
5+
#ifndef MICROPY_INCLUDED_STM32N6XX_HAL_CONF_H
6+
#define MICROPY_INCLUDED_STM32N6XX_HAL_CONF_H
7+
8+
// Oscillator values in Hz
9+
#define HSE_VALUE (48000000)
10+
#define LSE_VALUE (32768)
11+
//#define EXTERNAL_I2S1_CLOCK_VALUE (48000)
12+
//#if defined(STM32N6C1xx) || defined(STM32N6B1xx) || defined(STM32N6B0xx)
13+
//#define EXTERNAL_I2S2_CLOCK_VALUE (48000)
14+
//#endif
15+
16+
// Oscillator timeouts in ms
17+
#define HSE_STARTUP_TIMEOUT (100)
18+
#define LSE_STARTUP_TIMEOUT (5000)
19+
20+
#include "boards/stm32n6xx_hal_conf_base.h"
21+
22+
#endif // MICROPY_INCLUDED_STM32N6XX_HAL_CONF_H
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021-2022 Damien P. George
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 "py/obj.h"
28+
#include "storage.h"
29+
#include "spi.h"
30+
31+
#if defined(MICROPY_HW_BDEV_SPIFLASH)
32+
33+
static const mp_soft_spi_obj_t soft_spi_bus = {
34+
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
35+
.polarity = 0,
36+
.phase = 0,
37+
.sck = MBOOT_SPIFLASH_SCK,
38+
.mosi = MBOOT_SPIFLASH_MOSI,
39+
.miso = MBOOT_SPIFLASH_MISO,
40+
};
41+
42+
static mp_spiflash_cache_t spi_bdev_cache;
43+
44+
const mp_spiflash_config_t spiflash_config = {
45+
.bus_kind = MP_SPIFLASH_BUS_SPI,
46+
.bus.u_spi.cs = MBOOT_SPIFLASH_CS,
47+
.bus.u_spi.data = (void *)&soft_spi_bus,
48+
.bus.u_spi.proto = &mp_soft_spi_proto,
49+
.cache = &spi_bdev_cache,
50+
};
51+
52+
spi_bdev_t spi_bdev;
53+
54+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2025 OpenMV LLC.
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 STM32_HAL_H
28+
#include "py/mphal.h"
29+
30+
#define OMV_BOOT_MAGIC_ADDR (0x3401FFFCU)
31+
#define OMV_BOOT_MAGIC_VALUE (0xB00710ADU)
32+
33+
void board_early_init(void) {
34+
35+
}
36+
37+
void board_enter_bootloader(void) {
38+
*((uint32_t *) OMV_BOOT_MAGIC_ADDR) = OMV_BOOT_MAGIC_VALUE;
39+
SCB_CleanDCache();
40+
NVIC_SystemReset();
41+
}

0 commit comments

Comments
 (0)