From da00993354e4bf56c7e687b9f4c656a85cef1419 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 14 Apr 2023 20:54:34 +1000 Subject: [PATCH] AP_Bootloader: save a few byts contructing MCU string --- Tools/AP_Bootloader/mcu_f1.h | 2 +- Tools/AP_Bootloader/mcu_f3.h | 2 +- Tools/AP_Bootloader/mcu_f4.h | 9 ++++----- Tools/AP_Bootloader/mcu_f7.h | 6 +++--- Tools/AP_Bootloader/mcu_g4.h | 2 +- Tools/AP_Bootloader/mcu_h7.h | 4 ++-- Tools/AP_Bootloader/mcu_l4.h | 2 +- Tools/AP_Bootloader/support.cpp | 31 ++++++++++++++----------------- Tools/AP_Bootloader/support.h | 1 - 9 files changed, 27 insertions(+), 32 deletions(-) diff --git a/Tools/AP_Bootloader/mcu_f1.h b/Tools/AP_Bootloader/mcu_f1.h index 4132a4098e..015fc63477 100644 --- a/Tools/AP_Bootloader/mcu_f1.h +++ b/Tools/AP_Bootloader/mcu_f1.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_f3.h b/Tools/AP_Bootloader/mcu_f3.h index 5abfb60593..2ba1567baf 100644 --- a/Tools/AP_Bootloader/mcu_f3.h +++ b/Tools/AP_Bootloader/mcu_f3.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_f4.h b/Tools/AP_Bootloader/mcu_f4.h index 6f5ed61667..a07e08c3ac 100644 --- a/Tools/AP_Bootloader/mcu_f4.h +++ b/Tools/AP_Bootloader/mcu_f4.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_f7.h b/Tools/AP_Bootloader/mcu_f7.h index e60f757ad8..cb5d9160ee 100644 --- a/Tools/AP_Bootloader/mcu_f7.h +++ b/Tools/AP_Bootloader/mcu_f7.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_g4.h b/Tools/AP_Bootloader/mcu_g4.h index a258af137b..3c8f4309ca 100644 --- a/Tools/AP_Bootloader/mcu_g4.h +++ b/Tools/AP_Bootloader/mcu_g4.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_h7.h b/Tools/AP_Bootloader/mcu_h7.h index 5a0cc2ae31..eff524c984 100644 --- a/Tools/AP_Bootloader/mcu_h7.h +++ b/Tools/AP_Bootloader/mcu_h7.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/mcu_l4.h b/Tools/AP_Bootloader/mcu_l4.h index eed3509743..7ef0d42f50 100644 --- a/Tools/AP_Bootloader/mcu_l4.h +++ b/Tools/AP_Bootloader/mcu_l4.h @@ -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[] = { diff --git a/Tools/AP_Bootloader/support.cpp b/Tools/AP_Bootloader/support.cpp index c49b0158e2..4874d38f7b 100644 --- a/Tools/AP_Bootloader/support.cpp +++ b/Tools/AP_Bootloader/support.cpp @@ -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++ = ','; } - if (strp < endp) { - *strp++ = des.rev; + for (const auto &rev : silicon_revs) { + if (rev.revid == revid) { + if (strp < endp) { + *strp++ = rev.rev; + } + } } return strp - revstr; diff --git a/Tools/AP_Bootloader/support.h b/Tools/AP_Bootloader/support.h index 13f3085ba3..c47112ec76 100644 --- a/Tools/AP_Bootloader/support.h +++ b/Tools/AP_Bootloader/support.h @@ -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 {