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

Commit c3ed8fc

Browse files
committed
lpc55xx: Deduplicate error strings by extracting IAP command names into a reflection array
1 parent 8047eb3 commit c3ed8fc

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/target/lpc55xx.c

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

105+
/* Reflection strings for enum above */
106+
const char *const lpc55xx_iap_cmd_descr[] = {
107+
"FLASH_INIT",
108+
"FLASH_ERASE",
109+
"FLASH_PROGRAM",
110+
"FFR_INIT",
111+
"FFR_GET_UUID",
112+
};
113+
105114
/* The possible IAP errors are documented here for easy reference */
106115
typedef enum lpc55xx_iap_status {
107116
IAP_STATUS_FLASH_SUCCESS = 0,
@@ -341,7 +350,7 @@ static bool lpc55xx_flash_init(target_s *target, lpc55xx_flash_config_s *config)
341350

342351
const lpc55xx_iap_status_e status = iap_call_raw(target, IAP_CMD_FLASH_INIT, 0, 0, 0);
343352
if (status != IAP_STATUS_FLASH_SUCCESS) {
344-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
353+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
345354
goto exit;
346355
}
347356

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

371380
lpc55xx_iap_status_e status = iap_call_raw(target, IAP_CMD_FLASH_INIT, 0, 0, 0);
372381
if (status != IAP_STATUS_FLASH_SUCCESS) {
373-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
382+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
374383
goto exit;
375384
}
376385

377386
status = iap_call_raw(target, IAP_CMD_FFR_INIT, 0, 0, 0);
378387
if (status != IAP_STATUS_FLASH_SUCCESS) {
379-
DEBUG_ERROR("LPC55xx: IAP error: FFR_INIT (%d)\n", status);
388+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FFR_INIT], status);
380389
goto exit;
381390
}
382391

383392
status = iap_call_raw(target, IAP_CMD_FFR_GET_UUID, LPC55xx_UUID_ADDRESS, 0, 0);
384393
if (status != IAP_STATUS_FLASH_SUCCESS) {
385-
DEBUG_ERROR("LPC55xx: IAP error: FFR_GET_UUID (%d)\n", status);
394+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FFR_GET_UUID], status);
386395
goto exit;
387396
}
388397

@@ -430,7 +439,7 @@ static bool lpc55xx_flash_prepare(target_flash_s *flash)
430439

431440
const lpc55xx_iap_status_e status = iap_call_raw(flash->t, IAP_CMD_FLASH_INIT, 0, 0, 0);
432441
if (status != IAP_STATUS_FLASH_SUCCESS)
433-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_INIT (%d)\n", status);
442+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_INIT], status);
434443
return status == IAP_STATUS_FLASH_SUCCESS;
435444
}
436445

@@ -439,7 +448,7 @@ static bool lpc55xx_flash_erase(target_flash_s *flash, target_addr_t addr, size_
439448
const lpc55xx_iap_status_e status =
440449
iap_call_raw(flash->t, IAP_CMD_FLASH_ERASE, addr, (uint32_t)len, LPC55xx_ERASE_KEY);
441450
if (status != IAP_STATUS_FLASH_SUCCESS)
442-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_ERASE (%d)\n", status);
451+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_ERASE], status);
443452
return status == IAP_STATUS_FLASH_SUCCESS;
444453
}
445454

@@ -450,7 +459,7 @@ static bool lpc55xx_flash_write(target_flash_s *flash, target_addr_t dest, const
450459
const lpc55xx_iap_status_e status =
451460
iap_call_raw(flash->t, IAP_CMD_FLASH_PROGRAM, dest, LPC55xx_WRITE_BUFFER_ADDRESS, (uint32_t)len);
452461
if (status != IAP_STATUS_FLASH_SUCCESS)
453-
DEBUG_ERROR("LPC55xx: IAP error: FLASH_PROGRAM (%d)\n", status);
462+
DEBUG_ERROR("LPC55xx: IAP error: %s (%d)\n", lpc55xx_iap_cmd_descr[IAP_CMD_FLASH_PROGRAM], status);
454463
return status == IAP_STATUS_FLASH_SUCCESS;
455464
}
456465

0 commit comments

Comments
 (0)