Hopefully fix reading an invalid chip ID on STM32WB55
@@ -1222,8 +1222,34 @@ int stlink_chip_id(stlink_t *sl, uint32_t *chip_id) {
int ret;
if (sl->core_id == STM32H7_CORE_ID) {
- // STM32H7 chipid in 0x5c001000 (RM0433 pg3189)
- ret = stlink_read_debug32(sl, 0x5c001000, chip_id);
+ /* STM32H7 chipid in 0x5c001000 (RM0433 pg3189)
+ * However, the STM32H7 is not the only chip with a JTAG
+ * IDCODE of 0x6ba02477, so we cannot rely solely on this info
+ * to select the address to read the chip id */
+
+ uint32_t chip_id_tmp;
+ // try reading from 0x5c001000
+ ret = stlink_read_debug32(sl, 0x5c001000, &chip_id_tmp);
+
+ // Extract the DEV_ID/CHIPID
+ uint32_t h7_chip_id = chip_id_tmp & 0xfff;
+
+ if(ret != -1){
+ // If we successfully read a H7 chip ID, return that
+ if((h7_chip_id == STLINK_CHIPID_STM32_H74XXX) ||
+ (h7_chip_id == STLINK_CHIPID_STM32_H7AX) ||
+ (h7_chip_id == STLINK_CHIPID_STM32_H72X)) {
+ *chip_id = chip_id_tmp;
+ return(ret);
+ }
+ }
+
+ // If we had an error or were unsuccessful at reading an H7
+ // series chip ID, try reading the chip ID from the default
+ // address
+ ret = stlink_read_debug32(sl, 0xE0042000, chip_id);
+
+
} else {
// default chipid address
ret = stlink_read_debug32(sl, 0xE0042000, chip_id);
