Skip to content

Commit f083604

Browse files
KooLruvirtual-maker
authored andcommitted
Fix hwUniqueID and EEPROM
Fix hwUniqueID on STMF4. Speedup EEPROM write.
1 parent 51fdde4 commit f083604

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

hal/architecture/STM32/MyHwSTM32.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,29 @@ bool hwInit(void)
4747

4848
void hwReadConfigBlock(void *buf, void *addr, size_t length)
4949
{
50+
//MY_SERIALDEVICE.println(F("START hwReadConfigBlock"));
5051
uint8_t *dst = static_cast<uint8_t *>(buf);
5152
int offs = reinterpret_cast<int>(addr);
53+
54+
eeprom_buffer_fill();
5255
while (length-- > 0) {
53-
*dst++ = EEPROM.read(offs++);
56+
*dst++ = eeprom_buffered_read_byte(offs++);
5457
}
58+
//MY_SERIALDEVICE.println(F("END hwReadConfigBlock"));
5559
}
5660

5761
void hwWriteConfigBlock(void *buf, void *addr, size_t length)
5862
{
63+
//MY_SERIALDEVICE.println(F("START hwWriteConfigBlock"));
5964
uint8_t *src = static_cast<uint8_t *>(buf);
6065
int offs = reinterpret_cast<int>(addr);
66+
6167
while (length-- > 0) {
62-
EEPROM.write(offs++, *src++);
68+
eeprom_buffered_write_byte(offs++, *src++);
6369
}
70+
//MY_SERIALDEVICE.println(F("START FLUSH"));
71+
eeprom_buffer_flush();
72+
//MY_SERIALDEVICE.println(F("END hwWriteConfigBlock"));
6473
}
6574

6675
uint8_t hwReadConfig(const int addr)
@@ -110,7 +119,11 @@ int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t inte
110119

111120
bool hwUniqueID(unique_id_t *uniqueID)
112121
{
113-
(void)memcpy((uint8_t *)uniqueID, (uint32_t *)0x1FFFF7E0, 16); // FlashID + ChipID
122+
//Fill ID with FF
123+
(void)memset((uint8_t *)uniqueID, 0xFF, 16);
124+
//Read device ID
125+
(void)memcpy((uint8_t *)uniqueID, (uint32_t *)UID_BASE, 12);
126+
114127
return true;
115128
}
116129

hal/architecture/STM32/MyHwSTM32.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include <IWatchdog.h>
2424
#include <itoa.h>
25-
#include <EEPROM.h>
2625
#include <SPI.h>
2726

2827
#ifdef __cplusplus
@@ -32,7 +31,11 @@
3231
#define CRYPTO_LITTLE_ENDIAN
3332

3433
#ifndef MY_SERIALDEVICE
35-
#define MY_SERIALDEVICE Serial
34+
#if SERIAL_UART_INSTANCE == 2 //On Nucleo board UART 2 connect to ST-LINK
35+
#define MY_SERIALDEVICE Serial2
36+
#else
37+
#define MY_SERIALDEVICE Serial
38+
#endif
3639
#endif
3740

3841
#ifndef MY_DEBUGDEVICE

0 commit comments

Comments
 (0)