Skip to main content
Associate II
Question

STM32N6 - reading from XSPI2 with MCE shows data as unchanged

Hello, I hope everyone’s doing well.

 

 

I have trouble getting the MCE to work on the STM32N6 (my issue is highlighted in bold below). Side note, the AES_256 example doesn’t work for me (on the discovery board).

 

First of all, the configuration in CubeMX makes no sense, when I select AES_256 there should be 8x32 bit values, not 4x32 bit:

 

 

Well, that’s manageable. So I generate the code and this is the first set of relevant code that I slightly modified:

 



MCE_HandleTypeDef hmce1;
__ALIGN_BEGIN static const uint32_t NonceMCE1[2] __ALIGN_END = {
0x00000000,0x00000000};
__ALIGN_BEGIN static const uint32_t pKeyMCE1[8] __ALIGN_END = {
/* my awesome key */ }; // MODIFIED from [4]->[8]


// ....

static void MX_MCE1_Init(void)
{

/* USER CODE BEGIN MCE1_Init 0 */

/* USER CODE END MCE1_Init 0 */

MCE_AESConfigTypeDef ContextAESConfig = {0};

/* USER CODE BEGIN MCE1_Init 1 */

/* USER CODE END MCE1_Init 1 */
hmce1.Instance = MCE1;
if (HAL_MCE_Init(&hmce1) != HAL_OK)
{
Error_Handler();
}
ContextAESConfig.Nonce[0]= NonceMCE1[0];
ContextAESConfig.Nonce[1]= NonceMCE1[1];
ContextAESConfig.Version = 0x0000;
ContextAESConfig.pKey = (uint32_t *)pKeyMCE1;
if (HAL_MCE_ConfigAESContext(&hmce1, &ContextAESConfig, MCE_CONTEXT1) != HAL_OK)
{
Error_Handler();
}
if (HAL_MCE_EnableAESContext(&hmce1, MCE_CONTEXT1) != HAL_OK)
{
Error_Handler();
}
if (HAL_MCE_SetRegionAESContext(&hmce1, MCE_CONTEXT1, MCE_REGION1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN MCE1_Init 2 */

/* USER CODE END MCE1_Init 2 */

}

 

After that, in main, this is essentially what I do:

 

int main(void) {

// HAL_Init() etc

MX_MCE1_Init();
enable_mapped_mode_xspi2();


MCE_RegionConfigTypeDef RegionConfig = {0};

/* Set the MCE Region configuration*/
RegionConfig.Mode = MCE_BLOCK_CIPHER;
RegionConfig.ContextID = MCE_CONTEXT1;
RegionConfig.StartAddress = 0x70080000;
RegionConfig.EndAddress = 0x70080FFF;

if (HAL_MCE_ConfigRegion(&hmce1, 0, &RegionConfig)!= HAL_OK)
{
Error_Handler();
}



uint32_t tmp[8] = {0};
uint32_t *src = 0x70080000;

for(int i = 0; i < sizeof(tmp)/sizeof(*tmp); ++i) {
tmp[i] = *(src + i);
}

MX_LPUART1_UART_Init();
printf("================================\r\n");
printf("%s\r\n", (uint8_t *)tmp);
printf("================================\r\n");
for(int i = 0; i < sizeof(tmp); ++i) {
printf("%x, ", *((uint8_t *)tmp + i));
}
printf("\r\n================================\r\n");


return 0;
}

 

However, my issue is the following: The bytes at address 0x70080000 are read successfully, but as they are in memory. The MCE doesn’t change the values at all. I did change my key from all 0x00’s to something more sophisticated, as noted above.

 

Example, the memory content is: 0x01, 0x02, 0x03, 0x04 (etc.) and the output lists it as the exact same, 0x01, 0x02, 0x03, 0x04 (etc.)

 

 

Thanks in advance for any pointers.

 

Best Regards, R

1 reply

rrrsAuthor
Associate II

Okay, it was somewhat hinted at in the RM, but it’s kinda like so:

 

MCE1 → XSPI1

MCE2 → XSPI2

 

so after I switched MCE2 it worked