Skip to content

Commit 71f09ae

Browse files
committed
Forcefully mark all of SRAM uncachable
1 parent f67a3d5 commit 71f09ae

File tree

1 file changed

+20
-0
lines changed
  • examples/nucleo_h723zg/vl53/vl53l8_spi

1 file changed

+20
-0
lines changed

examples/nucleo_h723zg/vl53/vl53l8_spi/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ modm::Vl53SpiTransport<SpiMaster, Cs, LPn> transport;
4343
int
4444
main()
4545
{
46+
// This is a workaround for Erratum 1259864 on Cortex-M7 r1p1 CPUs. The data
47+
// cache may return garbage data when reading from the SRAM after a write operation.
48+
// https://www.st.com/resource/en/errata_sheet/es0392-stm32h742xig-stm32h743xig-stm32h750xb-stm32h753xi-device-errata-stmicroelectronics.pdf
49+
MPU->CTRL = 0; __DSB();
50+
// Set region 0 to SRAM base address [0x20000000, 0x40000000[ = 29-bits size
51+
MPU->RBAR = 0x20000010;
52+
// Permission register
53+
MPU->RASR = ( 28 << MPU_RASR_SIZE_Pos) | // 2^(28+1) = 0x20000000
54+
(0b001 << MPU_RASR_TEX_Pos) | // Normal memory type, outer and inner non-cachable
55+
( 0b0 << MPU_RASR_S_Pos) | // We only have one CPU, so not necessary to share
56+
( 0b0 << MPU_RASR_C_Pos) | // Non-Cacheable
57+
( 0b0 << MPU_RASR_B_Pos) | // Non-Bufferable
58+
(0b011 << MPU_RASR_AP_Pos) | // Read/Write full access
59+
( 0b0 << MPU_RASR_XN_Pos) | // Allow execution of .fastcode
60+
MPU_RASR_ENABLE_Msk; // Enable region
61+
// Use default memory map, handlers use MPU too
62+
MPU->CTRL = MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_HFNMIENA_Msk | MPU_CTRL_ENABLE_Msk;
63+
// Flush entire memory system
64+
__DSB(); __ISB();
65+
4666
Board::initialize();
4767

4868
Dma1::enable();

0 commit comments

Comments
 (0)