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

[code-structure] Add all STM32 Core-IDs to the codebase for MCU identification #903

Closed
Nightwalker-87 opened this issue Apr 1, 2020 · 12 comments · Fixed by #1216
Closed

Comments

@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Apr 1, 2020

We have Core-IDs defined in /include/stlink/stm32.h which are used to detect chips correctly.
However this is implemented differently for the various STM32 product lines which is not very clever nor follows any visible logic structure. The current situation is as follows:

/* STM32 Cortex-M core ids (CPUTAPID) */

#define STM32_CORE_ID_M0_SWD 0x0bb11477
// (RM0091 Section 32.5.3) F0 SW-DP
// (RM0444 Section 40.5.3) G0 SW-DP

#define STM32_CORE_ID_M0P_SWD 0x0bc11477
// (RM0385 Section 27.5.3) L0 SW-DP

#define STM32_CORE_ID_M3_r1p1_SWD 0x1ba01477
// (RM0008 Section 31.8.3) F1 SW-DP
#define STM32_CORE_ID_M3_r1p1_JTAG 0x3ba00477
// (RM0008 Section 31.6.3) F1 JTAG

#define STM32_CORE_ID_M3_r2p0_SWD 0x2ba01477
// (RM0033 Section 32.8.3) F2 SW-DP
// (RM0038 Section 30.8.3) L1 SW-DP
#define STM32_CORE_ID_M3_r2p0_JTAG 0x0ba00477
// (RM0033 Section 32.6.3) F2 JTAG
// (RM0038 Section 30.6.2) L1 JTAG

#define STM32_CORE_ID_M4_r0p1_SWD 0x1ba01477
// (RM0316 Section 33.8.3) F3 SW-DP
// (RM0351 Section 48.8.3) L4 SW-DP
// (RM0432 Section 57.8.3) L4+ SW-DP
#define STM32_CORE_ID_M4_r0p1_JTAG 0x4ba00477
// (RM0316 Section 33.6.3) F3 JTAG
// (RM0351 Section 48.6.3) L4 JTAG
// (RM0432 Section 57.6.3) L4+ JTAG

#define STM32_CORE_ID_M4F_r0p1_SWD 0x2ba01477
// (RM0090 Section 38.8.3) F4 SW-DP
// (RM0090 Section 47.8.3) G4 SW-DP
#define STM32_CORE_ID_M4F_r0p1_JTAG 0x4ba00477
// (RM0090 Section 38.6.3) F4 JTAG
// (RM0090 Section 47.6.3) G4 JTAG

#define STM32_CORE_ID_M7F_SWD 0x5ba02477
// (RM0385 Section 40.8.3) F7 SW-DP
#define STM32_CORE_ID_M7F_JTAG 0x5ba00477
// (RM0385 Section 40.6.3) F7 JTAG

#define STM32_CORE_ID_M7F_H7_SWD 0x6ba02477
// (RM0433 Section 60.4.1) H7 SW-DP
#define STM32_CORE_ID_M7F_H7_JTAG 0x6ba00477
// (RM0433 Section 60.4.1) H7 JTAG

#define STM32_CORE_ID_M33_SWD 0x0be02477
// (RM0438 Section 52.2.10) L5 SW-DP
// (RM0456 Section 65.3.3) U5 SW-DP
#define STM32_CORE_ID_M33_JTAGD 0x0be01477
// (RM0438 Section 52.2.10) L5 JTAG-DP
// (RM0456 Section 65.3.3) U5 JTAG-DP
#define STM32_CORE_ID_M33_JTAG 0x0ba04477
// (RM0438 Section 52.2.8) L5 JTAG
// (RM0456 Section 56.3.1) U5 JTAG

In reference to #756 and #761 this seems not to have been implemented well over time and should be commonly addressed.

@grevaillot
Copy link
Collaborator

hmm, while evaluating codebase to support H7/L5, i extracted a bit of an old H7 support patch and reworked it to do somethink like that

it's here : grevaillot@5b8ade2

i need to have a look at chips RM instead of defaulting to some default address for identification, but, as it, it works for the few devices i have in hand.

@Nightwalker-87
Copy link
Member Author

I'd propose to identify every MCUs via the following hierarchical workflow:

  1. Read Core-ID
  2. Read Chip-ID (by use of a unified macro naming scheme)
  3. Read specific parameters taken from /src/chip-id.c

@grevaillot
Copy link
Collaborator

grmpf, i need to finish back on that one, been busy recently and nothing rebases anymore :(

@Nightwalker-87
Copy link
Member Author

Well, one could think about a secondary loop to identify such if the regular Core-ID-based approach fails. This would not exclude clones from support, but instead even help to identify such more easily. A secondary loop could relate to the current process of identification.

The whole procedure would clearly strip down the whole process to a very unified linear approach with additional functionality.

@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.2, v1.6.3 Mar 10, 2021
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.8.0, v1.7.1 Apr 25, 2021
@houzhuhouzhu
Copy link

how to deal with ?

@Nightwalker-87
Copy link
Member Author

Yeah indeed, I've been waiting for some feedback here as well...

@Ant-ON
Copy link
Collaborator

Ant-ON commented Jul 30, 2021

@houzhuhouzhu
@Nightwalker-87
A similar implementation was done in PR #1120. Now it is used in release version. I have not heard any problem on the work yet...

@houzhuhouzhu
Copy link

J 4CPG89AUBHN@}_)C`@QLP

oh look it,maybe,I can rewrite it

@Nightwalker-87 Nightwalker-87 linked a pull request Jul 31, 2021 that will close this issue
@Nightwalker-87
Copy link
Member Author

@Ant-ON Yes, but as far as I noticed there are even more chip IDs that are currently not used for detection.

@Nightwalker-87 Nightwalker-87 removed a link to a pull request Aug 15, 2021
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.7.1, v1.8.0 Aug 15, 2021
@Nightwalker-87 Nightwalker-87 removed their assignment Sep 26, 2021
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.7.2, v1.7.1 Jan 16, 2022
@Nightwalker-87 Nightwalker-87 self-assigned this Jan 16, 2022
@Nightwalker-87 Nightwalker-87 linked a pull request Jan 16, 2022 that will close this issue
@Nightwalker-87 Nightwalker-87 changed the title [code-structure] Use of Core-IDs in the codebase for MCU identification [code-structure] Add all STM32 Core-IDs to the codebase for MCU identification Jan 20, 2022
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.