Skip to main content
Associate III
April 19, 2025
Solved

STM32CubeIDE not generating correct code for SWCLK on STM32WL33

  • April 19, 2025
  • 4 replies
  • 1130 views

In my design I needed to use the SPI on the 32-pin WL33, which normally is SWCLK, so I relocated it from its usual PA3, to PB2. When connecting the debugger, it was unable to find the target, which is usually an indication of incorrect connections to SWCLK and/or SWDIO.

The manual (rm0511) on pp58-59 describes the alternate functions, and I can see that using PB2 is a valid configuration using AF1 on on that pin. However, when doing a deeper dive into the generated code, I discovered that it has generated code for pin PA2 (SWDIO), (albeit using the wrong define for the Alternate member of the GPIO initialization struct, which is GPIO_AF0_LCO, instead of GPIO_AF0_SWDIO, but luckily they have the same value!), but NO CODE has been generated for SWCLK. As the default alternate register value, according to the manual, is AF0, then it comes up on the wrong pin. Hence the debugger error.

I am presuming that I can fix this by adding code to configure PB2 to use AF1? If there are any other suggestions I would like to know. 

Are there any plans to fix this in a later release? I don't see any SWCLK config on any other platform, including the Nucleo CC2.

 

 

Best answer by STTwo-32

Hello @divmstr 

You may try this initialization code:

/*Configure GPIO pin : PB2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_SWCLK;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, PWR_GPIO_BIT_2);

  Correction will be update on the future.

PS: this has been solved on the version 6.15.0 of the STM32CubeMX.

Best Regards.

STTwo-32

4 replies

STTwo-32
Technical Moderator
April 20, 2025

Hello @divmstr 

Could you please add your .ioc file so I can have a look to the issue. 
Best Regards.

STTwo-32

divmstrAuthor
Associate III
April 20, 2025

Thank you for your attention in this matter. Please find IOC attached.

 

Best Regards

 

STTwo-32
Technical Moderator
April 21, 2025

Hello @divmstr 

Thank you so much for reporting this behavior. I've escalated this to the concerned team (under internal ticket number 208179). For now, you need to add the concerned part of initialization manually to your code. 

Best Regards.

STTwo-32

divmstrAuthor
Associate III
April 21, 2025

Can you suggest parameters for setup?

Thanks.

 

divmstrAuthor
Associate III
April 21, 2025

Thanks, but this appears to be the only processor that has this functionality, the others all appear to have dedicated pins and do not need to be configured, they are just defaulted. I checked several F4xxx and F7xxx devices.

Please let me know when the bug has been fixed. 

Regards

 

STTwo-32
STTwo-32Best answer
Technical Moderator
April 21, 2025

Hello @divmstr 

You may try this initialization code:

/*Configure GPIO pin : PB2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_SWCLK;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_B, PWR_GPIO_BIT_2);

  Correction will be update on the future.

PS: this has been solved on the version 6.15.0 of the STM32CubeMX.

Best Regards.

STTwo-32

divmstrAuthor
Associate III
April 22, 2025

Thank you very much.