summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDave Hylands <dhylands@gmail.com>2015-10-29 09:03:10 -0700
committerDamien George <damien.p.george@gmail.com>2015-10-30 12:53:14 +0000
commitb83d0b35e9b86424b997ef1ccf50e2d2a9659fcf (patch)
treec850772e6fcb879c986ec4bc28c8412ad9f78859
parent823a961ecc4c4b3ed31c18676619e8cd595756cf (diff)
downloadmicropython-b83d0b35e9b86424b997ef1ccf50e2d2a9659fcf.tar.gz
micropython-b83d0b35e9b86424b997ef1ccf50e2d2a9659fcf.zip
stmhal: Add define for UNIQUE_ID address (differs per MCU)
-rw-r--r--stmhal/modmachine.c3
-rw-r--r--stmhal/mphal.h10
-rw-r--r--stmhal/usbd_desc.c6
3 files changed, 17 insertions, 2 deletions
diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c
index b452e223ec..fa6a1f9ddc 100644
--- a/stmhal/modmachine.c
+++ b/stmhal/modmachine.c
@@ -38,13 +38,14 @@
#include "pin.h"
#include "timer.h"
#include "usb.h"
+#include MICROPY_HAL_H
// machine.info([dump_alloc_table])
// Print out lots of information about the board.
STATIC mp_obj_t machine_info(mp_uint_t n_args, const mp_obj_t *args) {
// get and print unique id; 96 bits
{
- byte *id = (byte*)0x1fff7a10;
+ byte *id = (byte*)MP_HAL_UNIQUE_ID_ADDRESS;
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]);
}
diff --git a/stmhal/mphal.h b/stmhal/mphal.h
index 83b28d8d7e..bafee7b13d 100644
--- a/stmhal/mphal.h
+++ b/stmhal/mphal.h
@@ -1,6 +1,16 @@
// We use the ST Cube HAL library for most hardware peripherals
#include STM32_HAL_H
+// The unique id address differs per MCU. Ideally this define should
+// go in some MCU-specific header, but for now it lives here.
+#if defined(MCU_SERIES_F4)
+#define MP_HAL_UNIQUE_ID_ADDRESS (0x1fff7a10)
+#elif defined(MCU_SERIES_F7)
+#define MP_HAL_UNIQUE_ID_ADDRESS (0x1ff0f420)
+#else
+#error mphal.h: Unrecognized MCU_SERIES
+#endif
+
// Basic GPIO functions
#define GPIO_read_pin(gpio, pin) (((gpio)->IDR >> (pin)) & 1)
#if defined(MCU_SERIES_F7)
diff --git a/stmhal/usbd_desc.c b/stmhal/usbd_desc.c
index a3f1a7bc1b..32e4fd0438 100644
--- a/stmhal/usbd_desc.c
+++ b/stmhal/usbd_desc.c
@@ -33,6 +33,10 @@
#include "usbd_desc.h"
#include "usbd_conf.h"
+// need these headers just for MP_HAL_UNIQUE_ID_ADDRESS
+#include "py/misc.h"
+#include MICROPY_HAL_H
+
// So we don't clash with existing ST boards, we use the unofficial FOSS VID.
// This needs a proper solution.
#define USBD_VID 0xf055
@@ -169,7 +173,7 @@ STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
//
// See: https://my.st.com/52d187b7 for the algorithim used.
- uint8_t *id = (uint8_t *)0x1fff7a10;
+ uint8_t *id = (uint8_t *)MP_HAL_UNIQUE_ID_ADDRESS;
char serial_buf[16];
snprintf(serial_buf, sizeof(serial_buf),
"%02X%02X%02X%02X%02X%02X",