cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE not generating correct code for SWCLK on STM32WL33

divmstr
Associate II

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

10 REPLIES 10
STTwo-32
ST Employee

Hello @divmstr 

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

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

divmstr
Associate II

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

 

Best Regards

 

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Can you suggest parameters for setup?

Thanks.

 

Hello @divmstr 

You should use the same configuration of the PA2 pin for the PB2 or any other pin you need to configure as SWCLK. But be aware of the Alternate function that you are going to set (AF1 for PB2).

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

PA2 is the SWDIO pin, the generated code is below:

/*Configure GPIO pin : PA2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_LCO;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

It is configuring it as a push-pull output with a pullup, low speed, and using the incorrect alternate, which should have been GPIO_AF0_SWDIO, fortunately both have the same value (another bug). However SWCLK is defined in the datasheet as an input, so should it be GPIO_MODE_INPUT, and GPIO_AF1_SWCLK? What about speed, or any other params?

Pls advise.

Tnx.

 

For me, it will be a good reference if you have a look at the configuration of this pin on another MCU and inspire from it (same configuration using the GPIO_AF1_SWCLK macro to configure the Alternate function.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

divmstr
Associate II

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

 

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.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.