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

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

The log I received on "Validation on Target"

Flashing project 

Build is Done 

Starting AI validation on target with random data... 

Neural Network Tools for STM32 v1.0.0 (AI tools v4.0.0) 

Automatic build and run succeed 

-- Importing model 

-- Importing model - done (elapsed time 0.506s) 

-- Building X86 C-model 

-- Building X86 C-model - done (elapsed time 7.360s) 

-- Setting inputs (and outputs) data 

Using random input, shape=(10, 270) 

-- Running STM32 C-model 

ON-DEVICE STM32 execution ("aimodel", COM4, 115200).. 

LOAD ERROR: STM32 - no connected board(s)or invalid firmware or the board should be re-started

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

I tried to debug something using breakpoints. The neural model was initialized and I received the print "Ready to received a CMD from the Host". After this the code gets stuck is a IF condition that is under the following function

static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)

{

 /* Wait until flag is set */

 while ((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)

 {

  /* Check for the Timeout */

  if (Timeout != HAL_MAX_DELAY)

  {

   if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))

   {

    /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */

    CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));

    CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);

    huart->gState = HAL_UART_STATE_READY;

    huart->RxState = HAL_UART_STATE_READY;

    /* Process Unlocked */

    __HAL_UNLOCK(huart);

    return HAL_TIMEOUT;

   }

  }

 }

 return HAL_OK;

}

The code waits until the flag is SET. Could you let me know what is the cause behind this. I have not entered any code of my own. I just followed the procedure that was given in the video tutorial.

Regards,

Sinduja