VS Arduino
Visual Micro >> Installation & Troubleshooting >> Reset board before upload (OpenOCD)
https://www.visualmicro.com/forums/YaBB.pl?num=1561364972

Message started by cirlam12 on Jun 24th, 2019 at 8:29am

Title: Reset board before upload (OpenOCD)
Post by cirlam12 on Jun 24th, 2019 at 8:29am
I have a custom board based on the SamD21 (original prototypes were Arduino Zero based, and therefore my OpenOCD scripts are almost identical to those supplied).

On my custom board, I reconfigure the SWD pins in software as GPIOs, meaning the board NEEDS a reset before it can be uploaded to.

I can successfully upload to the device if I manually reset the board the moment before the upload takes place from vMicro, however if I time the reset wrong, it obviously fails as the pins are then configured as a GPIO within ~2 seconds of power up.  I'd like to avoid lengthening this delay if at all possible.

Is there anyway I can automatically initiate this reset the moment before upload? Atmel Studio is able to upload all the time, without fail (watching with my logic analyzer Atmel Studio pulls the reset pin low everytime the moment before upload, whereas vMicro does not).

I have tried within my board platform.txt (which I have confirmed vMicro is using) adding "init; reset halt;" just before the program command. I.e:

tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; reset halt; program {{{build.path}/{build.project_name}.bin}} verify reset 0x2000; shutdown"

tools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; reset halt; program {{{build.path}/{build.project_name}.elf}} verify reset; shutdown"

However, this fails to pull the reset line low when checked with my logic analyser, and when trying to program the device. I believe my reset-config is correct in openOCD as if I add "connect_assert_srst" (which pulls the reset line low when the target connects automatically - as described here: http://openocd.org/doc/html/Reset-Configuration.html) in my arduino_zero.cfg file, the reset line does get pulled low.

I am using an Atmel ICE programmer. Does anyone have any idea what I'm doing wrong?

Title: Re: Reset board before upload (OpenOCD)
Post by Visual Micro on Jun 24th, 2019 at 12:31pm
Hi,

We are missing some info here.

The Zero has two usb ports. One called programming port and one called native usb port.

By default both arduino ide and visual micro will use the default upload based on each port type but in both cases they do not use the ICE for upload.

In the case of programming port the built in EDBG programmer is used, for the Native port the board is triggered into bootloader mode by connecting serial at 1200 baud then the upload happens over serial

Both of the above do not use ICE to upload.

I don't believe that arduino have produced an ICE programmer definition for a zero. If they did that would be defined in programmers.txt not platform.txt (same folder)

To use visual micro or the arduino ide with an external programmer you would need to select the programmer in the ide from the programmers list and in visual micro click "always use programmer for upload". In the arduino ide you have to specifically click "Upload using programmer" to make a single upload using the selected programmer.

Visual Micro in atmel studio adds a special programmer name called "Use atmel studio device programming". When enabled, visual micro, will build and then hand the upload over to atmel studio to use whatever device you have selected for your atmel project.

I hope this information helps resolve some gray areas and that you are now able to report which type of upload you are using from visual micro and from the arduino ide.

Feel free to ask anything that is not clear. External programmers are not so well documented between arduino and atmel. Thanks

Title: Re: Reset board before upload (OpenOCD)
Post by cirlam12 on Jun 24th, 2019 at 1:34pm
Hi Tim,

Thanks for the response. The OpenOCD files are copied from the Arduino SamD core: https://github.com/arduino/ArduinoCore-samd, which does include Atmel ICE programmer definition and the openocd scripts.

We do have "always use programmer for upload" ticked - and are using vMicro plugin for Visual Studio (no Arduino IDE). I imagine, if we were to port the project over to Atmel Studio and use the "use atmel studio device programming" option this problem would be solved, but in the interest of avoiding rebuilding the project in Atmel Studio would prefer to make it work in Visual Studio if there is something obvious missing from my openocd scripts.

Title: Re: Reset board before upload (OpenOCD)
Post by Visual Micro on Jun 24th, 2019 at 1:41pm
Hi,

Thanks for the info. I agree that VS is better than Atmel for most things however Visual Micro will open the same project using Visual Micro in "Atmel Studio >File>Open Arduino Project"

Having said that I would like to resolve the problem. Does the reset work using the ICE programmer to upload from the Arduino IDE?

Thanks

Title: Re: Reset board before upload (OpenOCD)
Post by cirlam12 on Jun 24th, 2019 at 2:39pm
Hi Tim,

I haven't been able to test this just yet, as we have our header/source files loaded into a folder structure, such that all the header and source files aren't just lumped into 1 folder. Unfortunately when opening in Arduino (and Atmel Studio, when opening as an Arduino project), it flattens this structure (and loads them as if they are just lumped into the same folder) and will require me to change how the majority of my files include each other.

I hope I might get some time tomorrow to quickly change these includes to test this though.

Title: Re: Reset board before upload (OpenOCD)
Post by Visual Micro on Jun 26th, 2019 at 1:30am
1)
In Visual Studio, are you using shared projects or just one Arduino project?

2)
If you use the latest release of visual micro from this forum (1906.26). Do you see the new "Debug" tool bar? If so when you select "Hardware Debugging" do you see a list of "debuggers"? The ICE will not be in the list yet but it is important to know if you see the list that is there? If not we will need a bit more info about your platform.


Thanks

Title: Re: Reset board before upload (OpenOCD)
Post by cirlam12 on Jun 27th, 2019 at 8:19am
1. No, just a regular arduino project

2. Yes I have upgraded to 1906.26.4 - although I can't see the debug tool bar. The closest thing I get to it is in the Add/Remove buttons toolbar:

https://ibb.co/XYQHZsr

Cheers, Chris


Title: Re: Reset board before upload (OpenOCD)
Post by Visual Micro on Jun 27th, 2019 at 12:11pm
1)
If you are not using shared projects then I don't understand your point about arduino and atmel flattening your projects. They work the same. Maybe in atmel you need to click the little "show all files" icon above the solution explorer to see physical file view.

2)
The debug tool bar is empty because your platform is unknown platform. we would need the build output mentioned in the yellow box at the top of this page to give more advice about gdb in VS

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2025. All Rights Reserved.