AP_Bootloader: save a few byts contructing MCU string

This commit is contained in:
Peter Barker 2023-04-14 20:54:34 +10:00 committed by Peter Barker
parent c3c758a2e4
commit da00993354
9 changed files with 27 additions and 32 deletions

View File

@ -6,7 +6,7 @@
#define STM32_UNKNOWN 0
const mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32F1xx", '?'},
{ STM32_UNKNOWN, "STM32F1xx" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -6,7 +6,7 @@
#define STM32_UNKNOWN 0
const mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32F3xx", '?'},
{ STM32_UNKNOWN, "STM32F3xx" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -19,13 +19,12 @@ enum {
#define STM32F42x_446xx 0x421
// The default CPU ID of STM32_UNKNOWN is 0 and is in offset 0
// Before a rev is known it is set to ?
// There for new silicon will result in STM32F4..,?
const mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32F???", '?'},
{ STM32F40x_41x, "STM32F40x", '?'},
{ STM32F42x_43x, "STM32F42x", '?'},
{ STM32F42x_446xx, "STM32F446XX", '?'},
{ STM32_UNKNOWN, "STM32F???" },
{ STM32F40x_41x, "STM32F40x" },
{ STM32F42x_43x, "STM32F42x" },
{ STM32F42x_446xx, "STM32F446XX" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -17,9 +17,9 @@ typedef enum mcu_rev_e {
// Before a rev is known it is set to ?
// There for new silicon will result in STM32F4..,?
mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32F??????", '?'},
{ STM32F74x_75x, "STM32F7[4|5]x", '?'},
{ STM32F76x_77x, "STM32F7[6|7]x", '?'},
{ STM32_UNKNOWN, "STM32F??????" },
{ STM32F74x_75x, "STM32F7[4|5]x" },
{ STM32F76x_77x, "STM32F7[6|7]x" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -7,7 +7,7 @@
#define STM32_UNKNOWN 0
mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32G4??", '?'},
{ STM32_UNKNOWN, "STM32G4??" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -8,8 +8,8 @@
#define STM32_H743 0x450
mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32H7???", '?'},
{ STM32_H743, "STM32H743/753", '?'},
{ STM32_UNKNOWN, "STM32H7???" },
{ STM32_H743, "STM32H743/753" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -7,7 +7,7 @@
#define STM32_UNKNOWN 0
mcu_des_t mcu_descriptions[] = {
{ STM32_UNKNOWN, "STM32L4??", '?'},
{ STM32_UNKNOWN, "STM32L4??" },
};
const mcu_rev_t silicon_revs[] = {

View File

@ -241,34 +241,31 @@ uint32_t get_mcu_desc(uint32_t max, uint8_t *revstr)
int32_t mcuid = idcode & DEVID_MASK;
uint16_t revid = ((idcode & REVID_MASK) >> 16);
mcu_des_t des = mcu_descriptions[STM32_UNKNOWN];
uint8_t *endp = &revstr[max - 1];
uint8_t *strp = revstr;
for (const auto &desc : mcu_descriptions) {
if (mcuid == desc.mcuid) {
des = desc;
// copy the string in:
const char *tmp = desc.desc;
while (strp < endp && *tmp) {
*strp++ = *tmp++;
}
break;
}
}
for (const auto &rev : silicon_revs) {
if (rev.revid == revid) {
des.rev = rev.rev;
}
}
uint8_t *endp = &revstr[max - 1];
uint8_t *strp = revstr;
while (strp < endp && *des.desc) {
*strp++ = *des.desc++;
}
// comma-separated:
if (strp < endp) {
*strp++ = ',';
}
for (const auto &rev : silicon_revs) {
if (rev.revid == revid) {
if (strp < endp) {
*strp++ = des.rev;
*strp++ = rev.rev;
}
}
}
return strp - revstr;

View File

@ -55,7 +55,6 @@ void led_pulses(uint8_t npulses);
typedef struct mcu_des_t {
uint16_t mcuid;
const char *desc;
char rev;
} mcu_des_t;
typedef struct mcu_rev_t {