Giga devices GD32F405 USB Device

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Giga devices GD32F405 USB Device

Post by Tabulous »

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: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Giga devices GD32F405 USB Device

Post by Tabulous »

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: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Giga devices GD32F405 USB Device

Post by Giovanni »

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: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Giga devices GD32F405 USB Device

Post by Tabulous »

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: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Giga devices GD32F405 USB Device

Post by Giovanni »

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: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: Giga devices GD32F405 USB Device

Post by russian »

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

Did you get this to work?
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Giga devices GD32F405 USB Device

Post by Tabulous »

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: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Giga devices GD32F405 USB Device

Post by Tabulous »

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)
    ;
}
Post Reply