Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninitialized cpuid #938

Merged
merged 1 commit into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,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 @@ -30,9 +30,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