Browse Source

AP_Bootloader: added MCU descriptions

mission-4.1.18
Andrew Tridgell 7 years ago
parent
commit
c1d4362555
  1. 934
      Tools/AP_Bootloader/bl_protocol.cpp
  2. 65
      Tools/AP_Bootloader/support.cpp
  3. 17
      Tools/AP_Bootloader/support.h

934
Tools/AP_Bootloader/bl_protocol.cpp

File diff suppressed because it is too large Load Diff

65
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)
{ {
return 0; if (idx & 3) {
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)
@ -173,7 +222,7 @@ void *memcpy(void *dest, const void *src, size_t n)
{ {
uint8_t *tdest = (uint8_t *)dest; uint8_t *tdest = (uint8_t *)dest;
uint8_t *tsrc = (uint8_t *)src; uint8_t *tsrc = (uint8_t *)src;
for(int i=0; i<n; i++) { for (int i=0; i<n; i++) {
tdest[i] = tsrc[i]; tdest[i] = tsrc[i];
} }
return dest; return dest;
@ -182,7 +231,7 @@ void *memcpy(void *dest, const void *src, size_t n)
//simple variant of std c function to reduce used flash space //simple variant of std c function to reduce used flash space
int strcmp(const char *s1, const char *s2) int strcmp(const char *s1, const char *s2)
{ {
while( (*s1 != 0) && (*s1 == *s2) ) { while ((*s1 != 0) && (*s1 == *s2)) {
s1++; s1++;
s2++; s2++;
} }

17
Tools/AP_Bootloader/support.h

@ -1,12 +1,13 @@
#pragma once
#define LED_ACTIVITY 1 #define LED_ACTIVITY 1
#define LED_BOOTLOADER 2 #define LED_BOOTLOADER 2
/* board info forwarded from board-specific code to booloader */ /* board info forwarded from board-specific code to booloader */
struct boardinfo { struct boardinfo {
uint32_t board_type; uint32_t board_type;
uint32_t board_rev; uint32_t board_rev;
uint32_t fw_size; uint32_t fw_size;
} __attribute__((packed)); } __attribute__((packed));
extern struct boardinfo board_info; extern struct boardinfo board_info;
@ -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