serial_no: Fix error with "mon trace" #732
launchpad-icdi: Allow to set a serial number with make
This commit is contained in:
parent
bdb351a6ea
commit
77231e8972
|
@ -29,6 +29,7 @@
|
|||
#include "target.h"
|
||||
#include "morse.h"
|
||||
#include "version.h"
|
||||
#include "serialno.h"
|
||||
|
||||
#ifdef PLATFORM_HAS_TRACESWO
|
||||
# include "traceswo.h"
|
||||
|
@ -367,7 +368,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv)
|
|||
#ifdef PLATFORM_HAS_TRACESWO
|
||||
static bool cmd_traceswo(target *t, int argc, const char **argv)
|
||||
{
|
||||
extern char *serial_no;
|
||||
char serial_no[13];
|
||||
(void)t;
|
||||
#if TRACESWO_PROTOCOL == 2
|
||||
uint32_t baudrate = SWO_DEFAULT_BAUD;
|
||||
|
@ -413,6 +414,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv)
|
|||
#else
|
||||
traceswo_init(swo_channelmask);
|
||||
#endif
|
||||
serial_no_read(serial_no, sizeof(serial_no));
|
||||
gdb_outf("%s:%02X:%02X\n", serial_no, 5, 0x85);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#ifndef __SERIALNO_H
|
||||
#define __SERIALNO_H
|
||||
|
||||
char *serialno_read(char *s);
|
||||
char *serial_no_read(char *s, int max);
|
||||
|
||||
#endif
|
||||
|
|
@ -391,9 +391,9 @@ static const struct usb_config_descriptor config = {
|
|||
};
|
||||
|
||||
#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
|
||||
char serial_no[13];
|
||||
static char serial_no[13];
|
||||
#else
|
||||
char serial_no[9];
|
||||
static char serial_no[9];
|
||||
#endif
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
|
@ -547,7 +547,7 @@ void cdcacm_init(void)
|
|||
{
|
||||
void exti15_10_isr(void);
|
||||
|
||||
serialno_read(serial_no);
|
||||
serial_no_read(serial_no, sizeof(serial_no));
|
||||
|
||||
usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings,
|
||||
sizeof(usb_strings)/sizeof(char *),
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
CROSS_COMPILE ?= arm-none-eabi-
|
||||
SERIAL_NO ?= 1
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
|
||||
INCLUDES = -I../libopencm3/include
|
||||
|
||||
CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM
|
||||
CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DSERIAL_NO=$(SERIAL_NO) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM
|
||||
|
||||
LINKER_SCRIPT="platforms/tm4c/tm4c.ld"
|
||||
LDFLAGS = -nostartfiles -lc $(CPU_FLAGS) -nodefaultlibs -T$(LINKER_SCRIPT) -Wl,--gc-sections \
|
||||
|
|
|
@ -118,20 +118,20 @@ const char *platform_target_voltage(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *serialno_read(char *s)
|
||||
char *serial_no_read(char *s, int max)
|
||||
{
|
||||
/* FIXME: Store a unique serial number somewhere and retreive here */
|
||||
uint32_t unique_id = 1;
|
||||
uint32_t unique_id = SERIAL_NO;
|
||||
int i;
|
||||
|
||||
/* Fetch serial number from chip's unique ID */
|
||||
for(i = 0; i < 8; i++) {
|
||||
s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0';
|
||||
}
|
||||
for(i = 0; i < 8; i++)
|
||||
for(i = 0; i < max - 1; i++)
|
||||
if(s[i] > '9')
|
||||
s[i] += 'A' - '9' - 1;
|
||||
s[8] = 0;
|
||||
s[max] = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -19,32 +19,27 @@
|
|||
*/
|
||||
#include "general.h"
|
||||
|
||||
char *serialno_read(char *s)
|
||||
char *serial_no_read(char *s, int max)
|
||||
{
|
||||
#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4)
|
||||
volatile uint16_t *uid = (volatile uint16_t *)DESIG_UNIQUE_ID_BASE;
|
||||
#if defined(STM32F1)
|
||||
/* Only STM32F103 has no DFU Bootloader. Generate a ID comatible
|
||||
* with the BMP Bootloader since ages.
|
||||
*/
|
||||
uint32_t *unique_id_p = (uint32_t *)DESIG_UNIQUE_ID_BASE;
|
||||
uint32_t unique_id = *unique_id_p +
|
||||
*(unique_id_p + 1) +
|
||||
*(unique_id_p + 2);
|
||||
snprintf(s, max, "%08" PRIX32, unique_id);
|
||||
#else
|
||||
/* Use the same serial number as the ST DFU Bootloader.*/
|
||||
uint16_t *uid = (uint16_t *)DESIG_UNIQUE_ID_BASE;
|
||||
# if defined(STM32F4)
|
||||
int offset = 3;
|
||||
# elif defined(STM32L0) || defined(STM32F4)
|
||||
# elif defined(STM32L0) || defined(STM32F3)
|
||||
int offset = 5;
|
||||
#endif
|
||||
sprintf(s, "%04X%04X%04X",
|
||||
# endif
|
||||
snprintf(s, max, "%04X%04X%04X",
|
||||
uid[1] + uid[5], uid[0] + uid[4], uid[offset]);
|
||||
#else
|
||||
volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8;
|
||||
uint32_t unique_id = *unique_id_p +
|
||||
*(unique_id_p + 1) +
|
||||
*(unique_id_p + 2);
|
||||
int i;
|
||||
|
||||
/* Fetch serial number from chip's unique ID */
|
||||
for(i = 0; i < 8; i++) {
|
||||
s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0';
|
||||
}
|
||||
for(i = 0; i < 8; i++)
|
||||
if(s[i] > '9')
|
||||
s[i] += 'A' - '9' - 1;
|
||||
s[8] = 0;
|
||||
|
||||
#endif
|
||||
return s;
|
||||
|
|
Loading…
Reference in New Issue