AnsweredAssumed Answered

disabled swd debuging

Question asked by 1200rata on Aug 4, 2011
Latest reply on Oct 15, 2011 by soares.vitor
Hi,

i used to program my stm32 discovery board via usb cable using SWD. 
I used some example code and i think i disabled SWD debugging accidently. 
Now i cant enable it back, the Keil software i use says that no target is connected and flash download failed. Can anyone help me to enable SWD back ? Is there any ways to reset stm32. Here's the example code i used :

main.c

#include "stm32f10x_lib.h"

/* function prototypes */
void RCC_Configuration(void);
void GPIO_Configuration(void);
void Delay(vu32 nCount);

/* entry point */
int main(void)
{
  /* configure clock sources */
  RCC_Configuration();

  /* configure I/O ports */
  GPIO_Configuration();

  /* blinking loop */
  while (1) {
    /* change the PC7 state */
    GPIO_WriteBit(GPIOC, GPIO_Pin_8, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_8)));

    /* wait */
    Delay(0x5FFFF);
    Delay(0x5FFFF);
    Delay(0x5FFFF);
    Delay(0x5FFFF);
    Delay(0x5FFFF);
    Delay(0x5FFFF);
  }
}

/* set up clock sources */
void RCC_Configuration(void)
{
  /* reset */
  RCC_DeInit();

  /* activate HSI (Internal High Speed oscillator) */
  RCC_HSICmd(ENABLE);
  while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

  /* configure prescalers */  
  RCC_HCLKConfig(RCC_SYSCLK_Div1);// HCLK = 64 MHz, AHB
  RCC_PCLK1Config(RCC_HCLK_Div2); // APB1 = 32 MHz
  RCC_PCLK2Config(RCC_HCLK_Div1); // APB2 = 64 MHz

  /* set up FLASH */
  FLASH_SetLatency(FLASH_Latency_2);
  FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  /* set up PLL */
  RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_16); // 64 MHz
  RCC_PLLCmd(ENABLE);
  while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

  /* set up SYSCLK */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //SYSCLK = PLLCLK => 64 MHz
  while (RCC_GetSYSCLKSource() != 0x08);

  /* set up peripheral clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); 
}        

/* configure I/O ports */
void GPIO_Configuration(void)
{
  /* pin configuration parameters */
  GPIO_InitTypeDef GPIO_InitStructure;

  /* disable SWJ debug port - comment if you are using JTAG */
 GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
  
  /* configure PC7 as output push-pull  */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}

/* wait */
void Delay(vu32 nCount)
{
  while (nCount--);
}




Outcomes