X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstlink-common.c;h=707316cc988051daf4bd4085a486870f0084db65;hb=bd3472751be353b9e220bfa2fa59bacb4d6b5b57;hp=0aadb3d4891c7de73b76058398c6ebad0b938b46;hpb=f85a173c465bb875359df223cfac81cdd16db5c7;p=fw%2Fstlink diff --git a/src/stlink-common.c b/src/stlink-common.c index 0aadb3d..707316c 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -258,7 +258,6 @@ static void disable_flash_read_protection(stlink_t *sl) { void stlink_close(stlink_t *sl) { D(sl, "\n*** stlink_close ***\n"); sl->backend->close(sl); - free(sl); } @@ -299,10 +298,24 @@ uint16_t stlink_chip_id(stlink_t *sl) { return chip_id; } +/** + * Cortex m3 tech ref manual, CPUID register description + * @param sl stlink context + * @param cpuid pointer to the result object + */ +void stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid) { + stlink_read_mem32(sl, CM3_REG_CPUID, 4); + uint32_t raw = read_uint32(sl->q_buf, 0); + cpuid->implementer_id = (raw >> 24) & 0x7f; + cpuid->variant = (raw >> 20) & 0xf; + cpuid->part = (raw >> 4) & 0xfff; + cpuid->revision = raw & 0xf; + return; +} + void stlink_reset(stlink_t *sl) { D(sl, "\n*** stlink_reset ***\n"); sl->backend->reset(sl); - } void stlink_run(stlink_t *sl) {