-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disabled SWD pins for all boards when using DFU (bootloader) upload m…
…ethod
- Loading branch information
1 parent
abdf42d
commit a8d1c1d
Showing
1 changed file
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change? I just wanted to debug an arduino program that was crashing, but now I cannot attach with my debugger.
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to complains from other users, about their projects no longer working, because GPIO access is removed from the SWD pins.
I had to revert the change made made in 7c9b1cc
If you want this non-standard feature, please download that version
https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/7c9b1cc11ae391be547f191ceb7865a4b3925ffb
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change only disable the debug port when uploading with USB DFU, in which case usually you don't have any debugger connected.
You should be able to debug if you (build and) upload using STLink or other debug interface.
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also ran into this, uploading the stm32bootloader-with-congratulations sketch, which broke further SWD uploads, to my surprise. Took me a while to figure out why this happened.
Would it not be possible to leave the debug port enabled, but only disable it when setting the
pinMode
of one of the SWD/JTAG pins? That would allow debugging of all sketches that do not use these pins for anything else, which seems like a perfect solution?a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is a bit complicated.
There were many users complaining about not working PB3, PB4, PA15 pins, which are reserved for the debug interface.
The debug ports are enabled on reset per default, and they cannot be used as IOs in this mode, not even if you call pinMode().
So the best solution to avoid further user complain was to disable the debug ports thereby enabling the mentioned pins for IO usage.
A compromise could be to enable only the SWD interface at startup (reserving PA13/14 for debug) instead of disabling it completely.
This way the STlink can connect to the target and PB3/4, PA15 can also be used as IOs.
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be do something like this in pinMode (heavy pseudocode, just to get the idea):
e.g. only if the debug pins are used, disable debugging (and ideally only disable SWD when really needed).
Another solution would be to keep things enabled and let the sketch call a function to disable debugging if they'd need the debug pins.
This would indeed seem like a good compromise, since I expect most board will have SWD pins exposed separately, but maybe have the other JTAG pins included in the normal GPIO pin headers.
On top of this compromise, either of the above suggestions (disable SWD when pins are used in pinMode, or let the sketch explicitly disable SWD or enable JTAG if needed) could be applied, of course.
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The debug port selection is a matter of board option.
For bluepill it would eventually make sense to enable the SDW only debug mode, because it has the SWD pins exposed to a header.
These lines could be replaced by
enableDebugPorts();
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the STM32 core we disabled it as suggested by @matthijskooijman.
So if user calls
pinMode
on one of those pins it is disabled and also on anattachInterrupt
https://github.com/stm32duino/Arduino_Core_STM32/blob/0f24f28ab48ce24f5a148dbace85ff86dee477ec/cores/arduino/stm32/PinAF_STM32F1.h#L174-L194
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabling the debug as soon as someone called pinMode seems a reasonable solution.
It makes pinMode a bit slower, so I don't know if there are any instances where pinMode is changed constantly. Probably not.
Perhaps its quicker to have a variable that stores the debug pin state as its quicker to test this each time in pinMode than always to have to disable the debug, which may take longer.
a8d1c1d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some time critical applications which use
pinMode(),
so I rather would not prefer the pin checking each time to save run-time.As a general solution, I would enable only the SWD debug ports for all variants in startup. This enables PA15, PB3/4 for IO usage, and allows SWD connection reserving only PA13/14 for debug.
If any currently supported upload method needs full JTAG interface, the boards.txt could be eventually adapted to pass the corresponding parameter for
afio_cfg_debug_ports(AFIO_DEBUG_FULL_SWJ);
For users who need PA13/14 as IO, they will have to use
disableDebugPorts();
in their setup, as this is really a very special use case. The need for these specific pins hint towards choosing another variant having more IOs or a different platform (F4).Another option, a separate Arduino menu to choose the debug functionality is maybe exaggerated.