openwch / ch32x035

32-bit RISC-V MCU CH32X035 built-in USB PD PHY
44 stars 9 forks source link

CH32X035G8U6 SWJ disabling with GPIO_Remap_SWJ_Disable does not work #8

Open 0x0fe opened 8 months ago

0x0fe commented 8 months ago

So, we use the CH32X035G8U6 and we need to have control over PC18 PC19 which is also the SWD port. The following test works perfectly fine on PB10 PB11, and fails on PC18 PC19 As if the SWJ port was not disabled, but it is disabled. Is it a bug in the SDK?

GPIO_InitTypeDef GPIO_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_19;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_18;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);

while(1){
  GPIO_SetBits(GPIOC, GPIO_Pin_18);
  delay(1000);
  GPIO_ResetBits(GPIOC, GPIO_Pin_18);
  delay(1000); 
  GPIO_SetBits(GPIOC, GPIO_Pin_19);
  delay(1000);
  GPIO_ResetBits(GPIOC, GPIO_Pin_19);
  delay(1000);
}
AlaDdin-g commented 8 months ago

Hi,GPIO mode ‘GPIO_Mode_AF_PP’ is not appropriate to use here.You want to use PC18, PC19 pins as normal IO ports, so you should set the mode to push-pull outputs, not multiplexed push-pull outputs.