Giga devices GD32F405 USB Device

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Giga devices GD32F405 USB Device

Postby Tabulous » Mon Jan 17, 2022 3:06 pm

Currently running Chibios on a Giga devices GD32F405(STM32F4xx). Virtually everything works apart from the USB FS Device.
It looks to start enumerating but windows then show error as device not known.

Having spoken the GD FAE Manager, they say this

"In most cases, the configuration order of USB FIFO needs to be modified. ST's USB library refreshes FIFO first, then configures it. GD's USB must be configured with USB FIFO before refreshing. The order in which FIFOs are refreshed and configured applies to OTG devices and HOST."


Just wondering if anyone else has any other knowledge of this ?

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Giga devices GD32F405 USB Device

Postby Tabulous » Wed Feb 02, 2022 4:48 pm

Still trying to get to the bottom of this issue

if i comment out these two asserts
osalDbgAssert(!usbGetReceiveStatusI(usbp, ep), "already receiving");
osalDbgAssert(!usbGetTransmitStatusI(usbp, ep), "already transmitting");

and in usb_lld_start i put a break point on otg_core_reset(usbp);

hitting the break point means the system halts at the break point, when continues is pressed the USB CDC will work....

Now if remove the break point and run the system, USB CDC errors.

Seems this otgp->GCCFG = GCCFG_INIT_VALUE; needs time

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Giga devices GD32F405 USB Device

Postby Giovanni » Wed Feb 02, 2022 7:45 pm

Probably it is a race condition, that driver needed insertion of small delays in the past. Probably the OTG is configured a bit differently on this device.

Giovanni

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Giga devices GD32F405 USB Device

Postby Tabulous » Thu Feb 03, 2022 11:25 am

Giovanni wrote:Probably it is a race condition, that driver needed insertion of small delays in the past. Probably the OTG is configured a bit differently on this device.

Giovanni


do you have any recommendations to help debug this ?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Giga devices GD32F405 USB Device

Postby Giovanni » Thu Feb 03, 2022 11:40 am

Adding small delays or try to slow down the core using -O0 or a lower clock.

That OTG IP is hard to use.

Giovanni

User avatar
russian
Posts: 364
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 16 times
Been thanked: 14 times

Re: Giga devices GD32F405 USB Device

Postby russian » Fri Apr 22, 2022 5:17 am

Tabulous wrote:do you have any recommendations to help debug this ?

Did you get this to work?
http://rusefi.com/ - electronic fuel injection

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Giga devices GD32F405 USB Device

Postby Tabulous » Thu Apr 28, 2022 8:54 am

russian wrote:
Tabulous wrote:do you have any recommendations to help debug this ?

Did you get this to work?


Sort of but only by adding delays which makes the enumeration slow, i would really like to get to the route cause and fix it correctly, but just not had the time.

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Giga devices GD32F405 USB Device

Postby Tabulous » Thu Apr 28, 2022 12:13 pm

this is what i found works. Adding a delay here if MCU type is GD32.

Code: Select all

static void otg_polled_delay(rtcnt_t cycles)
{
  rtcnt_t start = chSysGetRealtimeCounterX();
  rtcnt_t end   = start + cycles;

  do
  {
    __asm("");
    WWDG->CR = ( 127 );
    WWDG->SR = ( 000 );
  }
  while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end));
}

static void otg_core_reset(USBDriver *usbp) {
  stm32_otg_t *otgp = usbp->otg;

  osalSysPolledDelayX(32);

  if(systemGetMcuType() == APP_MCU_GD32F)
  {
    otg_polled_delay(25000000);
  }

  /* Core reset and delay of at least 3 PHY cycles.*/
  otgp->GRSTCTL = GRSTCTL_CSRST;
  while ((otgp->GRSTCTL & GRSTCTL_CSRST) != 0)
    ;

  osalSysPolledDelayX(18);

  /* Wait AHB idle condition.*/
  while ((otgp->GRSTCTL & GRSTCTL_AHBIDL) == 0)
    ;
}


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 16 guests