Skip to content

Commit b83d0b3

Browse files
dhylandsdpgeorge
authored andcommitted
stmhal: Add define for UNIQUE_ID address (differs per MCU)
1 parent 823a961 commit b83d0b3

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

stmhal/modmachine.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
#include "pin.h"
3939
#include "timer.h"
4040
#include "usb.h"
41+
#include MICROPY_HAL_H
4142

4243
// machine.info([dump_alloc_table])
4344
// Print out lots of information about the board.
4445
STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
4546
// get and print unique id; 96 bits
4647
{
47-
byte *id = (byte*)0x1fff7a10;
48+
byte *id = (byte*)MP_HAL_UNIQUE_ID_ADDRESS;
4849
printf("ID=%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x\n", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], id[8], id[9], id[10], id[11]);
4950
}
5051

stmhal/mphal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// We use the ST Cube HAL library for most hardware peripherals
22
#include STM32_HAL_H
33

4+
// The unique id address differs per MCU. Ideally this define should
5+
// go in some MCU-specific header, but for now it lives here.
6+
#if defined(MCU_SERIES_F4)
7+
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7a10)
8+
#elif defined(MCU_SERIES_F7)
9+
#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
10+
#else
11+
#error mphal.h: Unrecognized MCU_SERIES
12+
#endif
13+
414
// Basic GPIO functions
515
#define GPIO_read_pin(gpio, pin) (((gpio)->IDR >> (pin)) & 1)
616
#if defined(MCU_SERIES_F7)

stmhal/usbd_desc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "usbd_desc.h"
3434
#include "usbd_conf.h"
3535

36+
// need these headers just for MP_HAL_UNIQUE_ID_ADDRESS
37+
#include "py/misc.h"
38+
#include MICROPY_HAL_H
39+
3640
// So we don't clash with existing ST boards, we use the unofficial FOSS VID.
3741
// This needs a proper solution.
3842
#define USBD_VID 0xf055
@@ -169,7 +173,7 @@ STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
169173
//
170174
// See: https://my.st.com/52d187b7 for the algorithim used.
171175

172-
uint8_t *id = (uint8_t *)0x1fff7a10;
176+
uint8_t *id = (uint8_t *)MP_HAL_UNIQUE_ID_ADDRESS;
173177
char serial_buf[16];
174178
snprintf(serial_buf, sizeof(serial_buf),
175179
"%02X%02X%02X%02X%02X%02X",

0 commit comments

Comments
 (0)