Browse Source

AP_Bootloader: added MCU descriptions

mission-4.1.18
Andrew Tridgell 7 years ago
parent
commit
c1d4362555
  1. 59
      Tools/AP_Bootloader/support.cpp
  2. 11
      Tools/AP_Bootloader/support.h

59
Tools/AP_Bootloader/support.cpp

@ -8,7 +8,10 @@
#include "hwdef.h" #include "hwdef.h"
#include <AP_HAL_ChibiOS/hwdef/common/usbcfg.h> #include <AP_HAL_ChibiOS/hwdef/common/usbcfg.h>
#include <AP_HAL_ChibiOS/hwdef/common/flash.h> #include <AP_HAL_ChibiOS/hwdef/common/flash.h>
#include <AP_HAL_ChibiOS/hwdef/common/stm32_util.h>
#include "support.h" #include "support.h"
#include "mcu_f4.h"
#include "mcu_f7.h"
int16_t cin(unsigned timeout_ms) int16_t cin(unsigned timeout_ms)
{ {
@ -75,25 +78,71 @@ void flash_func_erase_sector(uint32_t sector)
stm32_flash_erasepage(flash_base_page+sector); stm32_flash_erasepage(flash_base_page+sector);
} }
// read one-time programmable memory
uint32_t flash_func_read_otp(uint32_t idx) uint32_t flash_func_read_otp(uint32_t idx)
{ {
if (idx & 3) {
return 0; return 0;
} }
if (idx > OTP_SIZE) {
return 0;
}
return *(uint32_t *)(idx + OTP_BASE);
}
// read chip serial number
uint32_t flash_func_read_sn(uint32_t idx) uint32_t flash_func_read_sn(uint32_t idx)
{ {
return 0; return *(uint32_t *)(UDID_START + idx);
} }
uint32_t get_mcu_id(void) uint32_t get_mcu_id(void)
{ {
return 0; return *(uint32_t *)DBGMCU_BASE;
} }
uint32_t get_mcu_desc(uint32_t len, uint8_t *buf) #define REVID_MASK 0xFFFF0000
#define DEVID_MASK 0xFFF
uint32_t get_mcu_desc(uint32_t max, uint8_t *revstr)
{ {
buf[0] = 'A'; uint32_t idcode = (*(uint32_t *)DBGMCU_BASE);
return 1; int32_t mcuid = idcode & DEVID_MASK;
uint16_t revid = ((idcode & REVID_MASK) >> 16);
mcu_des_t des = mcu_descriptions[STM32_UNKNOWN];
for (int i = 0; i < ARRAY_SIZE_SIMPLE(mcu_descriptions); i++) {
if (mcuid == mcu_descriptions[i].mcuid) {
des = mcu_descriptions[i];
break;
}
}
for (int i = 0; i < ARRAY_SIZE_SIMPLE(silicon_revs); i++) {
if (silicon_revs[i].revid == revid) {
des.rev = silicon_revs[i].rev;
}
}
uint8_t *endp = &revstr[max - 1];
uint8_t *strp = revstr;
while (strp < endp && *des.desc) {
*strp++ = *des.desc++;
}
if (strp < endp) {
*strp++ = ',';
}
if (strp < endp) {
*strp++ = des.rev;
}
return strp - revstr;
} }
void led_on(unsigned led) void led_on(unsigned led)

11
Tools/AP_Bootloader/support.h

@ -1,3 +1,4 @@
#pragma once
#define LED_ACTIVITY 1 #define LED_ACTIVITY 1
#define LED_BOOTLOADER 2 #define LED_BOOTLOADER 2
@ -37,3 +38,13 @@ void uprintf(const char *fmt, ...);
// generate a LED sequence forever // generate a LED sequence forever
void led_pulses(uint8_t npulses); 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 {
uint16_t revid;
char rev;
} mcu_rev_t;

Loading…
Cancel
Save