Skip to content

Commit

Permalink
Disabled SWD pins for all boards when using DFU (bootloader) upload m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
rogerclarkmelbourne committed Feb 26, 2017
1 parent abdf42d commit a8d1c1d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions STM32F1/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ genericSTM32F103C.menu.device_variant.STM32F103CB.upload.flash.maximum_size=1310
genericSTM32F103C.menu.upload_method.DFUUploadMethod=STM32duino bootloader
genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericSTM32F103C.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_20.ld
genericSTM32F103C.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down Expand Up @@ -282,7 +282,7 @@ genericSTM32F103R.menu.device_variant.STM32F103RE.build.ldscript=ld/stm32f103re.
genericSTM32F103R.menu.upload_method.DFUUploadMethod=STM32duino bootloader
genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericSTM32F103R.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader.ld
genericSTM32F103R.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down Expand Up @@ -337,7 +337,7 @@ genericSTM32F103T.menu.device_variant.STM32F103TB.upload.flash.maximum_size=1310
genericSTM32F103T.menu.upload_method.DFUUploadMethod=STM32duino bootloader
genericSTM32F103T.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericSTM32F103T.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericSTM32F103T.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericSTM32F103T.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericSTM32F103T.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericSTM32F103T.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_20.ld
genericSTM32F103T.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down Expand Up @@ -400,7 +400,7 @@ genericSTM32F103V.menu.device_variant.STM32F103VE.build.ldscript=ld/stm32f103ve.
genericSTM32F103V.menu.upload_method.DFUUploadMethod=STM32duino bootloader
genericSTM32F103V.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericSTM32F103V.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericSTM32F103V.menu.upload_method.DFUUploadMethod.build.ldscript=ld/stm32f103veDFU.ld
genericSTM32F103V.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down Expand Up @@ -460,7 +460,7 @@ genericSTM32F103Z.menu.device_variant.STM32F103ZE.build.ldscript=ld/stm32f103ze.
genericSTM32F103Z.menu.upload_method.DFUUploadMethod=STM32duino bootloader
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.build.ldscript=ld/stm32f103z_dfu.ld
genericSTM32F103Z.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down Expand Up @@ -569,7 +569,7 @@ genericGD32F103C.menu.upload_method.DFUUploadMethod=GD32duino bootloader

genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_20.ld
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Expand Down

10 comments on commit a8d1c1d

@corecode
Copy link

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.

@rogerclarkmelbourne
Copy link
Owner Author

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

@stevstrong
Copy link
Collaborator

@stevstrong stevstrong commented on a8d1c1d Mar 12, 2017

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.

@matthijskooijman
Copy link

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?

@stevstrong
Copy link
Collaborator

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.

@matthijskooijman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

My suggestion would be do something like this in pinMode (heavy pseudocode, just to get the idea):

if (pin == PB3 || PB4 || PA15 || PA13 || PA14)
  disable_jtag();
if (pin == PB13 || PB14)
  disable_swd();

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.

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.

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.

@stevstrong
Copy link
Collaborator

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();

@fpistm
Copy link
Contributor

@fpistm fpistm commented on a8d1c1d Mar 26, 2020

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 an attachInterrupt
https://github.com/stm32duino/Arduino_Core_STM32/blob/0f24f28ab48ce24f5a148dbace85ff86dee477ec/cores/arduino/stm32/PinAF_STM32F1.h#L174-L194

@rogerclarkmelbourne
Copy link
Owner Author

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.

@stevstrong
Copy link
Collaborator

@stevstrong stevstrong commented on a8d1c1d Apr 3, 2020

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.

Please sign in to comment.