This is an automated email from Gerrit. "Jérôme Pouiller <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9444
-- gerrit commit d2c507f535f196a43ff7d598a827b215f15047c8 Author: Jérôme Pouiller <[email protected]> Date: Wed Feb 4 14:05:15 2026 +0100 flash/nor/efm32: Rework efm32_wait_status() This patch slightly improve efm32_wait_status(): - Specify unit for the timeout - Avoid use of int for the semantic of a boolean - Do not define symbols for arbitrary values (100ms of timeout is not a technical requirement, this is just a reasonable value without more meaning) Signed-off-by: Jérôme Pouiller <[email protected]> Change-Id: Iac7082cf4fbce2e762732274d2a10698a3865690 diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index 12697d2a62..9ece92d1d0 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -33,10 +33,6 @@ #define EFM_FAMILY_ID_GIANT_GECKO 72 #define EFM_FAMILY_ID_LEOPARD_GECKO 74 -#define EFM32_FLASH_ERASE_TMO 100 -#define EFM32_FLASH_WDATAREADY_TMO 100 -#define EFM32_FLASH_WRITE_TMO 100 - #define EFM32_FLASH_BASE 0 /* size in bytes, not words; must fit all Gecko devices */ @@ -420,25 +416,25 @@ static int efm32_msc_lock(struct flash_bank *bank, int lock) (lock ? 0 : EFM32_MSC_LOCK_LOCKKEY)); } -static int efm32_wait_status(struct flash_bank *bank, int timeout, - uint32_t wait_mask, int wait_for_set) +static int efm32_wait_status(struct flash_bank *bank, int timeout_ms, + uint32_t wait_mask, bool wait_for_set) { - int ret = 0; uint32_t status = 0; + int ret = 0; while (1) { ret = efm32_read_reg_u32(bank, EFM32_MSC_REG_STATUS, &status); if (ret != ERROR_OK) - break; + return ret; LOG_DEBUG("status: 0x%" PRIx32, status); - if ((status & wait_mask) == 0 && wait_for_set == 0) + if (!(status & wait_mask) && !wait_for_set) break; - else if ((status & wait_mask) != 0 && wait_for_set) + if ((status & wait_mask) && wait_for_set) break; - if (timeout-- <= 0) { + if (timeout_ms-- <= 0) { LOG_ERROR("timed out waiting for MSC status"); return ERROR_FAIL; } @@ -449,7 +445,7 @@ static int efm32_wait_status(struct flash_bank *bank, int timeout, if (status & EFM32_MSC_STATUS_ERASEABORTED_MASK) LOG_WARNING("page erase was aborted"); - return ret; + return ERROR_OK; } static int efm32_erase_page(struct flash_bank *bank, uint32_t addr) @@ -494,8 +490,8 @@ static int efm32_erase_page(struct flash_bank *bank, uint32_t addr) if (ret != ERROR_OK) return ret; - return efm32_wait_status(bank, EFM32_FLASH_ERASE_TMO, - EFM32_MSC_STATUS_BUSY_MASK, 0); + return efm32_wait_status(bank, 100, + EFM32_MSC_STATUS_BUSY_MASK, false); } static int efm32_erase(struct flash_bank *bank, unsigned int first, @@ -939,8 +935,8 @@ static int efm32_write_word(struct flash_bank *bank, uint32_t addr, return ERROR_FAIL; } - ret = efm32_wait_status(bank, EFM32_FLASH_WDATAREADY_TMO, - EFM32_MSC_STATUS_WDATAREADY_MASK, 1); + ret = efm32_wait_status(bank, 100, + EFM32_MSC_STATUS_WDATAREADY_MASK, true); if (ret != ERROR_OK) { LOG_ERROR("Wait for WDATAREADY failed"); return ret; @@ -959,8 +955,8 @@ static int efm32_write_word(struct flash_bank *bank, uint32_t addr, return ret; } - ret = efm32_wait_status(bank, EFM32_FLASH_WRITE_TMO, - EFM32_MSC_STATUS_BUSY_MASK, 0); + ret = efm32_wait_status(bank, 100, + EFM32_MSC_STATUS_BUSY_MASK, false); if (ret != ERROR_OK) { LOG_ERROR("Wait for BUSY failed"); return ret; --
