diff --git a/boards/nxp/fmurt1170-v1/nuttx-config/Kconfig b/boards/nxp/fmurt1170-v1/nuttx-config/Kconfig index bd3aa63579..7cb7213ab0 100644 --- a/boards/nxp/fmurt1170-v1/nuttx-config/Kconfig +++ b/boards/nxp/fmurt1170-v1/nuttx-config/Kconfig @@ -39,3 +39,21 @@ config BOARD_FORCE_ALIGNMENT Adds -mno-unaligned-access to build flags. to force alignment. This can be needed if data is stored in a region of memory, that is Strongly ordered and dcache is off. + +config BOARD_BOOTLOADER_INVALID_FCB + bool "Disables the FCB header" + default n + + ---help--- + This can be used to keep the ROM bootloader in the serial Download mode. + Thus preventing bootlooping on `is_debug_pending` in the lame Rev B + silicon ROM bootloader. You can not cold boot (Power cycle) but can + Jtag from Load and be abel to reset it. + +config BOARD_BOOTLOADER_FIXUP + bool "Restores OCTAL Flash when No FCB" + default n + select ARCH_RAMFUNCS + + ---help--- + Restores OCTAL Flash when FCB is invalid. diff --git a/boards/nxp/fmurt1170-v1/nuttx-config/nsh/defconfig b/boards/nxp/fmurt1170-v1/nuttx-config/nsh/defconfig index 4029443b8d..73bfe46ab0 100644 --- a/boards/nxp/fmurt1170-v1/nuttx-config/nsh/defconfig +++ b/boards/nxp/fmurt1170-v1/nuttx-config/nsh/defconfig @@ -5,7 +5,6 @@ # You can then do "make savedefconfig" to generate a new defconfig file that includes your # modifications. # -# CONFIG_ARCH_RAMFUNCS is not set # CONFIG_NSH_DISABLE_MB is not set # CONFIG_NSH_DISABLE_MH is not set # CONFIG_NSH_DISABLE_MW is not set @@ -30,6 +29,8 @@ CONFIG_ARMV7M_USEBASEPRI=y CONFIG_ARM_MPU=y CONFIG_BOARDCTL_RESET=y CONFIG_BOARD_ASSERT_RESET_VALUE=0 +CONFIG_BOARD_BOOTLOADER_FIXUP=y +CONFIG_BOARD_BOOTLOADER_INVALID_FCB=y CONFIG_BOARD_CUSTOM_LEDS=y CONFIG_BOARD_FORCE_ALIGNMENT=y CONFIG_BOARD_LOOPSPERMSEC=104926 @@ -102,6 +103,7 @@ CONFIG_IMXRT_GPIO5_16_31_IRQ=y CONFIG_IMXRT_GPIO6_0_15_IRQ=y CONFIG_IMXRT_GPIO6_16_31_IRQ=y CONFIG_IMXRT_GPIO_IRQ=y +CONFIG_IMXRT_INIT_FLEXRAM=y CONFIG_IMXRT_ITCM=0 CONFIG_IMXRT_LPI2C1=y CONFIG_IMXRT_LPI2C2=y diff --git a/boards/nxp/fmurt1170-v1/src/CMakeLists.txt b/boards/nxp/fmurt1170-v1/src/CMakeLists.txt index 4027703a81..7a7c35d8f7 100644 --- a/boards/nxp/fmurt1170-v1/src/CMakeLists.txt +++ b/boards/nxp/fmurt1170-v1/src/CMakeLists.txt @@ -50,6 +50,7 @@ px4_add_library(drivers_board spi.cpp timer_config.cpp usb.c + imxrt_romapi.c imxrt_flexspi_fram.c imxrt_flexspi_nor_boot.c imxrt_flexspi_nor_flash.c diff --git a/boards/nxp/fmurt1170-v1/src/imxrt_flexspi_nor_flash.h b/boards/nxp/fmurt1170-v1/src/imxrt_flexspi_nor_flash.h index 391d5d81b8..1854974c77 100644 --- a/boards/nxp/fmurt1170-v1/src/imxrt_flexspi_nor_flash.h +++ b/boards/nxp/fmurt1170-v1/src/imxrt_flexspi_nor_flash.h @@ -39,7 +39,11 @@ /*@}*/ /* FLEXSPI memory config block related defintions */ -#define FLEXSPI_CFG_BLK_TAG (0x42464346UL) // ascii "FCFB" Big Endian +#if !defined(CONFIG_BOARD_BOOTLOADER_INVALID_FCB) +# define FLEXSPI_CFG_BLK_TAG (0x42464346UL) // ascii "FCFB" Big Endian +#else +# define FLEXSPI_CFG_BLK_TAG (0xffffffffL) // ascii Over Writable +#endif #define FLEXSPI_CFG_BLK_VERSION (0x56010400UL) // V1.4.0 #define FLEXSPI_CFG_BLK_SIZE (512) @@ -215,6 +219,41 @@ typedef struct { uint8_t delay_cells; /* Data valid time, in terms of delay cells */ } flexspi_dll_time_t; +/*! + * @name Configuration Option + * @{ + */ +/*! @brief Serial NOR Configuration Option. */ +typedef struct _serial_nor_config_option { + union { + struct { + uint32_t max_freq : 4; /*!< Maximum supported Frequency */ + uint32_t misc_mode : 4; /*!< miscellaneous mode */ + uint32_t quad_mode_setting : 4; /*!< Quad mode setting */ + uint32_t cmd_pads : 4; /*!< Command pads */ + uint32_t query_pads : 4; /*!< SFDP read pads */ + uint32_t device_type : 4; /*!< Device type */ + uint32_t option_size : 4; /*!< Option size, in terms of uint32_t, size = (option_size + 1) * 4 */ + uint32_t tag : 4; /*!< Tag, must be 0x0E */ + } B; + uint32_t U; + } option0; + + union { + struct { + uint32_t dummy_cycles : 8; /*!< Dummy cycles before read */ + uint32_t status_override : 8; /*!< Override status register value during device mode configuration */ + uint32_t pinmux_group : 4; /*!< The pinmux group selection */ + uint32_t dqs_pinmux_group : 4; /*!< The DQS Pinmux Group Selection */ + uint32_t drive_strength : 4; /*!< The Drive Strength of FlexSPI Pads */ + uint32_t flash_connection : 4; /*!< Flash connection option: 0 - Single Flash connected to port A, 1 - + Parallel mode, 2 - Single Flash connected to Port B */ + } B; + uint32_t U; + } option1; + +} serial_nor_config_option_t; + //!@brief FlexSPI Memory Configuration Block struct mem_config_s { uint32_t tag; //!< [0x000-0x003] Tag, fixed value 0x42464346UL diff --git a/boards/nxp/fmurt1170-v1/src/imxrt_romapi.c b/boards/nxp/fmurt1170-v1/src/imxrt_romapi.c new file mode 100644 index 0000000000..05dad584e5 --- /dev/null +++ b/boards/nxp/fmurt1170-v1/src/imxrt_romapi.c @@ -0,0 +1,271 @@ +/**************************************************************************** + * boards/arm/imxrt/imxrt1170-evk/src/imxrt_romapi.c + * + * Copyright 2017-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * +****************************************************************************/ + +/**************************************************************************** + * + * Included Files + ****************************************************************************/ + +#include "board_config.h" + +#include +#include +#include +#include + +#include "arm_internal.h" + +#include "imxrt_flexspi_nor_flash.h" +#include "imxrt_romapi.h" + +#include + +/******************************************************************************* + * Definitions + ******************************************************************************/ +/*! + * @brief Structure of version property. + * + * @ingroup bl_core + */ +typedef union _standard_version { + struct { + uint8_t bugfix; /*!< bugfix version [7:0] */ + uint8_t minor; /*!< minor version [15:8] */ + uint8_t major; /*!< major version [23:16] */ + char name; /*!< name [31:24] */ + }; + uint32_t version; /*!< combined version numbers */ + +#if defined(__cplusplus) + StandardVersion() : version(0) { + } + StandardVersion(uint32_t version) : version(version) { + } +#endif +} standard_version_t; + +/*! + * @brief Interface for the ROM FLEXSPI NOR flash driver. + */ +typedef struct { + uint32_t version; + status_t (*init)(uint32_t instance, flexspi_nor_config_t *config); + status_t (*page_program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src); + status_t (*erase_all)(uint32_t instance, flexspi_nor_config_t *config); + status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length); + status_t (*read)(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes); + void (*clear_cache)(uint32_t instance); + status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer); + status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t numberOfSeq); + status_t (*get_config)(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option); + status_t (*erase_sector)(uint32_t instance, flexspi_nor_config_t *config, uint32_t address); + status_t (*erase_block)(uint32_t instance, flexspi_nor_config_t *config, uint32_t address); + const uint32_t reserved0; /*!< Reserved */ + status_t (*wait_busy)(uint32_t instance, flexspi_nor_config_t *config, bool isParallelMode, uint32_t address); + const uint32_t reserved1[2]; /*!< Reserved */ +} flexspi_nor_driver_interface_t; + +/*! + * @brief Root of the bootloader api tree. + * + * An instance of this struct resides in read-only memory in the bootloader. It + * provides a user application access to APIs exported by the bootloader. + * + * @note The order of existing fields must not be changed. + */ +typedef struct { + void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing.*/ + standard_version_t version; /*!< Bootloader version number.*/ + const char *copyright; /*!< Copyright string.*/ + const flexspi_nor_driver_interface_t *flexSpiNorDriver; /*!< FlexSPI NOR FLASH Driver API.*/ + const uint32_t reserved[8]; /*!< Reserved */ +} bootloader_api_entry_t; + +/******************************************************************************* + * Variables + ******************************************************************************/ + +static bootloader_api_entry_t *g_bootloaderTree = NULL; + +/******************************************************************************* + * ROM FLEXSPI NOR driver + ******************************************************************************/ +/*! + * @brief ROM API init. + */ +locate_code(".ramfunc") +void ROM_API_Init(void) +{ + + if ((getreg32(IMXRT_ANADIG_MISC_MISC_DIFPROG) & ANADIG_MISC_MISC_DIFPROG_CHIPID(0x10U)) != 0U) { + g_bootloaderTree = ((bootloader_api_entry_t *) * (uint32_t *)0x0021001cU); + + } else { + g_bootloaderTree = ((bootloader_api_entry_t *) * (uint32_t *)0x0020001cU); + } +} + +/*! + * @brief Enter Bootloader. + * + * @param arg A pointer to the storage for the bootloader param. + * refer to System Boot Chapter in device reference manual for details. + */ +locate_code(".ramfunc") +void ROM_RunBootloader(void *arg) +{ + g_bootloaderTree->runBootloader(arg); +} + +/*! @brief Get FLEXSPI NOR Configuration Block based on specified option. */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_GetConfig(uint32_t instance, + flexspi_nor_config_t *config, + serial_nor_config_option_t *option) +{ + return g_bootloaderTree->flexSpiNorDriver->get_config(instance, config, option); +} + +/*! + * @brief Initialize Serial NOR devices via FLEXSPI. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config) +{ + return g_bootloaderTree->flexSpiNorDriver->init(instance, config); +} + +/*! + * @brief Program data to Serial NOR via FLEXSPI. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dst_addr A pointer to the desired flash memory to be programmed. + * @param src A pointer to the source buffer of data that is to be programmed + * into the NOR flash. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance, + flexspi_nor_config_t *config, + uint32_t dst_addr, + const uint32_t *src) +{ + return g_bootloaderTree->flexSpiNorDriver->page_program(instance, config, dst_addr, src); +} + +/*! + * @brief Read data from Serial NOR + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dst A pointer to the dest buffer of data that is to be read from the NOR flash. + * @param lengthInBytes The length, given in bytes to be read. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_Read( + uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t lengthInBytes) +{ + return g_bootloaderTree->flexSpiNorDriver->read(instance, config, dst, start, lengthInBytes); +} + +/*! + * @brief Erase Flash Region specified by address and length. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * @param length The length, given in bytes to be erased. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length) +{ + return g_bootloaderTree->flexSpiNorDriver->erase(instance, config, start, length); +} + +/*! + * @brief Erase one sector specified by address. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t start) +{ + return g_bootloaderTree->flexSpiNorDriver->erase_sector(instance, config, start); +} + +/*! + * @brief Erase one block specified by address. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_EraseBlock(uint32_t instance, flexspi_nor_config_t *config, uint32_t start) +{ + return g_bootloaderTree->flexSpiNorDriver->erase_block(instance, config, start); +} + +/*! @brief Erase all the Serial NOR devices connected on FLEXSPI. */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config) +{ + return g_bootloaderTree->flexSpiNorDriver->erase_all(instance, config); +} + +/*! @brief FLEXSPI command */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer) +{ + return g_bootloaderTree->flexSpiNorDriver->xfer(instance, xfer); +} +/*! @brief Configure FLEXSPI Lookup table. */ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance, + uint32_t seqIndex, + const uint32_t *lutBase, + uint32_t seqNumber) +{ + return g_bootloaderTree->flexSpiNorDriver->update_lut(instance, seqIndex, lutBase, seqNumber); +} + +/*! @brief Software reset for the FLEXSPI logic. */ +locate_code(".ramfunc") +void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance) +{ + uint32_t clearCacheFunctionAddress; + + if ((getreg32(IMXRT_ANADIG_MISC_MISC_DIFPROG) & ANADIG_MISC_MISC_DIFPROG_CHIPID(0x10U)) != 0U) { + clearCacheFunctionAddress = 0x0021a3b7U; + + } else { + clearCacheFunctionAddress = 0x0020426bU; + } + + clearCacheCommand_t clearCacheCommand; + MISRA_CAST(clearCacheCommand_t, clearCacheCommand, uint32_t, clearCacheFunctionAddress); + (void)clearCacheCommand(instance); +} + +/*! @brief Wait until device is idle*/ +locate_code(".ramfunc") +status_t ROM_FLEXSPI_NorFlash_WaitBusy(uint32_t instance, + flexspi_nor_config_t *config, + bool isParallelMode, + uint32_t address) +{ + return g_bootloaderTree->flexSpiNorDriver->wait_busy(instance, config, isParallelMode, address); +} diff --git a/boards/nxp/fmurt1170-v1/src/imxrt_romapi.h b/boards/nxp/fmurt1170-v1/src/imxrt_romapi.h new file mode 100644 index 0000000000..cdc3018b6b --- /dev/null +++ b/boards/nxp/fmurt1170-v1/src/imxrt_romapi.h @@ -0,0 +1,372 @@ +/**************************************************************************** + * boards/arm/imxrt/imxrt1170-evk/src/imxrt_romapi.c + * + * Copyright 2017-2020 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * +****************************************************************************/ +#ifndef __BOARDS_ARM_IMXRT_IMXRT1170_SRC_IMXRT_ROMAPI_H +#define __BOARDS_ARM_IMXRT_IMXRT1170_SRC_IMXRT_ROMAPI_H + +/**************************************************************************** + * + * Included Files + ****************************************************************************/ + +#include "board_config.h" + +typedef int32_t status_t; +typedef struct flexspi_nor_config_s flexspi_nor_config_t; +typedef status_t (*clearCacheCommand_t)(uint32_t instance); + +/*! @brief FLEXSPI Operation Context */ +typedef enum _flexspi_operation { + kFLEXSPIOperation_Command, /*!< FLEXSPI operation: Only command, both TX and RX buffer are ignored. */ + kFLEXSPIOperation_Config, /*!< FLEXSPI operation: Configure device mode, the TX FIFO size is fixed in LUT. */ + kFLEXSPIOperation_Write, /*!< FLEXSPI operation: Write, only TX buffer is effective */ + kFLEXSPIOperation_Read, /*!< FLEXSPI operation: Read, only Rx Buffer is effective. */ +} flexspi_operation_t; + +#define kFLEXSPIOperation_End kFLEXSPIOperation_Read + +/*! @brief FLEXSPI Transfer Context */ +typedef struct _flexspi_xfer { + flexspi_operation_t operation; /*!< FLEXSPI operation */ + uint32_t baseAddress; /*!< FLEXSPI operation base address */ + uint32_t seqId; /*!< Sequence Id */ + uint32_t seqNum; /*!< Sequence Number */ + bool isParallelModeEnable; /*!< Is a parallel transfer */ + uint32_t *txBuffer; /*!< Tx buffer */ + uint32_t txSize; /*!< Tx size in bytes */ + uint32_t *rxBuffer; /*!< Rx buffer */ + uint32_t rxSize; /*!< Rx size in bytes */ +} flexspi_xfer_t; + +/*! @brief convert the type for MISRA */ +#define MISRA_CAST(to_type, to_var, from_type, from_var) \ + do \ + { \ + union \ + { \ + to_type to_var_tmp; \ + from_type from_var_tmp; \ + } type_converter_var = {.from_var_tmp = (from_var)}; \ + (to_var) = type_converter_var.to_var_tmp; \ + } while (false) + +#ifdef __cplusplus +extern "C" { +#endif + + +/*! + * @brief ROM API init + * + * Get the bootloader api entry address. + */ +void ROM_API_Init(void); + +/*! + * @name Enter Bootloader + * @{ + */ + +/*! + * @brief Enter Bootloader. + * + * @param arg A pointer to the storage for the bootloader param. + * refer to System Boot Chapter in device reference manual for details. + */ +void ROM_RunBootloader(void *arg); + +/*@}*/ + +/*! + * @name GetConfig + * @{ + */ +/*! + * @brief Get FLEXSPI NOR Configuration Block based on specified option. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param option A pointer to the storage Serial NOR Configuration Option Context. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_GetConfig(uint32_t instance, + flexspi_nor_config_t *config, + serial_nor_config_option_t *option); + +/*! + * @name Initialization + * @{ + */ + +/*! + * @brief Initialize Serial NOR devices via FLEXSPI + * + * This function checks and initializes the FLEXSPI module for the other FLEXSPI APIs. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config); + +/*@}*/ + +/*! + * @name Programming + * @{ + */ + +/*! + * @brief Program data to Serial NOR via FLEXSPI. + * + * This function programs the NOR flash memory with the dest address for a given + * flash area as determined by the dst address and the length. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dst_addr A pointer to the desired flash memory to be programmed. + * @note It is recommended that use page aligned access; + * If the dst_addr is not aligned to page, the driver automatically + * aligns address down with the page address. + * @param src A pointer to the source buffer of data that is to be programmed + * into the NOR flash. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance, + flexspi_nor_config_t *config, + uint32_t dst_addr, + const uint32_t *src); + +/*@}*/ + +/*! + * @name Reading + * @{ + */ + +/*! + * @brief Read data from Serial NOR via FLEXSPI. + * + * This function read the NOR flash memory with the start address for a given + * flash area as determined by the dst address and the length. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param dst A pointer to the dest buffer of data that is to be read from the NOR flash. + * @note It is recommended that use page aligned access; + * If the dstAddr is not aligned to page, the driver automatically + * aligns address down with the page address. + * @param start The start address of the desired NOR flash memory to be read. + * @param lengthInBytes The length, given in bytes to be read. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_Read( + uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t lengthInBytes); + +/*@}*/ + +/*! + * @name Erasing + * @{ + */ + +/*! + * @brief Erase Flash Region specified by address and length + * + * This function erases the appropriate number of flash sectors based on the + * desired start address and length. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * @note It is recommended that use sector-aligned access nor device; + * If dstAddr is not aligned with the sector,the driver automatically + * aligns address down with the sector address. + * @param length The length, given in bytes to be erased. + * @note It is recommended that use sector-aligned access nor device; + * If length is not aligned with the sector,the driver automatically + * aligns up with the sector. + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length); + +/*! + * @brief Erase one sector specified by address + * + * This function erases one of NOR flash sectors based on the desired address. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * @note It is recommended that use sector-aligned access nor device; + * If dstAddr is not aligned with the sector, the driver automatically + * aligns address down with the sector address. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t start); + +/*! + * @brief Erase one block specified by address + * + * This function erases one block of NOR flash based on the desired address. + * + * @param instance storage the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * @param start The start address of the desired NOR flash memory to be erased. + * @note It is recommended that use block-aligned access nor device; + * If dstAddr is not aligned with the block, the driver automatically + * aligns address down with the block address. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_EraseBlock(uint32_t instance, flexspi_nor_config_t *config, uint32_t start); + +/*! + * @brief Erase all the Serial NOR devices connected on FLEXSPI. + * + * @param instance storage the instance of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout the device timeout + */ +status_t ROM_FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config); + +/*@}*/ + +/*! + * @name Command + * @{ + */ +/*! + * @brief FLEXSPI command + * + * This function is used to perform the command write sequence to the NOR device. + * + * @param instance storage the index of FLEXSPI. + * @param xfer A pointer to the storage FLEXSPI Transfer Context. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + */ +status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer); + +/*@}*/ + +/*! + * @name UpdateLut + * @{ + */ + +/*! + * @brief Configure FLEXSPI Lookup table + * + * @param instance storage the index of FLEXSPI. + * @param seqIndex storage the sequence Id. + * @param lutBase A pointer to the look-up-table for command sequences. + * @param seqNumber storage sequence number. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + */ +status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance, + uint32_t seqIndex, + const uint32_t *lutBase, + uint32_t seqNumber); + + +/*@}*/ + +/*! + * @name Device status + * @{ + */ +/*! + * @brief Wait until device is idle. + * + * @param instance Indicates the index of FLEXSPI. + * @param config A pointer to the storage for the driver runtime state + * @param isParallelMode Indicates whether NOR flash is in parallel mode. + * @param address Indicates the operation(erase/program/read) address for serial NOR flash. + * + * @retval kStatus_Success Api was executed successfully. + * @retval kStatus_InvalidArgument A invalid argument is provided. + * @retval kStatus_ROM_FLEXSPI_SequenceExecutionTimeout Sequence Execution timeout. + * @retval kStatus_ROM_FLEXSPI_InvalidSequence A invalid Sequence is provided. + * @retval kStatus_ROM_FLEXSPI_DeviceTimeout Device timeout. + */ +status_t ROM_FLEXSPI_NorFlash_WaitBusy(uint32_t instance, + flexspi_nor_config_t *config, + bool isParallelMode, + uint32_t address); +/*@}*/ + +/*! + * @name ClearCache + * @{ + */ + +/*! + * @name ClearCache + * @{ + */ + +/*! + * @brief Software reset for the FLEXSPI logic. + * + * This function sets the software reset flags for both AHB and buffer domain and + * resets both AHB buffer and also IP FIFOs. + * + * @param instance storage the index of FLEXSPI. + */ +void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance); + +/*@}*/ + +#endif /* __BOARDS_ARM_IMXRT_IMXRT1170_SRC_IMXRT_ROMAPI_H */ diff --git a/boards/nxp/fmurt1170-v1/src/init.c b/boards/nxp/fmurt1170-v1/src/init.c index ff9872f2c4..43f478557c 100644 --- a/boards/nxp/fmurt1170-v1/src/init.c +++ b/boards/nxp/fmurt1170-v1/src/init.c @@ -47,6 +47,7 @@ #include "board_config.h" +#include #include #include #include @@ -63,9 +64,10 @@ #include #include -#include "arm_internal.h" #include "arm_internal.h" #include "imxrt_flexspi_nor_boot.h" +#include "imxrt_flexspi_nor_flash.h" +#include "imxrt_romapi.h" #include "imxrt_iomuxc.h" #include #include "board_config.h" @@ -149,7 +151,39 @@ __EXPORT void board_on_reset(int status) } } +#if defined(CONFIG_BOARD_BOOTLOADER_FIXUP) +/**************************************************************************** + * Name: imxrt_octl_flash_initialize + * + * Description: + * + ****************************************************************************/ +locate_code(".ramfunc") +void imxrt_octl_flash_initialize(void) +{ + const uint32_t instance = 1; + serial_nor_config_option_t option_1_8bit = { + .option0.U = 0xC0403007, + .option1.U = 0U, + }; + + struct flexspi_nor_config_s norConfig; + + ROM_API_Init(); + + + int32_t status = ROM_FLEXSPI_NorFlash_GetConfig(instance, &norConfig, &option_1_8bit); + + if (status == OK) { + status = ROM_FLEXSPI_NorFlash_Init(instance, &norConfig); + } + + ARM_DSB(); + ARM_ISB(); + ARM_DMB(); +} +#endif /**************************************************************************** * Name: imxrt_ocram_initialize * @@ -206,11 +240,11 @@ __EXPORT void imxrt_ocram_initialize(void) __EXPORT void imxrt_boardinitialize(void) { - -#if !defined(CONFIG_BOOT_RUNFROMISRAM) - imxrt_ocram_initialize(); +#if defined(CONFIG_BOARD_BOOTLOADER_FIXUP) + imxrt_octl_flash_initialize(); #endif + board_on_reset(-1); /* Reset PWM first thing */ /* configure LEDs */