Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit d3fee6f

Browse files
committed
lpc55xx: Deduplicate error strings by extracting IAP command names into a reflection array
1 parent 2ef9faa commit d3fee6f

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/target/lpc55xx.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ typedef enum lpc55xx_iap_cmd {
102102
IAP_CMD_FFR_GET_UUID,
103103
} lpc55xx_iap_cmd_e;
104104

105+
#ifndef DEBUG_ERROR_IS_NOOP
106+
/* Reflection strings for enum above */
107+
static const char *const lpc55xx_iap_cmd_descr[] = {
108+
"FLASH_INIT",
109+
"FLASH_ERASE",
110+
"FLASH_PROGRAM",
111+
"FFR_INIT",
112+
"FFR_GET_UUID",
113+
};
114+
#endif
115+
105116
/* The possible IAP errors are documented here for easy reference */
106117
typedef enum lpc55xx_iap_status {
107118
IAP_STATUS_FLASH_SUCCESS = 0,
@@ -341,7 +352,7 @@ static bool lpc55xx_flash_init(target_s *target, lpc55xx_flash_config_s *config)
341352

342353
const lpc55xx_iap_status_e status = iap_call_raw(target, IAP_CMD_FLASH_INIT, 0, 0, 0);
343354
if (status != IAP_STATUS_FLASH_SUCCESS) {
344-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
355+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
345356
goto exit;
346357
}
347358

@@ -370,19 +381,19 @@ static bool lpc55xx_get_uuid(target_s *target, uint8_t *uuid)
370381

371382
lpc55xx_iap_status_e status = iap_call_raw(target, IAP_CMD_FLASH_INIT, 0, 0, 0);
372383
if (status != IAP_STATUS_FLASH_SUCCESS) {
373-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
384+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
374385
goto exit;
375386
}
376387

377388
status = iap_call_raw(target, IAP_CMD_FFR_INIT, 0, 0, 0);
378389
if (status != IAP_STATUS_FLASH_SUCCESS) {
379-
DEBUG_ERROR("LPC55xx: IAP error: FFR_INIT (%d)\n", status);
390+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FFR_INIT], status);
380391
goto exit;
381392
}
382393

383394
status = iap_call_raw(target, IAP_CMD_FFR_GET_UUID, LPC55xx_UUID_ADDRESS, 0, 0);
384395
if (status != IAP_STATUS_FLASH_SUCCESS) {
385-
DEBUG_ERROR("LPC55xx: IAP error: FFR_GET_UUID (%d)\n", status);
396+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FFR_GET_UUID], status);
386397
goto exit;
387398
}
388399

@@ -430,7 +441,7 @@ static bool lpc55xx_flash_prepare(target_flash_s *flash)
430441

431442
const lpc55xx_iap_status_e status = iap_call_raw(flash->t, IAP_CMD_FLASH_INIT, 0, 0, 0);
432443
if (status != IAP_STATUS_FLASH_SUCCESS)
433-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
444+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
434445
return status == IAP_STATUS_FLASH_SUCCESS;
435446
}
436447

@@ -439,7 +450,7 @@ static bool lpc55xx_flash_erase(target_flash_s *flash, target_addr_t addr, size_
439450
const lpc55xx_iap_status_e status =
440451
iap_call_raw(flash->t, IAP_CMD_FLASH_ERASE, addr, (uint32_t)len, LPC55xx_ERASE_KEY);
441452
if (status != IAP_STATUS_FLASH_SUCCESS)
442-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_ERASE (%d)\n", status);
453+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_ERASE], status);
443454
return status == IAP_STATUS_FLASH_SUCCESS;
444455
}
445456

@@ -450,7 +461,7 @@ static bool lpc55xx_flash_write(target_flash_s *flash, target_addr_t dest, const
450461
const lpc55xx_iap_status_e status =
451462
iap_call_raw(flash->t, IAP_CMD_FLASH_PROGRAM, dest, LPC55xx_WRITE_BUFFER_ADDRESS, (uint32_t)len);
452463
if (status != IAP_STATUS_FLASH_SUCCESS)
453-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_PROGRAM (%d)\n", status);
464+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_PROGRAM], status);
454465
return status == IAP_STATUS_FLASH_SUCCESS;
455466
}
456467

0 commit comments

Comments
 (0)