There could be several issues with the IOC file that lead to the external mode fail:
- Incorrect function call order
- Incorrect GPIO settings
- 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:
- Open the IOC file associated with your Simulink model in STM32CubeMX.
- 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”.
- 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
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.