AP_Bootloader: added MCU descriptions

This commit is contained in:
Andrew Tridgell 2018-06-21 16:41:07 +10:00
parent 518d41e0d4
commit c1d4362555
4 changed files with 508 additions and 448 deletions

View File

@ -44,7 +44,7 @@ int main(void)
chThdSleepMilliseconds(1000);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
board_info.board_type = APJ_BOARD_ID;
board_info.board_rev = 0;
board_info.fw_size = (BOARD_FLASH_SIZE - FLASH_BOOTLOADER_LOAD_KB)*1024;

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,10 @@
#include "hwdef.h"
#include <AP_HAL_ChibiOS/hwdef/common/usbcfg.h>
#include <AP_HAL_ChibiOS/hwdef/common/flash.h>
#include <AP_HAL_ChibiOS/hwdef/common/stm32_util.h>
#include "support.h"
#include "mcu_f4.h"
#include "mcu_f7.h"
int16_t cin(unsigned timeout_ms)
{
@ -72,28 +75,74 @@ uint32_t flash_func_sector_size(uint32_t sector)
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)
{
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)
{
return 0;
return *(uint32_t *)(UDID_START + idx);
}
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';
return 1;
uint32_t idcode = (*(uint32_t *)DBGMCU_BASE);
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)
@ -173,7 +222,7 @@ void *memcpy(void *dest, const void *src, size_t n)
{
uint8_t *tdest = (uint8_t *)dest;
uint8_t *tsrc = (uint8_t *)src;
for(int i=0; i<n; i++) {
for (int i=0; i<n; i++) {
tdest[i] = tsrc[i];
}
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
int strcmp(const char *s1, const char *s2)
{
while( (*s1 != 0) && (*s1 == *s2) ) {
while ((*s1 != 0) && (*s1 == *s2)) {
s1++;
s2++;
}

View File

@ -1,12 +1,13 @@
#pragma once
#define LED_ACTIVITY 1
#define LED_BOOTLOADER 2
/* board info forwarded from board-specific code to booloader */
struct boardinfo {
uint32_t board_type;
uint32_t board_rev;
uint32_t fw_size;
uint32_t board_type;
uint32_t board_rev;
uint32_t fw_size;
} __attribute__((packed));
extern struct boardinfo board_info;
@ -37,3 +38,13 @@ void uprintf(const char *fmt, ...);
// generate a LED sequence forever
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;