Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic L4 variants disable SWD debugging without any notice #2047

Closed
fronders opened this issue Jun 26, 2023 · 2 comments
Closed

Generic L4 variants disable SWD debugging without any notice #2047

fronders opened this issue Jun 26, 2023 · 2 comments

Comments

@fronders
Copy link

fronders commented Jun 26, 2023

I have a custom STM32L486-based board and wanted to debug via SWD using ST-Link V3.
So I'm using release 2.5.0 and selected Generic STM32L4 series with board PN Generic STM32L486RGTx and the following options:
image

So the code uploads okay, but the debugging session would not start. After hours of battling with openocd configs and trying multiple different options I discovered it can only connect after chip was previously erased. This made me wonder if SWD pins might be disabled.

I checked variant's PeriperalPins.c

//*** USB ***
#if defined(HAL_PCD_MODULE_ENABLED) || defined(HAL_HCD_MODULE_ENABLED)
WEAK const PinMap PinMap_USB_OTG_FS[] = {
{PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_SOF
{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS
{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_ID
{PA_11, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DM
{PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_DP
{PA_13, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_NOE
{PC_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_NOE
{NC, NP, 0}
};
#endif

PA_13 is initialized there, which kills the debugging ability.
As soon as I redefined this PinMap as a strong in my sketch with that line definitions commented out

//   {PA_13, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG_FS)}, // USB_OTG_FS_NOE

debugging started working like a charm!

Would it be better to define those pins overridden if needed explicitly? Like, wrap it in an ifdef for example when debug symbols are enabled, or smth similar. Also please advise on the best solution in my case. I can keep the redefined PinMap_USB_OTG_FS[], or even create my own board variant, but the fact that this isn't mentioned anywhere and I had to kill like a day for finding this, is certainly discouraging.
Thanks

@fpistm
Copy link
Member

fpistm commented Jun 26, 2023

Hi @fronders
Sorry for that, generic provide all possibles values and those files are automatically generated.
With STM32 there are several possibilities for pins and hard to fit/guess what user want. You used the correct way by redefining the PinMap array, that is why it is defined as WEAK.
Maybe a note could be added in the FAQ section of the Wiki.
https://github.com/stm32duino/Arduino_Core_STM32/wiki/FAQ

@fpistm
Copy link
Member

fpistm commented Jun 27, 2023

I've added a debug section to the FAQ:
https://github.com/stm32duino/Arduino_Core_STM32/wiki/FAQ#debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants