Can I debug stm32duino with KEIL and ST-Link V2

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sat Mar 11, 2017 7:18 am

Hi board.

I just discovered stm32duino and I totally likes it. I want to program with Arduino and debug when necessary. I'm trying to use KEIL because the free version is enough for me. I've already compile and debug other projects in Keil so I believe the hardware setup is OK.

I tried following things.

1. I added -gdwarf-2 flag in boards.txt in genericSTM32F103C.menu.device_variant.STM32F103C8.build.cpu_flags , so there will be debug info.

2. I followed the http://www.keil.com/support/docs/2575.htm to create a new project and try to load the elf file.

3. I make sure I uncheck "download to flash" in debug and "Update Target before Debugging" in Utilities

4. I download code with Arduino IDE

5. I try to debug code and it give me an error "Cannot access target" and I can see "error 57: illegal address (0x08003628)" in console.

I'm trying to debug the blink example. One thing I observed is that LED stop flashing then I try to debug. Seems there is a crash?

Did anyone see similar situation or may offer some help?

Thanks

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby RogerClark » Sat Mar 11, 2017 7:34 am

We don't have a setup to compile in Keil. I'm sure it would be possible to make a project, its just that no one else uses Keil for this, and the repo is setup to be used by the Arduino IDE.

If you have a JLink you could use Segger OZone, and a JLink as it will read the .elf files.

I think @victor_pv uses OZone, but I don't know his particular setup.

BTW.
The evaluation version of Keil is limited to a maximum binary size of 32k, which will be fine for small projects, but even a blank sketch (with USB support) takes 12k, so you may quickly run into the 32k limit.

If you don't want to use the Arduinino IDE, you could try using Eclipse, as their is an Arduino plug-in, but I don't think the setup is that easy.

If you don't have a JLink, it is possible to convert some STlink's to Jlink using a updater from Segger, but I think this only works on some Nucleo boards STLink and not most of the dongles that are on eBay etc

iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sat Mar 11, 2017 8:26 am

Thank you for your reply.

I'm using Arduino for compiling code. However when I'm unsure about registers. The watch window really helps.

The reason I'm doing it is that I'm trying to copy 0xws2812 project to stm32duino. I did got it working with little bugs that I believe some registers may be wrong. So I want to load elf with IDE and debug it.

I hope keil would work. But I'm also open to other options. Is there any other option that I can do with st link?

Thanks

iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sat Mar 11, 2017 11:17 pm

Finally I got it working and I'm leaving my result here. If you have windows and Keil, I believe this is the most hassle free solution.

1. edit boards.txt in stm32duino, add -gdwarf-2 flag to add debug info in elf file
step1_board_txt.PNG
step1_board_txt.PNG (84.52 KiB) Viewed 142 times


2. edit preferences.txt in arduino, add build.path to make your life easier.
step2_preferences.PNG
step2_preferences.PNG (38.13 KiB) Viewed 142 times


3. compile and upload code in Arduino IDE. code is in flash and elf should be ready
step3_upload_code.PNG
step3_upload_code.PNG (39.9 KiB) Viewed 142 times

iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sat Mar 11, 2017 11:18 pm

4. Start µVision and use Project -> New Project... to create a new project file in the folder.
Select the device that you are using from the Device Database.
Project -> Options for Target
Choose ST_Link and uncheck "Load application on startup"
step4_choose_ST_Link.PNG
step4_choose_ST_Link.PNG (57.9 KiB) Viewed 142 times

5. In Utilities, uncheck Update "Target before Debugging"
step5_Do_not_update.PNG
step5_Do_not_update.PNG (46.62 KiB) Viewed 142 times

6. Check driver setting, sometimes those info got lost and I got error.
step6_CheckDriverSetup.PNG
step6_CheckDriverSetup.PNG (63.15 KiB) Viewed 142 times

iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sat Mar 11, 2017 11:37 pm

7. start debugging, in lower left corner, I typed

load C:\Users\t_sund\Documents\Arduino\buildFolder\BlinkWithoutDelay.ino.elf

You can also create a ini init file and put load command there. So the elf can be loaded when debug starts. Also your breakpoints and watch list will not get lost.

step7_Happydebuging.PNG
step7_Happydebuging.PNG (134.67 KiB) Viewed 141 times
Last edited by iamseer on Sun Mar 12, 2017 2:44 am, edited 1 time in total.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby RogerClark » Sun Mar 12, 2017 12:55 am

Very interesting

Thanks for posting.

I wonder if the evaluation version of Keil will where the binary size > 32k.

I looked in the limitations and it states "The debugger supports programs that are 32 Kbytes or smaller."

So I presume that even if you compile a using gcc, that you won't be able to debug if the size is greater than 32k

BTW. I looked at Seggers standalone debugger "OZone" but as far as I can tell, unlike Keil, it only supports JLink as the debug hardware

iamseer
Posts: 6
Joined: Sat Mar 11, 2017 7:06 am

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby iamseer » Sun Mar 12, 2017 2:48 am

I used Keil to catch a bug in my code when I set up DMA registers. It will be really difficult to debug with print.

I would say 32K is enough if we debug code blocks separately.

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Can I debug stm32duino with KEIL and ST-Link V2

Postby RogerClark » Sun Mar 12, 2017 6:17 am

iamseer wrote:I used Keil to catch a bug in my code when I set up DMA registers. It will be really difficult to debug with print.

I would say 32K is enough if we debug code blocks separately.


Yes ;-)


Return to “IDE's”

Who is online

Users browsing this forum: No registered users and 1 guest