Skip to content

Commit 4da1db7

Browse files
committed
stm32h5/hw_id: Disable cache when reading ID
System Memory is not cacheable. When access device ID system caches are temporarily disabled. Other option would be to configure MPU with attributes OUTER_SHAREABLE, NO_CACHE, DEVICE_nGnRE Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
1 parent d5b30ca commit 4da1db7

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

hw/mcu/stm/stm32_common/src/stm32_hw_id.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
#include "mcu/stm32_hal.h"
2424
#include <hal/hal_bsp.h>
2525

26+
#ifdef STM32H5
27+
#include <stm32h5xx_ll_dcache.h>
28+
#include <stm32h5xx_ll_icache.h>
29+
#endif
30+
2631
#ifndef min
2732
#define min(a, b) ((a)<(b)?(a):(b))
2833
#endif
@@ -35,13 +40,40 @@ hal_bsp_hw_id_len(void)
3540
return STM32_HW_ID_LEN;
3641
}
3742

43+
#ifndef DCACHE1
44+
/* H503 devices do not have DCACHE */
45+
#define LL_DCACHE_IsEnabled(dcache) 0
46+
#define LL_DCACHE_Enable(dcache)
47+
#define LL_DCACHE_Disable(dcache)
48+
#endif
49+
3850
int
3951
hal_bsp_hw_id(uint8_t *id, int max_len)
4052
{
4153
int cnt;
54+
#ifdef STM32H5
55+
uint32_t dcache_enabled = LL_DCACHE_IsEnabled(DCACHE1);
56+
uint32_t icache_enabled = LL_ICACHE_IsEnabled();
57+
58+
if (dcache_enabled) {
59+
LL_DCACHE_Disable(DCACHE1);
60+
}
61+
if (icache_enabled) {
62+
LL_ICACHE_Disable();
63+
}
64+
#endif
4265

4366
cnt = min(STM32_HW_ID_LEN, max_len);
4467
memcpy(id, (void *)UID_BASE, cnt);
4568

69+
#ifdef STM32H5
70+
if (icache_enabled) {
71+
LL_ICACHE_Enable();
72+
}
73+
if (dcache_enabled) {
74+
LL_DCACHE_Enable(DCACHE1);
75+
}
76+
#endif
77+
4678
return cnt;
4779
}

0 commit comments

Comments
 (0)