|
| 1 | +// Copyright (c) 2024 Arduino SA |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
1 | 3 | #include "RPC.h"
|
2 | 4 |
|
3 | 5 | #define ENDPOINT_ID_RAW 0
|
@@ -161,6 +163,35 @@ int RPCClass::begin() {
|
161 | 163 | #endif
|
162 | 164 |
|
163 | 165 | #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 | + |
164 | 195 | int RPCClass::begin() {
|
165 | 196 | eventThread = new rtos::Thread(osPriorityHigh, 16*1024, nullptr, "rpc_evt");
|
166 | 197 | eventThread->start(&eventHandler);
|
|
0 commit comments