STM32F1 Bulk transfer size problem

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

Dwar
Posts: 12
Joined: Fri Jan 08, 2016 2:04 pm
Location: USA
Has thanked: 4 times
Been thanked: 3 times

Re: STM32F1 Bulk transfer size problem

Postby Dwar » Sat Apr 16, 2016 8:19 am

This is puzzling.

I tried this on an LC Technology board (stm32f103c8t6) and ChibiOS 16.1.4 and it works with 64 byte blocks. The blocks are written and read from a Raspberry PI 2 with the latest Raspian Jessie running the test binary.

rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: STM32F1 Bulk transfer size problem

Postby rbarreiros » Tue Apr 19, 2016 11:51 am

Using the exact same board, latest github ChibiOS with latest Ubuntu, arm-none-eabi-gcc (15:4.9.3+svn227297-1) 4.9.3 20150529 (prerelease), libusb-1.0

It's currently working with 64 byte block, I have no idea what I changed to make it work !! surely was something I did (or didn't) I will attempt to further investigate this issue to try and determine what was causing this.

Dwar did you test using the github code I posted or your own ?

The other problems remain though, the assert when connecting/disconnecting/connecting and the call to libusb_set_configuration.

Best regards.

Dwar
Posts: 12
Joined: Fri Jan 08, 2016 2:04 pm
Location: USA
Has thanked: 4 times
Been thanked: 3 times

Re: STM32F1 Bulk transfer size problem

Postby Dwar » Tue Apr 19, 2016 1:36 pm

Yes, I used your posted github code. Also fine with the latest GhibiOS development trunk.

This is not a high quality board. It does not have the transistor to control USB Renumeration on USB_DP like most of the STM32 boards from STM.

I use the following to help with the USB initialization (did not use it on your code).
My board.h includes these, otherwise it won't connect at all to a Win 7 box.

Code: Select all

/*
 * USB bus activation macro, required by the USB driver.
 */
#define usb_lld_connect_bus(usbp)                             \
   palClearPort (GPIOA, (1<<GPIOA_USBDM) | (1<<GPIOA_USBDP)); \
   palSetPadMode(GPIOA, GPIOA_USBDM, PAL_MODE_INPUT);         \
   palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_INPUT);

/*
 * USB bus de-activation macro, required by the USB driver.
 */
#define usb_lld_disconnect_bus(usbp)                            \
   palClearPort (GPIOA, (1<<GPIOA_USBDM) | (1<<GPIOA_USBDP));   \
   palSetPadMode(GPIOA, GPIOA_USBDM, PAL_MODE_OUTPUT_PUSHPULL); \
   palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_OUTPUT_PUSHPULL);


rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: STM32F1 Bulk transfer size problem

Postby rbarreiros » Tue Apr 19, 2016 4:12 pm

Thanks for those macros Dwar, I'm exactly on a pickle with that, I'm using a DFU bootloader with said same board, and I'm having trouble 'rebooting' into the bootloader from ChibiOS, those macros still don't help :/ the USB doesn't get re-numerated by the os when shutting down ChibiOS and rebooting into bootloader.

When going from Bootloader to Application (ChibiOS) the USB get's re-enumerated, but when shutting down ChibiOS and restarting (NVIC_SystemReset()) the USB is never re-enumerated, need to unplug/plug the usb cable again, I'm doing the following procedure for reboot on ChibiOS

Code: Select all

THD_WORKING_AREA(waUSB, USB_THREAD_SIZE);
THD_FUNCTION(USBThread, arg)
{
  event_listener_t el1;
  eventflags_t flags;

  chRegSetThreadName("USB");
  (void)arg;

  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg);

  usbDisconnectBus(serusbcfg.usbp);
  chThdSleepMilliseconds(1500);
  usbStart(serusbcfg.usbp, &usbcfg);
  usbConnectBus(serusbcfg.usbp);

  chEvtRegisterMask(chnGetEventSource(&SDU1), &el1, ALL_EVENTS);

  while(USBD1.state != USB_READY) chThdSleepMilliseconds(10);
  while(SDU1.state != SDU_READY) chThdSleepMilliseconds(10);

  while(!chThdShouldTerminateX())
  {
    // Needs to timeout or else it hangs waiting for an                                                                                                                                         
    // event when we wish to terminate the thread!                                                                                                                                             
    chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100));
    chSysLock();
    flags = chEvtGetAndClearFlagsI(&el1);
    chSysUnlock();

    if (flags & CHN_INPUT_AVAILABLE)
      usbProtoReadCmd((BaseChannel *)&SDU1);
  }

  // Stop USB here                                                                                                                                                                             
  usbStop(serusbcfg.usbp);
  usbDisconnectBus(serusbcfg.usbp);
}

/*                                                                                                                                                                                             
 * Application entry point.                                                                                                                                                                     
 */
int __attribute__((noreturn)) main(void) {
//int main(void) {                                                                                                                                                                             
  thread_t *usbThread;

  while(true)
  {
    halInit();
    chSysInit();

    // Start USB Thread                                                                                                                                                                         
    usbThread = chThdCreateStatic(waUSB, sizeof(waUSB), NORMALPRIO, USBThread, NULL);

    while (!gDoShutdown)
    {
      chThdSleepMilliseconds(1000);
    }

    // Shutdown and reset                                                                                                                                                                       

    // Wait a bit before shutting everything down                                                                                                                                               
    chThdSleepMilliseconds(100);

    // Stop USB Thread                                                                                                                                                                         
    chThdTerminate(usbThread);
    chThdWait(usbThread);

    chSysDisable();
    chSysEnable();
    chSysDisable();
    NVIC_SystemReset();
  }
}


Shouldn't this work ? or is it really needed to implement the transistor to control usb re-enumeration for this to work ?

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

Re: STM32F1 Bulk transfer size problem

Postby Giovanni » Tue Apr 19, 2016 4:15 pm

Hi,

I think you need to implement a way to trigger a re-enumeration. The USB sriver state would not be carried over between the booloader and the application.

Giovanni

rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: STM32F1 Bulk transfer size problem

Postby rbarreiros » Tue Apr 19, 2016 4:19 pm

Weirdly enough, the dfu bootloader only just disables the peripheral clocks, boots into the application and the USB is re-enumerated !

I attempted to do the same thing on ChibiOS and still doesn't get re-enumerated, here is the DFU bootloader function that leaves the bootloader, it's using libopencm3

Code: Select all

static void leave_bootloader(usbd_device *usbd_dev)
{
  int i;

  usbd_disconnect(usbd_dev, true);
  for (i = 0; i < 8000; i++)   /* Wait a bit. */
    __asm__("nop");

  gpio_clear(GPIOC, GPIO13);
  rcc_peripheral_disable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
  rcc_peripheral_disable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN);
  rcc_peripheral_disable_clock(&RCC_AHBENR, RCC_AHBENR_OTGFSEN);

  /* Set vector table base address. */
  SCB_VTOR = APP_ADDRESS & 0xFFFF;
  /* Initialise master stack pointer. */
  asm volatile("msr msp, %0"::"g"
               (*(volatile uint32_t *)APP_ADDRESS));
  /* Jump to application. */
  (*(void (**)())(APP_ADDRESS + 4))();
}


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 39 guests