2019-09-20 02:43 AM
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
Solved! Go to Solution.
2019-09-20 03:16 AM
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
2019-09-20 02:53 AM
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
2019-09-20 03:04 AM
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.
2019-09-20 03:07 AM
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
2019-09-20 03:11 AM
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
2019-09-20 03:13 AM
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"
2019-09-20 03:16 AM
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
2019-09-20 03:44 AM
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
2019-09-20 04:06 AM
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
2019-09-20 04:07 AM
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.