How to change the baud rate for STM32F4 Discovery boards running in External Mode?

12 views (last 30 days)
While running the Parametric Audio Equalizer example on Discovery STM32F4 board in external mode, the spectrum analyzer update is very slow. I believe this is due to communication between the host and target. But, I do not see the option to change the baud rate in the Configuration Parameters.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Jul 2016
There is a bottleneck in communication between host and target during External Mode simulation due to which the data update in the Spectrum Analyzer is very slow. This is because the real time processing occurs on the hardware and the data for simulation to be displayed by the Spectrum Analyzer block needs to be transferred back to Simulink via the Serial TTL connection. 
During external mode, the baud rate set in "Windows Control Panel -> Device Manager" does not set the baud rate in Simulink. For STM32F4-Discovery board, the baud rate is fixed to 460800 bits/s. If you want to change the baud rate for external mode simulation, you can follow the steps below:
1. Execute the following command to open attributes XML file:
>> edit(fullfile(codertarget.stm32f4discovery.internal.getSpPkgRootDir,'registry','attributes','stm32f4_discovery_attribute.xml'))
2. At line 45, change the baud rate from 460800 to the required baud rate. For example:
<baudrate value ="921600" visible="false"/>
3. Open RTIO stream file:
>> edit(fullfile(codertarget.stm32f4discovery.internal.getSpPkgRootDir,'src','rtiostream_serial_dma_stm32f4xx.c'))
4. In the RTIO stream file, at line 99 (inside the rtIOStreamOpen() function), change the baud rate "4 * 115200" with the required baud rate selected in step 2. For example,
USART2_init(921600);
With these steps, you can set the external mode simulation with your required baud rate. Please note, for PIL will to work you will also need to change to the baud rate in "codertarget.stm32f4discovery.pil.SerialConnectivityConfig" at line 50.
To open this file,
    >> edit codertarget.stm32f4discovery.pil.SerialConnectivityConfig
5. Execute the following commands in MATLAB Command Window after updating the above files:
>> clear pcode;
>> clear classes;
>> rehash path; rehash toolbox; rehash pathreset; rehash toolboxreset; 
>> rehash toolboxcache;
>> sl_refresh_customizations;
Following the above steps will allow you to manually specify the baud rate in Simulink. However, this might not resolve the bottleneck issue but it will provide control over the baud rate.

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!