2021-03-12 09:53 AM
I'm using a Nucleo-144 and have not been able to get X-CUBE-AI working in TrustZone. I'm using STM32CubeIDE and trying to add X-CUBE-AI with the software component manager (with the integrated STM32CubeMX).
Interestingly, before a recent update (so STM32CubeIDE 1.5.1, STM32L5 package version 1.3.1, and I think STM32CubeMX 6.1.1), adding X-CUBE-AI wasn't even an option in the component manager with TrustZone applications, I just tried to manually add the code but it would hang once it entered the X-CUBE-AI library (NetworkRuntime520_CM33_GCC.a). After an update (STM32Cube IDE 1.6.0, STM32L5 package version 1.4.0, and STM32CubeMX 6.2.0) it's an option in the component manager but STM32CubeMX fails to generate the code (FreeMarker template error).
Anyways, I'm just wondering if there are any known reasons why X-CUBE-AI should or shouldn't work in a TrustZone application. It's hard to tell if the component "support" in the latest version was on accident or if there's just a bug in the code generation.
Solved! Go to Solution.
2021-03-15 01:21 AM
With X-Cube-AI 6.0.0 (just released) combined with STM32CubeMX 6.2 you'll be able to activate X-Cube-AI with trustzone and generate correctly the code.
Previous versions of X-Cube-AI or STM32CubeMX won't allow you to generate X-CUBE-AI projects with trustzone
Regards
Daniel
2021-03-15 01:21 AM
With X-Cube-AI 6.0.0 (just released) combined with STM32CubeMX 6.2 you'll be able to activate X-Cube-AI with trustzone and generate correctly the code.
Previous versions of X-Cube-AI or STM32CubeMX won't allow you to generate X-CUBE-AI projects with trustzone
Regards
Daniel
2021-03-15 02:03 AM
Hello @XRaye
Thanks for your feedback,
Yes, the Cube-AI pack is supported on L5 with Trust zone Enable, could you please re-check if the problem linked to CubeMX still occurs? (thanks @fauvarque.daniel for sharing the details about the new Cube version)
Khouloud
2021-03-17 11:23 AM
Hi @Khouloud ZEMMELI
I appreciate the responses. I reinstalled the X-CUBE-AI software pack (it actually forced me to for some reason), and it now properly generates the required files (I no longer see the FreeMarker template errors).
Unfortunately, now it hangs on ai_platform_network_create when running on the Nucleo-144, I believe this is the first call into the X-CUBE-AI library. I removed the X-CUBE-AI component from the Secure world and added it to the NonSecure world in the same application, and it runs just fine. I tried to put it back in the Secure world again, but it hangs in the same spot. This is actually the same behavior I observed when I tried to manually add the library to a Secure application back in the previous version before it was supported, but I'm not sure if that's a coincidence.
2021-03-18 12:46 AM
for the X-CUBE-AI library to work correctly we need to have the CRC IP activated on the same context.
Normally this is done automatically in STM32CubeMX when selecting X-CUBE-AI on one context or this other but it is worth verifying that CRC and X-CUBE-AI are actually on the same context
Regards
Daniel
2021-03-18 11:34 AM
I learned about the CRC dependency when I tried to get it working in the previous version, but I double checked and confirmed the current version of CubeMX is doing it automatically (for both secure and non-secure context). As a sanity check I tried it again in both the secure and non-secure world with a different model, and it is still only working in the non-secure world.
To clarify, I am just using the Application Template in the software pack component selector, I am not changing anything other than the printf function. Do you know if X-CUBE-AI in the secure world has been tested or confirmed working?
2021-03-18 12:13 PM
Yes I confirm that there is an issue when running X-Cube-AI in the secured context.
I'll let you know when it has been fixed
2021-03-18 12:24 PM
Ok, thank you for the help.
2021-03-19 07:29 AM
The workaround to the issue is to put the CRC IP in the non secured world
The L5 will start in secured mode, jump to the non secured world by calling NonSecure_Init(); at the end of the main()
the NonSecure_Init(); never returns so the code after is never executed.
To be able to run AI you'll have to then:
CMSE_NS_ENTRY void SECURE_X_Cube_AI_Process() {
MX_X_CUBE_AI_Process();
}
void SECURE_X_Cube_AI_Process();
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_CRC_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
SECURE_X_Cube_AI_Process();
}
/* USER CODE END 3 */
}
Hope it helps
Regards
Daniel
2021-03-19 09:06 AM
Perfect. Putting the CRC IP in the non-secure world and calling the X-CUBE-AI related functions (MX_X_CUBE_AI_Init and MX_X_CUBE_AI_Process) from secure_nsc.c worked. Thank you again for the help.