cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0 reenable SWCLK

mazahner
Associate
Posted on October 27, 2016 at 13:34

Hello,

I'm using a stm32f030x6. During normal operation i need my swclk-pin (PA14 in my package) to be configured as a UART. However for debugging, i'd like to reconfigure it back and use it as a swclk to use it with the ST-LINK

i tried the following:

void ReEnableSWCLK()

{

  GPIO_InitTypeDef GPIO_InitStruct;

  GPIO_InitStruct.Pin = GPIO_PIN_14;  // only initialize the CLK

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_PULLDOWN;

  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF0_SWCLK;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

which did not work. Then  Resetting the whole GPIOA registers back to their reset values (then SWD is available):

  // bring back the SWD port!

  GPIOA->AFR[0] = 0x00000000;

  GPIOA->AFR[1] = 0x00000000;

  GPIOA->MODER = 0x28000000;

  GPIOA->OTYPER = 0x00000000;

  GPIOA->OSPEEDR = 0x0C000000;

  GPIOA->PUPDR = 0x24000000;

which sort o helps: my st-link finds the chip (unlike in uart mode) but it fails to really comunicate to it:

Info : using stlink api v2

Info : Target voltage: 3.592147

Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints

Error: jtag status contains invalid mode value - communication failure

Polling target stm32f0x.cpu failed, trying to reexamine

Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints

Info : Previous state query failed, trying to reconnect

Error: jtag status contains invalid mode value - communication failure

and so on...

i'm tying to reenable the swclk from an interrupt routine.

Any Idea what's going wrong? any help is higly appreciated. Thank you!!

#stm32f030-!swclk
1 REPLY 1
mazahner
Associate
Posted on October 27, 2016 at 14:00

Ha figured out what the problem was: someone else was spamming my port. so it kept disconnecting. last approach works! (maybe first aswell)

SOLVED