CommunityGD32Cores / ArduinoCore-GD32

Arduino core for GD32 devices, community developed, based on original GigaDevice's core
Other
89 stars 33 forks source link

digital output does not work on PB3 of GD32F303C #91

Closed flute2k3 closed 1 year ago

flute2k3 commented 1 year ago

include

define LED PB3

void setup(){ pinMode(LED, OUTPUT); }

void loop(){ digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); }

Tested above codes, no plus voltage observed at PB3 pin, by another words, if I do not want to use JTAG debugging function, how can I release the PB3 PB4 pin, etc? by google searching, I found this claimed to work on stm32 does not work with gd32 afio_cfg_debug_ports(AFIO_DEBUG_NONE)

maxgerhardt commented 1 year ago

Currently we don't yet automatically disable the JTAG / SWD pin remapping functions if we see those pins being used.

Can you try this manually as the first line in setup()?

gpio_pin_remap_config(GPIO_SWJ_DISABLE_REMAP, ENABLE);

might need DISABLE instead of ENABLE if it doesn't work.

maxgerhardt commented 1 year ago

Oh, actually that would completely disable JTAG + SWD (you might need to hold down reset and release it at the right time during the flashing process if you can't flash it now).

Reference manual chapter 8.4.3 says

grafik

So if you use SWD to flash it, you should be able to do

gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);

instead, that makes PB3 available.

flute2k3 commented 1 year ago

sorry to say, but both DISABLE and ENABLE does not work. I use ST-link to flash

maxgerhardt commented 1 year ago

Mhh I think it must be the second line, after you did the pinMode() because then the clock for the AFIO peripheral is activated and the command becomes valid.. I'll check on my hardware.

Or manually

rcu_periph_clock_enable(RCU_AF);

first.

maxgerhardt commented 1 year ago

Basically what I'm saying is

#include <Arduino.h>
#define LED PB3
void setup()
{
    rcu_periph_clock_enable(RCU_AF);
    gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);
    pinMode(LED, OUTPUT);
}

void loop()
{
    digitalWrite(LED, LOW);
    delay(100);
    digitalWrite(LED, HIGH);
    delay(100);
}
flute2k3 commented 1 year ago

super, it works but I get this error 0x2ba01477 Error: init mode failed (unable to connect to the target) in procedure 'program' OpenOCD init failed shutdown command invoked

*** [upload] Error 1

by press the reset button works with flashing. I'm happy with it now. thank you again!

maxgerhardt commented 1 year ago

Did you upload with GPIO_SWJ_SWDPENABLE_REMAP or GPIO_SWJ_DISABLE_REMAP? You're connecting via the SWDCLK (PA14) + SWDIO (PA13) lines?

Try also connecting the NRST of the ST-Link to the (N)RST line of the board.

Also,

you might need to hold down reset and release it at the right time during the flashing process if you can't flash it now

maxgerhardt commented 1 year ago

I've actually just pulled in the API for the afio_cfg_debug_ports() function, see

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/commit/a178ad6ef661aff6b0b91245163ba4791f279a09

Can I ask you to update again and use the sketch

#include <Arduino.h>
#define LED PB3
void setup()
{
    // switch to "SWD only", releasing PA15, PB3 and PB4
    // from their original JTAG function.
    afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
    pinMode(LED, OUTPUT);
}

void loop()
{
    digitalWrite(LED, LOW);
    delay(100);
    digitalWrite(LED, HIGH);
    delay(100);
}

as a test?

flute2k3 commented 1 year ago

I've actually just pulled in the API for the afio_cfg_debug_ports() function, see

a178ad6

Can I ask you to update again and use the sketch

#include <Arduino.h>
#define LED PB3
void setup()
{
    // switch to "SWD only", releasing PA15, PB3 and PB4
    // from their original JTAG function.
    afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
    pinMode(LED, OUTPUT);
}

void loop()
{
    digitalWrite(LED, LOW);
    delay(100);
    digitalWrite(LED, HIGH);
    delay(100);
}

as a test?

it works like a charm without blocking the flashing function, cool ^_^