Skip to content

Commit

Permalink
stm32mp15: Use stm32-generic uid and revision commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Sep 19, 2023
1 parent 8d19e7b commit acfd190
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/target/stm32mp15.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@
#define STM32MP15_AHBSRAM_BASE 0x10000000U
#define STM32MP15_AHBSRAM_SIZE 0x00060000U /* AHB SRAM 1+2+3+4, 128+128+64+64 KiB */

/* Access from processor address space.
* Access via the debug APB is at 0xe0081000 over AP1. */
#define STM32MP15_DBGMCU_BASE 0x50081000U
#define STM32MP15_UID_BASE 0x5c005234U
#define DBGMCU_IDCODE (STM32MP15_DBGMCU_BASE + 0U)

/* Taken from DP_TARGETID.TPARTNO = 0x5000 in §66.8.3 of RM0436 rev 6, pg3669 */
/* Taken from DBGMCU_IDC.DEV_ID = 0x500 in §66.10.9 of RM0436 rev 6, pg3825 */
#define ID_STM32MP15x 0x5000U
/* Taken from CM4ROM_PIDRx in 2.3.21 of ES0438 rev 7, pg18 */
#define ID_STM32MP15x_ERRATA 0x450U

static bool stm32mp15_uid(target_s *target, int argc, const char **argv);
static bool stm32mp15_cmd_rev(target_s *target, int argc, const char **argv);

const command_s stm32mp15_cmd_list[] = {
{"uid", stm32mp15_uid, "Print unique device ID"},
{"revision", stm32mp15_cmd_rev, "Returns the Device ID and Revision"},
{NULL, NULL, NULL},
};

bool stm32mp15_cm4_probe(target_s *target)
{
if (target->part_id != ID_STM32MP15x && target->part_id != ID_STM32MP15x_ERRATA)
Expand All @@ -52,10 +67,69 @@ bool stm32mp15_cm4_probe(target_s *target)
target->driver = "STM32MP15";
target->attach = cortexm_attach;
target->detach = cortexm_detach;
target_add_commands(target, stm32mp15_cmd_list, target->driver);

/* Figure 4. Memory map from §2.5.2 in RM0436 rev 6, pg158 */
target_add_ram(target, STM32MP15_RETRAM_BASE, STM32MP15_RETRAM_SIZE);
target_add_ram(target, STM32MP15_AHBSRAM_BASE, STM32MP15_AHBSRAM_SIZE);

return true;
}

/*
* Print the Unique device ID.
* Can be reused for other STM32 devices with uid as parameter.
*/
static bool stm32mp15_uid(target_s *target, int argc, const char **argv)
{
(void)argc;
(void)argv;

tc_printf(target, "0x");
for (size_t i = 0; i < 12U; i += 4U) {
const uint32_t value = target_mem_read32(target, STM32MP15_UID_BASE + i);
tc_printf(target, "%02X%02X%02X%02X", (value >> 24U) & 0xffU, (value >> 16U) & 0xffU, (value >> 8U) & 0xffU,
value & 0xffU);
}
tc_printf(target, "\n");
return true;
}

static const struct {
uint16_t rev_id;
char revision;
} stm32mp15x_revisions[] = {
{0x2000U, 'B'},
{0x2001U, 'Z'},
};

static bool stm32mp15_cmd_rev(target_s *target, int argc, const char **argv)
{
(void)argc;
(void)argv;
/* DBGMCU identity code register */
const uint32_t dbgmcu_idcode = target_mem_read32(target, DBGMCU_IDCODE);
const uint16_t rev_id = (dbgmcu_idcode >> 16U) & 0xffffU;
const uint16_t dev_id = (dbgmcu_idcode & 0xfffU) << 4U;

/* Print device */
switch (dev_id) {
case ID_STM32MP15x:
tc_printf(target, "STM32MP15x\n");

/* Print revision */
char rev = '?';
for (size_t i = 0; i < ARRAY_LENGTH(stm32mp15x_revisions); i++) {
/* Check for matching revision */
if (stm32mp15x_revisions[i].rev_id == rev_id)
rev = stm32mp15x_revisions[i].revision;
}
tc_printf(target, "Revision %c\n", rev);
break;

default:
tc_printf(target, "Unknown %s. BMP may not correctly support it!\n", target->driver);
}

return true;
}

0 comments on commit acfd190

Please sign in to comment.