From 9c4523f4fa7b5ca840052a92a60bcf409cd31613 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 7 Nov 2024 08:13:07 -0500 Subject: [PATCH] OTA RT1170 --- mongoose.c | 54 ++++++++++++++++++++++++++++++++++++++++++------- mongoose.h | 1 + src/ota.h | 1 + src/ota_imxrt.c | 54 ++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 96 insertions(+), 14 deletions(-) diff --git a/mongoose.c b/mongoose.c index 25d92e41..e4979e4f 100644 --- a/mongoose.c +++ b/mongoose.c @@ -5452,17 +5452,20 @@ bool mg_ota_end(void) { -#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1064 +#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1170 static bool mg_imxrt_write(void *, const void *, size_t); static bool mg_imxrt_swap(void); -#if MG_OTA == MG_OTA_RT1064 -#define MG_IMXRT_FLASH_START 0x70000000 -#define FLEXSPI_NOR_INSTANCE 1 -#else +#if MG_OTA <= MG_OTA_RT1060 #define MG_IMXRT_FLASH_START 0x60000000 #define FLEXSPI_NOR_INSTANCE 0 +#elif MG_OTA == MG_OTA_RT1064 +#define MG_IMXRT_FLASH_START 0x70000000 +#define FLEXSPI_NOR_INSTANCE 1 +#else // RT1170 +#define MG_IMXRT_FLASH_START 0x30000000 +#define FLEXSPI_NOR_INSTANCE 1 #endif // TODO(): fill at init, support more devices in a dynamic way @@ -5616,7 +5619,7 @@ struct mg_flexspi_nor_driver_interface { int (*xfer)(uint32_t instance, char *xfer); void (*clear_cache)(uint32_t instance); }; -#else +#elif MG_OTA <= MG_OTA_RT1064 // RT104x and RT106x support ROM API version 1.5 struct mg_flexspi_nor_driver_interface { uint32_t version; @@ -5635,11 +5638,48 @@ struct mg_flexspi_nor_driver_interface { int (*get_config)(uint32_t instance, struct mg_flexspi_nor_config *config, uint32_t *option); }; +#else +// RT117x support ROM API version 1.7 +struct mg_flexspi_nor_driver_interface { + uint32_t version; + int (*init)(uint32_t instance, struct mg_flexspi_nor_config *config); + int (*program)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t dst_addr, const uint32_t *src); + int (*erase_all)(uint32_t instance, struct mg_flexspi_nor_config *config); + int (*erase)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t start, uint32_t lengthInBytes); + int (*read)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t *dst, uint32_t addr, uint32_t lengthInBytes); + uint32_t reserved; + int (*xfer)(uint32_t instance, char *xfer); + int (*update_lut)(uint32_t instance, uint32_t seqIndex, + const uint32_t *lutBase, uint32_t seqNumber); + int (*get_config)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t *option); + int (*erase_sector)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t address); + int (*erase_block)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t address); + void (*hw_reset)(uint32_t instance, uint32_t resetLogic); + int (*wait_busy)(uint32_t instance, struct mg_flexspi_nor_config *config, + bool isParallelMode, uint32_t address); + int (*set_clock_source)(uint32_t instance, uint32_t clockSrc); + void (*config_clock)(uint32_t instance, uint32_t freqOption, + uint32_t sampleClkMode); +}; #endif +#if MG_OTA <= MG_OTA_RT1064 +#define MG_FLEXSPI_BASE 0x402A8000 #define flexspi_nor \ (*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \ 16))) +#else +#define MG_FLEXSPI_BASE 0x400CC000 +#define flexspi_nor \ + (*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0021001c + \ + 12))) +#endif static bool s_flash_irq_disabled; @@ -5699,7 +5739,7 @@ MG_IRAM static void mg_spin(volatile uint32_t count) { } MG_IRAM static void flash_wait(void) { - while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) + while ((*((volatile uint32_t *) (MG_FLEXSPI_BASE + 0xE0)) & MG_BIT(1)) == 0) mg_spin(1); } diff --git a/mongoose.h b/mongoose.h index ddf3d3cf..40e189fa 100644 --- a/mongoose.h +++ b/mongoose.h @@ -2656,6 +2656,7 @@ void mg_rpc_list(struct mg_rpc_req *r); #define MG_OTA_RT1020 300 // IMXRT1020 #define MG_OTA_RT1060 301 // IMXRT1060 #define MG_OTA_RT1064 302 // IMXRT1064 +#define MG_OTA_RT1170 303 // IMXRT1170 #define MG_OTA_MCXN 310 // MCXN947 #define MG_OTA_FLASH 900 // OTA via an internal flash #define MG_OTA_ESP32 910 // ESP32 OTA implementation diff --git a/src/ota.h b/src/ota.h index 602340f9..861abd8a 100644 --- a/src/ota.h +++ b/src/ota.h @@ -14,6 +14,7 @@ #define MG_OTA_RT1020 300 // IMXRT1020 #define MG_OTA_RT1060 301 // IMXRT1060 #define MG_OTA_RT1064 302 // IMXRT1064 +#define MG_OTA_RT1170 303 // IMXRT1170 #define MG_OTA_MCXN 310 // MCXN947 #define MG_OTA_FLASH 900 // OTA via an internal flash #define MG_OTA_ESP32 910 // ESP32 OTA implementation diff --git a/src/ota_imxrt.c b/src/ota_imxrt.c index 0a01bfe4..800c47fe 100644 --- a/src/ota_imxrt.c +++ b/src/ota_imxrt.c @@ -2,17 +2,20 @@ #include "log.h" #include "ota.h" -#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1064 +#if MG_OTA >= MG_OTA_RT1020 && MG_OTA <= MG_OTA_RT1170 static bool mg_imxrt_write(void *, const void *, size_t); static bool mg_imxrt_swap(void); -#if MG_OTA == MG_OTA_RT1064 -#define MG_IMXRT_FLASH_START 0x70000000 -#define FLEXSPI_NOR_INSTANCE 1 -#else +#if MG_OTA <= MG_OTA_RT1060 #define MG_IMXRT_FLASH_START 0x60000000 #define FLEXSPI_NOR_INSTANCE 0 +#elif MG_OTA == MG_OTA_RT1064 +#define MG_IMXRT_FLASH_START 0x70000000 +#define FLEXSPI_NOR_INSTANCE 1 +#else // RT1170 +#define MG_IMXRT_FLASH_START 0x30000000 +#define FLEXSPI_NOR_INSTANCE 1 #endif // TODO(): fill at init, support more devices in a dynamic way @@ -166,7 +169,7 @@ struct mg_flexspi_nor_driver_interface { int (*xfer)(uint32_t instance, char *xfer); void (*clear_cache)(uint32_t instance); }; -#else +#elif MG_OTA <= MG_OTA_RT1064 // RT104x and RT106x support ROM API version 1.5 struct mg_flexspi_nor_driver_interface { uint32_t version; @@ -185,11 +188,48 @@ struct mg_flexspi_nor_driver_interface { int (*get_config)(uint32_t instance, struct mg_flexspi_nor_config *config, uint32_t *option); }; +#else +// RT117x support ROM API version 1.7 +struct mg_flexspi_nor_driver_interface { + uint32_t version; + int (*init)(uint32_t instance, struct mg_flexspi_nor_config *config); + int (*program)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t dst_addr, const uint32_t *src); + int (*erase_all)(uint32_t instance, struct mg_flexspi_nor_config *config); + int (*erase)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t start, uint32_t lengthInBytes); + int (*read)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t *dst, uint32_t addr, uint32_t lengthInBytes); + uint32_t reserved; + int (*xfer)(uint32_t instance, char *xfer); + int (*update_lut)(uint32_t instance, uint32_t seqIndex, + const uint32_t *lutBase, uint32_t seqNumber); + int (*get_config)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t *option); + int (*erase_sector)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t address); + int (*erase_block)(uint32_t instance, struct mg_flexspi_nor_config *config, + uint32_t address); + void (*hw_reset)(uint32_t instance, uint32_t resetLogic); + int (*wait_busy)(uint32_t instance, struct mg_flexspi_nor_config *config, + bool isParallelMode, uint32_t address); + int (*set_clock_source)(uint32_t instance, uint32_t clockSrc); + void (*config_clock)(uint32_t instance, uint32_t freqOption, + uint32_t sampleClkMode); +}; #endif +#if MG_OTA <= MG_OTA_RT1064 +#define MG_FLEXSPI_BASE 0x402A8000 #define flexspi_nor \ (*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0020001c + \ 16))) +#else +#define MG_FLEXSPI_BASE 0x400CC000 +#define flexspi_nor \ + (*((struct mg_flexspi_nor_driver_interface **) (*(uint32_t *) 0x0021001c + \ + 12))) +#endif static bool s_flash_irq_disabled; @@ -249,7 +289,7 @@ MG_IRAM static void mg_spin(volatile uint32_t count) { } MG_IRAM static void flash_wait(void) { - while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0) + while ((*((volatile uint32_t *) (MG_FLEXSPI_BASE + 0xE0)) & MG_BIT(1)) == 0) mg_spin(1); }