Skip to content

Commit

Permalink
mimxrt/Makefile: Fix internal flash configuration and build.
Browse files Browse the repository at this point in the history
  • Loading branch information
iabdalkader authored and dpgeorge committed Apr 11, 2023
1 parent a22136a commit ed5e359
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
54 changes: 31 additions & 23 deletions ports/mimxrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,33 @@ SHARED_SRC_C += \
shared/runtime/sys_stdio_mphal.c \
shared/timeutils/timeutils.c \

# Add sources for respective board flash type
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash qspi_hyper_flash))
# Add hal/flexspi_nor_flash.c or hal/flashspi_hyper_flash.c respectively
SRC_HAL_C += hal/flexspi_$(subst qspi_,,$(MICROPY_HW_FLASH_TYPE)).c
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
SRC_HAL_C += $(BOARD_DIR)/$(MICROPY_HW_FLASH_TYPE)_config.c
else
SRC_HAL_C += hal/$(MICROPY_HW_FLASH_TYPE)_config.c
endif
# Set flash driver name, base address and internal flash flag, based on the flash type.
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash))
MICROPY_HW_FLASH_BASE = 0x60000000
FLEXSPI_FLASH_TYPE = $(MICROPY_HW_FLASH_TYPE)
else ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_hyper_flash))
MICROPY_HW_FLASH_BASE = 0x60000000
FLEXSPI_FLASH_TYPE = $(MICROPY_HW_FLASH_TYPE)
else ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),internal))
# The internal flash is an SPI NOR Flash.
MICROPY_HW_FLASH_BASE = 0x70000000
FLEXSPI_FLASH_TYPE = qspi_nor_flash
CFLAGS += -DMICROPY_HW_FLASH_INTERNAL
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
endif

# Add sources for respective board flash type
# Add hal/flexspi_nor_flash.c or hal/flashspi_hyper_flash.c respectively
SRC_HAL_C += hal/flexspi_$(subst qspi_,,$(FLEXSPI_FLASH_TYPE)).c
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
SRC_HAL_C += $(BOARD_DIR)/$(FLEXSPI_FLASH_TYPE)_config.c
else
SRC_HAL_C += hal/$(FLEXSPI_FLASH_TYPE)_config.c
endif

# Math library source files
ifeq ($(MICROPY_FLOAT_IMPL),double)
LIBM_SRC_C += $(addprefix lib/libm_dbl/,\
Expand Down Expand Up @@ -341,18 +353,14 @@ CFLAGS += \
-Wno-error=unused-parameter

# Configure respective board flash type
ifeq ($(MICROPY_HW_FLASH_TYPE),$(filter $(MICROPY_HW_FLASH_TYPE),qspi_nor_flash qspi_hyper_flash))
# Add hal/flexspi_nor_flash.h or hal/flexspi_hyper_flash.h respectively
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_$(subst qspi_,,$(MICROPY_HW_FLASH_TYPE)).h\"
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif
# Add hal/flexspi_nor_flash.h or hal/flexspi_hyper_flash.h respectively
CFLAGS += -DBOARD_FLASH_OPS_HEADER_H=\"hal/flexspi_$(subst qspi_,,$(FLEXSPI_FLASH_TYPE)).h\"
#
# Add custom (board specific) or default configuration
ifeq ($(MICROPY_HW_BOARD_FLASH_FILES),1)
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"$(BOARD)_flexspi_flash_config.h\"
else
$(error Error: Unknown board flash type $(MICROPY_HW_FLASH_TYPE))
CFLAGS += -DBOARD_FLASH_CONFIG_HEADER_H=\"hal/flexspi_flash_config.h\"
endif

# Configure floating point support
Expand Down Expand Up @@ -399,7 +407,7 @@ LDFLAGS += \
# the C preprocessor. Therefore keep LDDEFINES separated from LDFLAGS!

LDDEFINES = \
-DMICROPY_HW_FLASH_TYPE=$(MICROPY_HW_FLASH_TYPE) \
-DMICROPY_HW_FLASH_BASE=$(MICROPY_HW_FLASH_BASE) \
-DMICROPY_HW_FLASH_SIZE=$(MICROPY_HW_FLASH_SIZE)

ifdef MICROPY_HW_FLASH_RESERVED
Expand Down
10 changes: 1 addition & 9 deletions ports/mimxrt/boards/MIMXRT1064.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
reserved_size = MICROPY_HW_FLASH_RESERVED;
#endif

#if MICROPY_HW_FLASH_TYPE == qspi_nor_flash
flash_start = 0x60000000;
#elif MICROPY_HW_FLASH_TYPE == qspi_hyper_flash
flash_start = 0x60000000;
#elif MICROPY_HW_FLASH_TYPE == internal
flash_start = 0x70000000;
#else
#error Unknown MICROPY_HW_FLASH_TYPE
#endif
flash_start = MICROPY_HW_FLASH_BASE;
flash_size = MICROPY_HW_FLASH_SIZE;
flash_end = DEFINED(reserved_size) ? ((flash_start) + (flash_size - reserved_size)) : ((flash_start) + (flash_size));
flash_config_start = flash_start;
Expand Down
5 changes: 4 additions & 1 deletion ports/mimxrt/hal/flexspi_hyper_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
#include "fsl_flexspi.h"
// #include BOARD_FLASH_CONFIG_HEADER_H

#if defined MIMXRT117x_SERIES
#if defined MICROPY_HW_FLASH_INTERNAL
#define BOARD_FLEX_SPI FLEXSPI2
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI2_AMBA_BASE
#elif defined MIMXRT117x_SERIES
#define BOARD_FLEX_SPI FLEXSPI1
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI1_AMBA_BASE
#else
Expand Down
6 changes: 5 additions & 1 deletion ports/mimxrt/hal/flexspi_nor_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
#define MICROPY_INCLUDED_MIMXRT_HAL_FLEXSPI_NOR_FLASH_H

#include "fsl_flexspi.h"
#include "mpconfigboard.h"
#include BOARD_FLASH_CONFIG_HEADER_H

#if defined MIMXRT117x_SERIES
#if defined MICROPY_HW_FLASH_INTERNAL
#define BOARD_FLEX_SPI FLEXSPI2
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI2_AMBA_BASE
#elif defined MIMXRT117x_SERIES
#define BOARD_FLEX_SPI FLEXSPI1
#define BOARD_FLEX_SPI_ADDR_BASE FlexSPI1_AMBA_BASE
#else
Expand Down

0 comments on commit ed5e359

Please sign in to comment.