Skip to main content
SPrak.4
Associate II
September 20, 2019
Solved

Code generated with errors

  • September 20, 2019
  • 12 replies
  • 4190 views

I use STM32 Nucleo f429zi. I tried to replicate the application on the following link, and followed all the steps. I use USART3 with pins PD8 and PD9 (the manual says these pins are connected to ST-Link)

https://www.youtube.com/watch?v=grgNXdkmzzQ

I use STM Cube IDE. On STM Cude IDE -> there is Debug option to flash the code on Board. However, when I try to Debug - there are errors generated in the app_x-cube-ai.c file.

void MX_X_CUBE_AI_Process(void)
{
 aiValidationProcess();
 /* USER CODE BEGIN 1 */
	int nb_run = 20;
 int res;
 
 /* Example of definition of the buffers to store the tensor input/output */
 /* type is dependent of the expected format */
 AI_ALIGNED(4)
 static ai_i8 in_data[AI_IMAGECLASSIFICATION_IN_1_SIZE_BYTES];
 
 AI_ALIGNED(4)
 static ai_i8 out_data[AI_IMAGECLASSIFICATION_OUT_1_SIZE_BYTES];
 
 /* Retrieve format/type of the first input tensor - index 0 */
 const ai_buffer_format fmt_ = AI_BUFFER_FORMAT(&ai_input[0]); // ai_input undeclared
 const uint32_t type_ = AI_BUFFER_FMT_GET_TYPE(fmt_);
 
 /* Prepare parameters for float to Qmn conversion */
 const ai_i16 N_ = AI_BUFFER_FMT_GET_FBITS(fmt_);
 const ai_float scale_ = (0x1U << N_);
 const ai_i16 M_ = AI_BUFFER_FMT_GET_BITS(fmt_)
 - AI_BUFFER_FMT_GET_SIGN(fmt_) - N_;
 const ai_float max_ = (ai_float)(0x1U << M_);
 
 /* Perform nb_rub inferences (batch = 1) */
 while (--nb_run) {
 
 /* ---------------------------------------- */
 /* Data generation and Pre-Process */
 /* ---------------------------------------- */
 /* - fill the input buffer with random data */
 for (ai_size i=0; i < AI_IMAGECLASSIFICATION_IN_1_SIZE; i++ ) {
 
 /* Generate random data in the range [-1, 1] */
 ai_float val = 2.0f * (ai_float)rand() / (ai_float)RAND_MAX - 1.0f; // RAND_MAX undeclared
 
 /* Convert the data if necessary */
 if (type_ == AI_BUFFER_FMT_TYPE_FLOAT) {
 ((ai_float *)in_data)[i] = val;
 } else { /* AI_BUFFER_FMT_TYPE_Q */
 /* Scale the values in the range [-2^M, 2^M] */
 val *= max_;
 /* Convert float to Qmn format */
 const ai_i32 tmp_ = AI_ROUND(val * scale_, ai_i32); // expected expression before ai_132
 in_data[i] = AI_CLAMP(tmp_, -128, 127, ai_i8); // expected expression before ai_i8
 }
 }
 
 /* Perform the inference */
 res = aiRun(in_data, out_data);
 if (res) {
 // ...
 return;
 }
 
 /* Post-Process - process the output buffer */
 // ...
 }
 /* USER CODE END 1 */
}

Eventhough I got these error. I tried to validate on target, just to see what happens. I selected COM PORT 3 (COM 3 and COM 4 were the available options) with baud rate 115200. I got error "No board connected or invalid firware or restart board". I tried with COM port 4, but got the same error.

Could someone please help me out and let me know as to what is going wrong here.

Thanks in advance

This topic has been closed for replies.
Best answer by fauvarque.daniel

I recommend to remove all the files in the generated project except the .ioc and restart the code generation.

Or you can use the auto compilation inside X-Cube-AI

Regards

Daniel

12 replies

fauvarque.daniel
ST Employee
September 20, 2019

This message is generated when STM32Cubeprogrammer can't connect to the target.

I recommend launching STM32Cubeprogrammer and do a firmware upgrade of the STLink on the board.

Regards

Daniel

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

Thank you for the response. However, for other projects I can see the code getting flashed to the target and also debug the output (using USART3).

Only for this particular AI project I get an error.

fauvarque.daniel
ST Employee
September 20, 2019

X-Cube-AI uses STM32CubeProgramer to flash on the target and to list the target connected to the machine.

Please try to connect to the board using STM32Cubeprogramer, and if it can't connect, upgrade the STLink.

As far as I know STM32CubeProgramer sometime requires to have a recent version of the firmware.

It may work with your favorite IDE but not with STM32Cubeprogramer.

Regards

Daniel

fauvarque.daniel
ST Employee
September 20, 2019

As a side note I notice that you made several generation of the project once with the template application and once with the validation application.

In STM32CubeMX what is generated under the tags USER CODE BEGIN and END is never removed.

The template application is just a generation to show you how to launch the inference. We put it in an User section as you are supposed to replace it with your real code.

When doing automatic validation on the target, a separated project is always generated so this multiple generation won't hurt.

Regards

Daniel

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

I am using STM32CubeProgrammer with the latest firmware upgrade. Even then the code generated automatically has errors in it. Because of that the debug shows errors and the code is not flashed to the target.

Validate on target still shows "No connected board or invalid firmware or restart the board"

fauvarque.daniel
fauvarque.danielBest answer
ST Employee
September 20, 2019

I recommend to remove all the files in the generated project except the .ioc and restart the code generation.

Or you can use the auto compilation inside X-Cube-AI

Regards

Daniel

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

Thank you for the help Daniel, This solution indeed solved the problem of errorsin auto generated code.

However, the validate on target still shows the same error, eventhough I use STMCubeProgrammer and latest firware upgraded. Does this have something to do with the COM port selection ? I tried both automatic and manual selection, but with no success

fauvarque.daniel
ST Employee
September 20, 2019

You can connect a pseudo terminal (putty) on the com port and verify that you have a message after reset.

In the MX configuration, you can also check that the USART3 is configured as Asynchronous, 115200, 8 bits no parity.

You can also see in the device manager the COM port assigned to the ST-Link and use directly this COM port in the X-Cube-AI UI

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

I tried the same. Selected the correct baud rate, com port and other configuration as you mentioned. Still validation on target shows the same error.

While using putty, i see no output received on the com port

fauvarque.daniel
ST Employee
September 20, 2019

and I suppose you closed the putty before launching the validation on the target on the PC (on windows only one application can access a com port at the same time)

fauvarque.daniel
ST Employee
September 20, 2019

When you take the target application in an IDE you can put a breakpoint in the HardFault handler.

If you have an HardFault, you can increase the heap and stack size in the IDE.

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

Yes I did. Still the same error.

But the program got flashed on the board, I could debug the program. However, Validate on Target is not able to identify the board. Once the program has been flashed to the board, should I terminate the execution and then select "Validate on target" or should the IDE be still running the program ?

fauvarque.daniel
ST Employee
September 20, 2019

I guess the code on the target is not correct.

The main should look like that:

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 */

 /* 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 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

   /* USER CODE END WHILE */

 MX_X_CUBE_AI_Process();

   /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

And app_x-cube-ai.c like that

void MX_X_CUBE_AI_Init(void)

{

 MX_UARTx_Init();

 aiValidationInit();

 /* USER CODE BEGIN 0 */

 /* USER CODE END 0 */

}

void MX_X_CUBE_AI_Process(void)

{

   aiValidationProcess();

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

}

with some extra code below to manage multiple networks.

What version of X-Cube-AI are you using ?

SPrak.4
SPrak.4Author
Associate II
September 20, 2019

Am using X-Cube-AI version 4.0.0.

The code I previosuly posted was generated wrong, as I tried application template and validation consecutively. However, based on your advice I regenerated all the files. No my code looks like what you have posted.

I would like to bring it to your point that: the code got compiled with no errors and flashed on board. However validation on target says "no board found"