Skip to content

Commit

Permalink
Merge pull request #938 from chenguokai/issue937
Browse files Browse the repository at this point in the history
Fixed uninitialized cpuid
  • Loading branch information
Nightwalker-87 committed Apr 20, 2020
2 parents fb9f777 + 5f983a6 commit 05cf375
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,13 @@ int stlink_chip_id(stlink_t *sl, uint32_t *chip_id) {
int stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid) {
uint32_t raw;

if (stlink_read_debug32(sl, STLINK_REG_CM3_CPUID, &raw))
if (stlink_read_debug32(sl, STLINK_REG_CM3_CPUID, &raw)) {
cpuid->implementer_id = 0;
cpuid->variant = 0;
cpuid->part = 0;
cpuid->revision = 0;
return -1;

}
cpuid->implementer_id = (raw >> 24) & 0x7f;
cpuid->variant = (raw >> 20) & 0xf;
cpuid->part = (raw >> 4) & 0xfff;
Expand Down
10 changes: 7 additions & 3 deletions tests/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ int main(int ac, char** av) {
printf("-- core_id: %#x\n", sl->core_id);

cortex_m3_cpuid_t cpuid;
stlink_cpu_id(sl, &cpuid);
printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
if (stlink_cpu_id(sl, &cpuid)) {
printf("Failed reading stlink_cpu_id\n");
} else {
printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
}


printf("-- read_sram\n");
static const uint32_t sram_base = STM32_SRAM_BASE;
Expand Down

0 comments on commit 05cf375

Please sign in to comment.