OpenOCD-Error: Embedded Coder Support Package for STMicroelectronics Discovery Boards

18 views (last 30 days)
Hello,
currently I try to get an example of the " Embedded Coder Support Package for STMicroelectronics Discovery Boards" running in a STM32F429 Discovery Board.
I get the following Error:
The following error occurred during deployment to your hardware board:
Error while writing the executable to the STM32F4 flash. OpenOCD returned the following diagnostic message:
Error while trying to establish USB communication with the STM32F4-Discovery board. Please reset the USB communication:
1. Disconnect the USB cable from the board.
2. Wait for three seconds.
3. Connect the USB cable again.
For more information look into logfile generated by openOCD: mw_openocd_log.txt.
The Logfile says:
GNU MCU Eclipse 64-bits Open On-Chip Debugger 0.10.0+dev-00254-g2ec04e4e (2017-11-10-11:34)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 2000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : clock speed 1800 kHz
Error: open failed
in procedure 'program'
in procedure 'init' called at file "embedded:startup.tcl", line 495
in procedure 'ocd_bouncer'
** OpenOCD init failed **
shutdown command invoked
Does anyone has an idea how to solve it? Can anyone help in setting it up for a new ST-Discovery-Board?
Thanky you very much, Best Ragards, Sebastian

Answers (2)

Sebastian Wendel
Sebastian Wendel on 9 Jul 2019
Edited: Sebastian Wendel on 6 Aug 2019
Hello,
Mathworks sent me a tutorial,
Part 1) is about how to solve the issue with OpenOcd Config,
Part 2 ) Use the StLink instead
I haven’t managed to use the ST-Link(Part2), which I would consider better because it may be better maintained, but I have managed to make a LED blink on my Nucleo144 STM32F429 Board using OpenOCD. Please make sure that you use a port and a Pin that is connected to an LED, on mine (Nucleo144 STM32F429 ZI) I configured the Block to GPIOB, Pin14.
Ok, what I did was follow the instructions from Mathworks, but the first attempt failed. My solution is a combination of Mathworks but patching all STM32F4 related files to ST-Link 2.1:
------------------------------------------------------------------------------------
(1) Go to the folder where your support packages are installed and go to the openocd-0.10.0 folder. For example, the default is; C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\openocd.instrset\GNU MCU Eclipse\OpenOCD\0.10.0-5-20171110-1117\scripts\board
(2) Open st_nucleo_f4.cfg , stm32f4discovery.cfg , stm32f429disc1.cfg , stm32f429discovery.cfg
(3) Change
[find interface/stlink-v2.cfg]
to
[find interface/stlink-v2-1.cfg]
(4) Save the files and restart MATLAB. Try the example again.
-------------------------------------------------------------------------------------
I’ll keep you updated, I’ll try to get the ST-Link as well.
Best Regards, Sebastian Wendel

mahdi akbari
mahdi akbari on 3 Aug 2019
hello i have same issue
and this solution dont work for me
  4 Comments
Sebastian Wendel
Sebastian Wendel on 6 Aug 2019
Hello mahdi akbari,
depending on the board that is used different config files may need to be changed. Also make sure to change theme to the ST-Link version for the OpenOCD that is actually used.
There is also an alternative way, not using OpenOCD for the ST-Link-Debugger, but I have not tested it.
Best Regards, Sebastian Wendel
P.S. Here is the original mail from Mathworks (not sure why they do not post it on the web):
1) Go to the folder where your support packages are installed and go to the openocd-0.10.0 folder. For example, the default is
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\openocd.instrset\GNU MCU Eclipse\OpenOCD\0.10.0-5-20171110-1117\scripts\board
(2) Open stm32f4discovery.cfg
(3) Change
[find interface/stlink-v2.cfg]
to
[find interface/stlink-v2-1.cfg]
(4) Save and restart MATLAB. Try the example again.
If the above does not work, another possible workaround is to install a patch that uses the ST-Link Utility instead of OpenOCD to download the generated hex file to the STM32F4 Discovery board. As a disclaimer, note that MathWorks is not responsible for the modifications made to the support package files and that you will be fully responsible for the changes.
With that in mind, to use the patch, please follow the instructions below:
1. Install ST-Link Utility. The tool can be downloaded from the following link:
https://my.st.com/content/my_st_com/en/products/embedded-software/development-tool-software/stsw-link004.html#
2. Create an environment variable called MW_STLINK_UTILITY_PATH. The value for this is the path of the ST-Link command line utility after installing the ST-Link Utility. For example, by default, ST-Link Utility is installed at 'C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility'. Under this folder, the ST-Link command line utility (ST-LINK_CLI.exe) can be found under the 'ST-LINK Utility' folder. So, the environment variable MW_STLINK_UTILITY_PATH should be set with value 'C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility'
Alternatively, you can set the environment variable from the MATLAB command prompt after opening MATLAB:
setenv('MW_STLINK_UTILITY_PATH','C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility')
3. Open the MATLAB and run following command to get the STM32F4-Discovery board support package root directory:
codertarget.stm32f4discovery.internal.getSpPkgRootDir
Now that you have the directory, close MATLAB.
4. Before applying the patch, copy the "+codertarget" folder from the support package root directory from step 3 to back it up. Make sure that the original folder is not deleted or moved.
5. Extract the patch in stm32f4discovery.zip to the support package root directory from step 3. Place the files in the corresponding folder, replacing files as necessary.
6. Now restart MATLAB and then build, load, and run the model "stm32f4discovery_pb_led" from Simulink and check that is model working properly.
Please note that with this patch:
* PIL with 'ST-Link' as the PIL commnunication interface does not work. For PIL, you will need to select 'Serial (USART2)' from PIL communication interface. More information can be found at the following link:
http://www.mathworks.com/help/supportpkg/stmicroelectronicsstm32f4discovery/examples/code-verification-and-validation-with-pil-and-external-mode.html
* Make sure that you have connected only the STM32F4-Discovery board to the machine. If multiple STM32 based boards or non STM32F4-Discovery boards are connected, then the behavior is not deterministic.
amr abdeltawab
amr abdeltawab on 6 Dec 2019
i understood the second solution very well but in step 4 i can't understand what of mean patch here and how form enviroment variable, i can generate patch and extract it in a folder i think this is something missing for me

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!