Why am I receiving a XCP Internal timeout error when starting External Mode on an STM32 Board using the "Embedded Coder Support Package for STMicroelectronics STM32 Processors"?

122 views (last 30 days)
I am using the MATLAB R2023a with the "Embedded Coder Support Package for STMicroelectronics STM32 Processors".
I am trying to deploy my model using the external mode, also known as "Monitor & Tune". However, Simulink keeps returning the following error:
Connecting to the target...
    Error:External Mode Open Protocol Connect command failed
    Caused by:
        Could not connect to target application: XCP internal error: timeout expired, in response to XCP CONNECT command
 
My model has the following code generation settings:
  • Hardware board STM32F4xx Based
  • Connectivity: USART3, COM3
  • External Mode Communication Interface: Serial
I configured the STM32CubeMX project for the Simulink Model as shown in the documentation linked below: Serial Configuration for Monitor & Tune and PIL for STM32 Processor-Based Boards
I can see in Device Manager that the USB to UART converter is detected at the COM3 port. I have confirmed that COM3 settings on my PC (baudrate, parity etc.) are set just like in the STM32CubeMX USART3 configuration.
I noticed that if my Simulink model uses USART2, communication, External Mode executes without error. When I use USART3, External Mode errors every time.
Also, if I create a new IOC file, and set this as the STM32CubeMX project of the model, External Mode seems to work fine.
Why is Simulink unable to connect for External Mode?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Dec 2023

For timeout errors with USART:

Simulink is unable to connect due to a faulty function caller order in the IOC file.
In USART, DMA is being used. This means DMA initialization must execute before the initialization of any USART to make the peripherals work as expected. If USART is initialized before DMA, this issue can occur. Please follow the below steps to work around this issue:
1) Open the IOC file associated with the Simulink model you want to execute in STM32CubeMX.
2) Go to the Project Manager > Advanced Settings tab. Ensure that “MX_DMA_Init” executes before any LPUART initialization calls.
In this case, since only USART3 fails to send data, ensure “MX_DMA_Init” executes before “MX_USART3_USART_Init”.
3) Save the IOC file. Return to the Simulink model associated with the IOC file and click “Monitor & Tune” to verify External Mode is working.
Please see the picture below comparing the function call order of a faulty IOC file "STM32_external_doesnotwork.ioc" and a working IOC file "STM32_external_doesnotwork.ioc":
Tip: Use right-click > "Open image in new tab" to see the picture in full size

For timeout errors with LPUART:

The same issue with the IOC file can cause External mode to fail with LPUART as well. For example, a faulty IOC file may initialize LPUART before DMA as in the screenshot below:
Alt Text: The picture shows the IOC project "NucleoG491RE_LPUART.ioc" open in STM32CubeMX. The Project Manager > Advanced Settings tab is open. Function call "MX_LPUART1_UART_Init" is listed above “MX_DMA_Init".
This will cause the same timeout error. To resolve this error, ensure that the STM32CubeMX project executes “MX_DMA_Init” before initializing any LPUART ports, as in the screenshot below:
Alt Text: The picture shows the IOC project "NucleoG491RE_LPUART.ioc" open in STM32CubeMX. The Project Manager > Advanced Settings tab is open. Function call "MX_LPUART1_UART_Init" is now listed below “MX_DMA_Init".

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!