cancel
Showing results for 
Search instead for 
Did you mean: 

MATLAB/Simulink XCP protocol via LPUART1

JellyFish
Associate II

Hi all,

I failed to run Nucleo-G431RB board using Simulink "Monitor & Tune" mode via Simulink XCP protocol.

I've got the error message at Simulink,
"Could not connect to target application: XCP internal error: timeout expired, in response to XCP CONNECT command"

There has been no problem for Simulink "Build, Deploy & Start".

I followed an example from the link below.
https://www.mathworks.com/help/ecoder/stmicroelectronicsstm32f4discovery/ug/STM32F4XX-ADC-example.html

I've already changed Simulink model configuration to run Nucleo-G431RB LPUART.
- Hardware board = STM32G4xx Based
- Hardware board settings> Build options> Create> Select hardware = NUCLEO-G431RB
- Connectivity > USART/UART = LPUART1
- Connectivity > Serial port = COM1 (same port for STMicroelectronics STLink Virtual COM Port)

MATLAB related version:
- MATLAB 2023a
- Embedded Coder Support Package for ARM Cortex-M Processors V23.1.0
- Embedded Coder Support Package for STMicroelectronics STM32 Processors V23.1.3

STM32 related version:
- STM32CubeMX V.6.4.0
- STM32Cube_FW_G4_V1.5.1


I've read the similar post below, but couldn't figure out what was the problem.
https://community.st.com/t5/stm32-mcus-products/nucleo-g491re-communication-error-with-matlab-simulink-xcp/td-p/82065

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
STTwo-32
ST Employee

Hello @JellyFish and welcome to the ST Community.

For support on MATLAB/Simunlink, i suggest you to use the MATLAB Community https://www.mathworks.com/matlabcentral/content/communities.html.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
JellyFish
Associate II

Let me attach the ioc and Simulink files.

STTwo-32
ST Employee

Hello @JellyFish and welcome to the ST Community.

For support on MATLAB/Simunlink, i suggest you to use the MATLAB Community https://www.mathworks.com/matlabcentral/content/communities.html.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

JellyFish
Associate II

Thanks for the reply.

 

For the others who might go through similar problems,
This issue was solved by changing the order of Generated function call at STM32CubeMX.
"MX_DMA_Init" should be ahead of "MX_LPUART1_UART_Init".

 

 

MATLAB say the same but backwards bro~

 

Better be helpful and attend your audicence instead of send over and over to other provider, your circus your monkeys pal!

I had the same issue with NUCLEO-G474RE trying to make a PIL control. no luck there.

Then I downgrade the project to this one:

https://www.mathworks.com/help/ecoder/stmicroelectronicsstm32f4discovery/ug/Monitor-Tune-example.html

It mentioned the use of USARTx tho...

Still not working, so I jumped from MATLAB 2024a to 202b to 2025a. Still the same, changed cables 4 times, uninstalled/instaled the drivers on Device manager (Windoze 11), use/unuse LPUARTx, put in different directories, changed names to be shorter and without spaces in order to Windoze/MATLAB do not protest, then I followed an infinite number of links on MATLAB:

 

https://www.mathworks.com/matlabcentral/answers/1939784-stm32f407vgt6u-disc1-external-mode-could-not-connect-to-target-application-xcp-internal-error

https://www.mathworks.com/matlabcentral/answers/1762895-external-mode-open-protocol-checkdata-command-failed-error

https://www.mathworks.com/matlabcentral/answers/1939784-stm32f407vgt6u-disc1-external-mode-could-not-connect-to-target-application-xcp-internal-error

https://www.mathworks.com/matlabcentral/answers/2106356-external-mode-open-protocol-checkdata-command-failed

https://www.mathworks.com/matlabcentral/answers/1567058-error-in-simulink-when-using-arduino-uno-for-motor-speed-reading

https://www.mathworks.com/matlabcentral/answers/1850793-simulink-error-while-running-controller-on-hardware-using-arduino

 

And still not working. 

Changed to another board I have (NUCLEO-F334R8), and worked as MATLAB directed.

Again returned to NUCLEO-G474RE, upgraded to the latest firmware for the STLINK-V3E (v3-17-10), still the same with USART1, then I just give it a try again with LPUART1 and it worked.

 

** As it seems after all these amnipulations, for sure the NUCLEO-F334R8 won't work...ya all know!!~

 

The lesson here is: try all, ST and MATLAB won't move a finger for something that should be "plug&play" as promoted.

 

Good luck.