2021-05-11 03:45 AM
Help! I am trying to port CubeAI from an STMCubeMX generated demo (System Performance) to a production app, but the call to ai_platform_network_create never returns.
I can see the code is stuck in the function CRC_Lock but this is internal to the pre-compiled library so I do not know what it is trying to do.
I have the CRC initialised by MX_CRC_Init which contains identical code generated by my Cube reference code and although there are very few difference between the demo code and my production code I feel that I must be missing something which is preventing the AI libs from running smoothly.
The demo code runs beautifully on my target hardware so it is not hardware related. The production code also runs on my target hardware, but only if I comment out the attempts to initialise my ML models.
I've checked Stack, Heap, memory locations, clock configurations etc. everything I can think of is setup very similarly if not identically to the demo code.
Can anyone shed any light on what the AI library requires to be set up for it (and how)? I thought I read somewhere that all it needs is clocks configured but maybe there is something else...
Jonathan
2021-05-11 04:57 AM
Sounds like the CRC is not initialized correctly in your code.
The network runtime library needs the CRC to be activated in order to function correctly.
you should call a function like this one in your main:
static void MX_CRC_Init(void)
{
/* USER CODE BEGIN CRC_Init 0 */
/* USER CODE END CRC_Init 0 */
/* USER CODE BEGIN CRC_Init 1 */
/* USER CODE END CRC_Init 1 */
hcrc.Instance = CRC;
if (HAL_CRC_Init(&hcrc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CRC_Init 2 */
/* USER CODE END CRC_Init 2 */
}
Typically the sequence generated in the main by MX is
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CRC_Init();
MX_X_CUBE_AI_Init();
/* USER CODE BEGIN 2 */
Regards
2021-05-11 05:28 AM
Many thanks for the prompt response, I had the same thought so I reviewed the CRC initialisation code and I do have the MX_CRC_Init function and it is being called before MX_X_CUBE_AI_Init in the startup sequence...
... however, I discovered that there was no call to __HAL_RCC_CRC_CLK_ENABLE() so thank you, your post helped me zone in on the problem.
I note that in the AI reference code (System Performance) that the CRC clock is enabled in aiTestUtility.c, function crcIpInit() called from systemSettingLog().
I wonder if the advice from ST on porting AI to your project would be to port this function, or whether it would be better to enable the CRC clocks as part of the main.c startup sequence
Anyway, thank you for helping with my issue
Jonathan
2021-05-11 05:36 AM
Currently it is simpler to start the CRC (and clock it) at the beginning.
We have some background low priority task to be smarter with CRC and just enable it when we need it without overwriting any set done in the main application. It won't be done in the next release but probably at some point in the future.