Skip to content

Commit

Permalink
RT1020 OTA: removed unnecessary compiler optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Nov 4, 2024
1 parent 67e17d3 commit e0db39b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
31 changes: 17 additions & 14 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -5644,8 +5644,8 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
// Note: the get_config function below works both for RT1020 and 1060
#if MG_OTA == MG_OTA_RT1020
MG_IRAM static int flexspi_nor_get_config(
struct mg_flexspi_nor_config *config) {
struct mg_flexspi_nor_config default_config = {
struct mg_flexspi_nor_config *config) {
static struct mg_flexspi_nor_config default_config = {
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
.version = MG_FLEXSPI_CFG_BLK_VERSION,
.readSampleClkSrc = 1, // ReadSampleClk_LoopbackFromDqsPad
Expand All @@ -5662,8 +5662,11 @@ MG_IRAM static int flexspi_nor_get_config(
.ipcmdSerialClkFreq = 1,
.blockSize = 64 * 1024,
.isUniformBlockSize = false};

*config = default_config;
const uint8_t *src = (const uint8_t *)&default_config;
volatile uint8_t *dst = (uint8_t *)config;
for (volatile size_t i = 0; i < sizeof(struct mg_flexspi_nor_config); i++) {
dst[i] = src[i];
}
return 0;
}
#else
Expand All @@ -5684,6 +5687,15 @@ MG_IRAM static int flexspi_nor_get_config(
}
#endif

MG_IRAM static void mg_spin(volatile uint32_t count) {
while (count--) (void) 0;
}

MG_IRAM static void flash_wait(void) {
while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0)
mg_spin(1);
}

MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config,
void *addr) {
if (flash_page_start(addr) == false) {
Expand All @@ -5708,7 +5720,7 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) {
MG_ARM_DISABLE_IRQ();
ret = (flexspi_nor_get_config(&config) == 0);
if (ret) ret = flash_erase(&config, addr);
MG_ARM_ENABLE_IRQ();
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
return ret;
}
#endif
Expand All @@ -5717,15 +5729,6 @@ MG_IRAM bool mg_imxrt_swap(void) {
return true;
}

static inline void spin(volatile uint32_t count) {
while (count--) (void) 0;
}

static inline void flash_wait(void) {
while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0)
spin(1);
}

MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
struct mg_flexspi_nor_config config;
bool ok = false;
Expand Down
31 changes: 17 additions & 14 deletions src/ota_imxrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ MG_IRAM static bool flash_page_start(volatile uint32_t *dst) {
// Note: the get_config function below works both for RT1020 and 1060
#if MG_OTA == MG_OTA_RT1020
MG_IRAM static int flexspi_nor_get_config(
struct mg_flexspi_nor_config *config) {
struct mg_flexspi_nor_config default_config = {
struct mg_flexspi_nor_config *config) {
static struct mg_flexspi_nor_config default_config = {
.memConfig = {.tag = MG_FLEXSPI_CFG_BLK_TAG,
.version = MG_FLEXSPI_CFG_BLK_VERSION,
.readSampleClkSrc = 1, // ReadSampleClk_LoopbackFromDqsPad
Expand All @@ -212,8 +212,11 @@ MG_IRAM static int flexspi_nor_get_config(
.ipcmdSerialClkFreq = 1,
.blockSize = 64 * 1024,
.isUniformBlockSize = false};

*config = default_config;
const uint8_t *src = (const uint8_t *)&default_config;
volatile uint8_t *dst = (uint8_t *)config;
for (volatile size_t i = 0; i < sizeof(struct mg_flexspi_nor_config); i++) {
dst[i] = src[i];
}
return 0;
}
#else
Expand All @@ -234,6 +237,15 @@ MG_IRAM static int flexspi_nor_get_config(
}
#endif

MG_IRAM static void mg_spin(volatile uint32_t count) {
while (count--) (void) 0;
}

MG_IRAM static void flash_wait(void) {
while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0)
mg_spin(1);
}

MG_IRAM static bool flash_erase(struct mg_flexspi_nor_config *config,
void *addr) {
if (flash_page_start(addr) == false) {
Expand All @@ -258,7 +270,7 @@ MG_IRAM static bool mg_imxrt_erase(void *addr) {
MG_ARM_DISABLE_IRQ();
ret = (flexspi_nor_get_config(&config) == 0);
if (ret) ret = flash_erase(&config, addr);
MG_ARM_ENABLE_IRQ();
if (!s_flash_irq_disabled) MG_ARM_ENABLE_IRQ();
return ret;
}
#endif
Expand All @@ -267,15 +279,6 @@ MG_IRAM bool mg_imxrt_swap(void) {
return true;
}

static inline void spin(volatile uint32_t count) {
while (count--) (void) 0;
}

static inline void flash_wait(void) {
while ((*((volatile uint32_t *) (0x402A8000 + 0xE0)) & MG_BIT(1)) == 0)
spin(1);
}

MG_IRAM static bool mg_imxrt_write(void *addr, const void *buf, size_t len) {
struct mg_flexspi_nor_config config;
bool ok = false;
Expand Down

0 comments on commit e0db39b

Please sign in to comment.