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

70 views (last 30 days)
I am using 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 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 pages linked below:
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.
Why is Simulink unable to connect for External Mode?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Jul 2024
Edited: MathWorks Support Team on 12 Jul 2024
There could be several issues with the IOC file that lead to the external mode fail:
  1. Incorrect function call order
  2. Incorrect GPIO settings
  3. Unsupported STM32CubeMX version 

1. Incorrect function call order

Timeout errors in Simulink when using USART may be due to an incorrect function call order in the IOC file. Since USART uses DMA, it is crucial that DMA initialization occurs before the initialization of any USART. If USART is initialized before DMA, it can lead to communication issues. Follow these steps to resolve this problem:
  1. Open the IOC file associated with your Simulink model in STM32CubeMX.
  2. Go to the Project Manager > Advanced Settings tab. Ensure that “MX_DMA_Init” executes before any USART initialization calls. For example, when using USART3, ensure that “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 that External Mode works correctly.
Below is a comparison of the function call order in a faulty IOC file (STM32_external_doesnotwork.ioc) and a working IOC file (STM32_external_works.ioc). In this specific case, the call order allowed External Mode to function correctly with USART2, but caused errors when using USART3.
Use right-click > "Open image in new tab" to see the picture in full size
The same issue with the IOC file can occur for boards like the STM32G4xx that require LPUART instead of USART. The picture below shows the IOC file "NucleoG491RE_LPUART.ioc" open in STM32CubeMX where the Function call "MX_LPUART1_UART_Init" is listed above “MX_DMA_Init", which will cause External Mode to fail. To resolve this, ensure that “MX_DMA_Init” executes before initializing any LPUART ports:
Use right-click > "Open image in new tab" to see the picture in full size

2. Incorrect GPIO settings

The hardware board has USART pins connected to ST-LINK. To run the model in External mode without the need for an external FTDI, ensure to configure the GPIO settings for USART. For more information on USART pins connected to the ST-LINK, refer to the respective board's schematic diagram.
For example, on the STM32F7xx, the PD8 and PD9 pins are connected to STLK_RX and STLK_TX in the hardware. Refer to the image below: 
If you incorrectly configured the PB10 and PB11 pins as USART3_TX and USART3_RX, respectively, which are not connected to the STLK_RX and STLK_TX, the power cable cannot transfer USART3 data via serial. To resolve this, go to Pinout & Configuration > Connectivity > USARTX and select the "GPIO Settings" tab.
Use right-click > "Open image in new tab" to see the picture in full size
If these USART pins cannot be changed to PD8 and PD9, an external FTDI connector needs to be used. Refer to the following link for details regarding the same: https://microcontrollerslab.com/uart-usart-communication-stm32f4-discovery-board-hal-uart-driver/

3. Unsupported STM32CubeMX version 

As of R2024a, we currently support STM32CubeMX 6.4.0, and all of the provided peripheral and target support has been tested on this version of CubeMX. Using a newer CubeMX version may lead to unexpected failures as it has not been thoroughly tested by us yet.

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!