Skip to content

Commit c736a9b

Browse files
dpgeorgeiabdalkader
authored andcommitted
stm32: Add support for N6.
Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 3469a9f commit c736a9b

73 files changed

Lines changed: 2805 additions & 117 deletions

Some content is hidden

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

drivers/bus/qspi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct _mp_qspi_proto_t {
4646
int (*write_cmd_addr_data)(void *self, uint8_t cmd, uint32_t addr, size_t len, const uint8_t *src);
4747
int (*read_cmd)(void *self, uint8_t cmd, size_t len, uint32_t *dest);
4848
int (*read_cmd_qaddr_qdata)(void *self, uint8_t cmd, uint32_t addr, uint8_t num_dummy, size_t len, uint8_t *dest);
49+
int (*read)(void *self, uint32_t addr, size_t len, uint8_t *dest); // can be NULL if direct read not supported
4950
} mp_qspi_proto_t;
5051

5152
typedef struct _mp_soft_qspi_obj_t {

drivers/memory/spiflash.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ void mp_spiflash_init(mp_spiflash_t *self) {
197197
} else {
198198
uint8_t num_dummy = MICROPY_HW_SPIFLASH_QREAD_NUM_DUMMY(self);
199199
self->config->bus.u_qspi.proto->ioctl(self->config->bus.u_qspi.data, MP_QSPI_IOCTL_INIT, num_dummy);
200+
if (self->config->bus.u_qspi.proto->read != NULL) {
201+
// A bus with a custom read function should not have any further initialisation done.
202+
return;
203+
}
200204
}
201205

202206
mp_spiflash_acquire_bus(self);
@@ -316,6 +320,10 @@ int mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *de
316320
if (len == 0) {
317321
return 0;
318322
}
323+
const mp_spiflash_config_t *c = self->config;
324+
if (c->bus_kind == MP_SPIFLASH_BUS_QSPI && c->bus.u_qspi.proto->read != NULL) {
325+
return c->bus.u_qspi.proto->read(c->bus.u_qspi.data, addr, len, dest);
326+
}
319327
mp_spiflash_acquire_bus(self);
320328
int ret = mp_spiflash_read_data(self, addr, len, dest);
321329
mp_spiflash_release_bus(self);

lib/libm_dbl/rint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <math.h>
33
#include <stdint.h>
44

5-
#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
5+
#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 || FLT_EVAL_METHOD==16
66
#define EPS DBL_EPSILON
77
#elif FLT_EVAL_METHOD==2
88
#define EPS LDBL_EPSILON

lib/stm32lib

Submodule stm32lib updated 269 files

ports/stm32/Makefile

Lines changed: 41 additions & 5 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)
@@ -300,6 +305,7 @@ SRC_C = \
300305
adc.c \
301306
sdio.c \
302307
subghz.c \
308+
xspi.c \
303309
$(wildcard $(BOARD_DIR)/*.c)
304310

305311
SRC_O += \
@@ -316,6 +322,10 @@ CFLAGS += -DUSE_HAL_DRIVER
316322
SRC_O += \
317323
resethandler_m3.o \
318324
shared/runtime/gchelper_thumb2.o
325+
else ifeq ($(MCU_SERIES),n6)
326+
SRC_O += \
327+
resethandler_m3_iram.o \
328+
shared/runtime/gchelper_thumb2.o
319329
else
320330
SRC_O += \
321331
resethandler.o \
@@ -328,8 +338,6 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
328338
hal_adc_ex.c \
329339
hal_cortex.c \
330340
hal_dma.c \
331-
hal_flash.c \
332-
hal_flash_ex.c \
333341
hal_gpio.c \
334342
hal_i2c.c \
335343
hal_pwr.c \
@@ -346,15 +354,30 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
346354
ll_utils.c \
347355
)
348356

349-
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 wb))
357+
ifneq ($(MCU_SERIES),n6)
358+
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
359+
hal_flash.c \
360+
hal_flash_ex.c \
361+
)
362+
endif
363+
364+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 l0 l1 l4 n6 wb))
350365
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
351366
hal_pcd.c \
352367
hal_pcd_ex.c \
353368
ll_usb.c \
354369
)
355370
endif
356371

357-
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h5 h7 l4))
372+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6))
373+
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
374+
hal_bsec.c \
375+
hal_rif.c \
376+
hal_xspi.c \
377+
)
378+
endif
379+
380+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 h5 h7 l4 n6))
358381
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
359382
hal_sd.c \
360383
ll_sdmmc.c \
@@ -379,7 +402,7 @@ $(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_mmc.o: CFLAGS += -Wno
379402
endif
380403
endif
381404

382-
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7))
405+
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f4 f7 g0 g4 h5 h7 n6))
383406
HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
384407
hal_dma_ex.c \
385408
)
@@ -489,6 +512,12 @@ all: $(OBJ)
489512

490513
ifeq ($(MBOOT_ENABLE_PACKING),1)
491514
all_main: $(BUILD)/firmware.pack.dfu
515+
else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),n6))
516+
ifeq ($(USE_MBOOT),1)
517+
all_main: $(BUILD)/firmware.dfu
518+
else
519+
all_main: $(BUILD)/firmware-trusted.bin
520+
endif
492521
else
493522
all_main: $(BUILD)/firmware.dfu
494523
endif
@@ -608,6 +637,13 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf
608637
$(BUILD)/firmware.elf: $(OBJ)
609638
$(call GENERATE_ELF,$@,$^)
610639

640+
$(BUILD)/firmware-trusted.bin: $(BUILD)/firmware.bin
641+
/bin/rm -f $@
642+
$(CUBE_PROG_BASE)/bin/STM32MP_SigningTool_CLI -bin $^ -nk -of 0x80000000 -t fsbl -o $@ -hv $(STM32_N6_HEADER_VERSION)
643+
644+
deploy-n6: $(BUILD)/firmware-trusted.bin
645+
$(CUBE_PROG_BASE)/bin/STM32_Programmer.sh -c port=SWD mode=HOTPLUG ap=1 -el $(DKEL) -w $^ 0x70000000 -hardRst
646+
611647
# List of sources for qstr extraction
612648
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(GEN_PINS_SRC)
613649

ports/stm32/adc.c

Lines changed: 17 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,8 @@ 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) {
281288
#else
282289
#error Unsupported processor
283290
#endif
@@ -311,6 +318,8 @@ static void adcx_clock_enable(ADC_HandleTypeDef *adch) {
311318
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
312319
}
313320
__HAL_RCC_ADC_CLK_ENABLE();
321+
#elif defined(STM32N6)
322+
// TODO
314323
#else
315324
#error Unsupported processor
316325
#endif
@@ -368,6 +377,8 @@ static void adcx_init_periph(ADC_HandleTypeDef *adch, uint32_t resolution) {
368377
adch->Init.OversamplingMode = DISABLE;
369378
adch->Init.DataAlign = ADC_DATAALIGN_RIGHT;
370379
adch->Init.DMAContinuousRequests = DISABLE;
380+
#elif defined(STM32N6)
381+
// TODO
371382
#else
372383
#error Unsupported processor
373384
#endif
@@ -449,6 +460,8 @@ static void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel)
449460
sConfig.SingleDiff = ADC_SINGLE_ENDED;
450461
sConfig.OffsetNumber = ADC_OFFSET_NONE;
451462
sConfig.Offset = 0;
463+
#elif defined(STM32N6)
464+
// TODO
452465
#else
453466
#error Unsupported processor
454467
#endif
@@ -669,6 +682,8 @@ static mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
669682
self->handle.Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
670683
#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
671684
SET_BIT(self->handle.Instance->CR, ADC_CR_ADSTART);
685+
#elif defined(STM32N6)
686+
// TODO
672687
#else
673688
#error Unsupported processor
674689
#endif
@@ -779,6 +794,8 @@ static mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
779794
adc->handle.Instance->CR2 |= (uint32_t)ADC_CR2_SWSTART;
780795
#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32H5) || defined(STM32H7) || defined(STM32L4) || defined(STM32WB)
781796
SET_BIT(adc->handle.Instance->CR, ADC_CR_ADSTART);
797+
#elif defined(STM32N6)
798+
// TODO
782799
#else
783800
#error Unsupported processor
784801
#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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
12+
// Oscillator timeouts in ms
13+
#define HSE_STARTUP_TIMEOUT (100)
14+
#define LSE_STARTUP_TIMEOUT (5000)
15+
16+
#include "boards/stm32n6xx_hal_conf_base.h"
17+
18+
#endif // MICROPY_INCLUDED_STM32N6XX_HAL_CONF_H

0 commit comments

Comments
 (0)