Skip to content

Commit 96ccceb

Browse files
committed
RPC: Configure M4 memory as strongly ordered if booting from SDRAM.
If the Cortex-M4 core is booting from SDRAM, the memory region must be configured as Strongly Ordered. Note that the Cortex-M4 core does not seem to implement speculative prefetching, so there is no need to protect the whole region from speculative prefetching with a second MPU region. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent fa34b9d commit 96ccceb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

libraries/RPC/src/RPC.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,35 @@ int RPCClass::begin() {
163163
#endif
164164

165165
#ifdef CORE_CM4
166+
#if (CM4_BINARY_START >= 0x60000000) && (CM4_BINARY_START < 0xe0000000)
167+
class M4Init {
168+
public:
169+
M4Init() {
170+
// If the Cortex-M4 core is booting from SDRAM, the memory region must be
171+
// configured as Strongly Ordered. Note that the Cortex-M4 core does not
172+
// seem to implement speculative prefetching, so there is no need to protect
173+
// the whole region from speculative prefetching with a second MPU region.
174+
HAL_MPU_Disable();
175+
MPU_Region_InitTypeDef MPU_InitStruct;
176+
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
177+
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
178+
MPU_InitStruct.BaseAddress = CM4_BINARY_START;
179+
MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
180+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
181+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
182+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
183+
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
184+
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
185+
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
186+
MPU_InitStruct.SubRegionDisable = 0x00;
187+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
188+
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
189+
}
190+
};
191+
192+
M4Init __m4init __attribute__ ((init_priority (101)));
193+
#endif
194+
166195
int RPCClass::begin() {
167196
eventThread = new rtos::Thread(osPriorityHigh, 16*1024, nullptr, "rpc_evt");
168197
eventThread->start(&eventHandler);

0 commit comments

Comments
 (0)