Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTA RT1170 #2956

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions mongoose.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 47 additions & 7 deletions src/ota_imxrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
Loading