cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid Initializer and Initializer element is not constant errors in STMCubeAI

akoluacik
Senior

I have obtained a model by using Google Colab and translate it through TF Lite. I could apply validate on target and validate on desktop process and I did not get any error. However, once CubeAI generated related .h files and I used them, I got two errors, the errors are attached.

0693W00000NpyAoQAJ.jpg0693W00000NpyAjQAJ.jpg0693W00000NpyAeQAJ.jpg0693W00000NpyAZQAZ.jpg0693W00000NpyAUQAZ.jpgPlease note that the errors are due to the files that are generated by CubeAI.

Thx for your responses.

11 REPLIES 11
CBapt.2
Associate II

Hey, I had the same problem. The error occured when running this code:

ai_network_params ai_params ={
		AI_CLASSIFYSPEED_DATA_WEIGHTS(ai_MODELNAME_data_weights_get()),
		AI_CLASSIFYSPEED_DATA_ACTIVATIONS(activations)
	};

The problem was that the code was not inside a function, which means it has to be an initializer - which is assigned only when the item is declared - which means it must be a constant value at compile time!

So to solve the issue I just put the code above inside a function!

I hope it helps!

RU.1
Associate

Hi CBabt.2,

I encountered the exact same issue as described above and I am trying to figure out how to implement your solution to the problem. Could you please elaborate bit more on how to wrap the above code inside a function.

Thanks in advance

Best

R

CBapt.2
Associate II

Hey RU.1,

the problem occured in my case because I tried to run the code from my first post outside of a function. To fix the error i created a function and ran the code in there. That fixed the issue. I hope you understand what I mean. Ill post a code snippet to clarify.

/*
 * Test.c
 *
 *  Created on: Jun 20, 2022
 *      Author: Cbapt
 * 
 */
// The error occurs when you try to call the code from the first post outside of a c function
 
// The following Code shows the error
 
// Outside Funktion Call --> Causes Initializer Error! 
ai_network_params ai_params ={
		AI_CLASSIFYSPEED_DATA_WEIGHTS(ai_classifyspeed_data_weights_get()),
		AI_CLASSIFYSPEED_DATA_ACTIVATIONS(activations)
	};
 
 
//This fixed it --> Just create a function around the call
ai_error AI_INIT(void)
{
 
	ai_network_params ai_params ={
		AI_CLASSIFYSPEED_DATA_WEIGHTS(ai_classifyspeed_data_weights_get()),
		AI_CLASSIFYSPEED_DATA_ACTIVATIONS(activations)
	};
 
}

I hope it helps.

Best Regards,

cbapt

Thanks a lot for your rapid response!! Unfortunately this this approach wont fix my code. Part of the issue is that ai_params is being used outside the scope of the function. Also the error mentioned above remains (invalid initializer). Would you mind to share the entire code of your main.c?

Best

R.

CBapt.2
Associate II

Hey,

Im really sorry but I cant share the full main.c with you due to copyright issues. I can recommend you to work with the documentation of x-cube-ai to get a minimal application running, that worked for me the best.

Best regards,

cbapt

akoluacik
Senior

My problem was because STM32CubeIDE somehow didn't adjust the compiler and linker settings so linking process didn't work correctly. After it was adjusted manually, it worked fine.

Hello could you please explain how you solved it? I don't know how to adjust the compiler and linker settings to fix this. Thank you!

akoluacik
Senior

As I mentioned, the problem is STM32CubeIDE somehow didn't adjust the compiler and linker settings. Once you compile the code, the compiler cannot find the header and source file of XCUBEAI. Therefore, you need to say to compiler that these files are actually source files. You can this by following Right click your project name -> Properties -> C/C++ General -> Paths and Symbols -> Includes(TAB). You than add source files by clicking Add->Workspace buttons.

After that, Right click your project name -> Properties -> C/C++ Build -> MCU GCC Linker -> Libraries, add NetworkRuntime720_CM7_GCC.a here, which can be found under Middlewares -> ST -> Lib directory.

0693W00000SuRBFQA3.png0693W00000SuRBKQA3.png 

Those images might help you to find the tabs and files to be added. Hope this helps.

Hello, I've just added a new answer. Please look at it and select as best if it helps.

Good luck.