Menu

#1001 Board STM32F103C8_MINIMAL USB Disconnect alternative

trunk
closed
None
HAL
Low
18.2.1
True
2021-06-18
2019-01-12
No

In the board STM32F103C8_MINIMAL, the macro usb_lld_disconnect_bus, it is a NOP, as this board doesn't have a mosfet to turn on/off the pull up on the USB line D+.

There is a work around that configures the port as output and pull the pin low, this will be equivalent to turning on/off the pull up. I use this with success for some time.

I don't know how to colaborate to the project, I'm used to GitHub Pull Requests, but in SourceForge I'm a dummy.

Here is the patch:

diff --git a/os/hal/boards/STM32F103C8_MINIMAL/board.h b/os/hal/boards/STM32F103C8_MINIMAL/board.h
index 9350c1388..d2360e096 100644
--- a/os/hal/boards/STM32F103C8_MINIMAL/board.h
+++ b/os/hal/boards/STM32F103C8_MINIMAL/board.h
@@ -136,7 +136,10 @@
 /*

  * USB bus de-activation macro, required by the USB driver.
  */
-#define usb_lld_disconnect_bus(usbp)   /* always connected */
+#define usb_lld_disconnect_bus(usbp)   do { \
+                                          palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_OUTPUT_PUSHPULL); \
+                                          palClearPad(GPIOA, GPIOA_USBDP); \
+                                        } while(0);

 #if !defined(_FROM_ASM_)
 #ifdef __cplusplus

Discussion

  • Giovanni Di Sirio

    Hi,

    You need to provide the code also for usb_lld_connect_bus(usbp) or it would not be very useful. Posting small patches here is fine as approach, alternatively you may post on the ChibiOS forum.

     
  • Giovanni Di Sirio

    • assigned_to: Giovanni Di Sirio
     
  • Tercio F Gaudencio Filho

    Hi!

    Here we go:

    diff --git a/os/hal/boards/STM32F103C8_MINIMAL/board.h b/os/hal/boards/STM32F103C8_MINIMAL/board.h
    index 9350c1388..fbdaf7e2a 100644
    --- a/os/hal/boards/STM32F103C8_MINIMAL/board.h
    +++ b/os/hal/boards/STM32F103C8_MINIMAL/board.h
    @@ -131,12 +131,17 @@
     /*
    
      * USB bus activation macro, required by the USB driver.
      */
    -#define usb_lld_connect_bus(usbp)      /* always connected */
    +#define usb_lld_connect_bus(usbp)       do { \
    +                                            palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_INPUT); \
    +                                        } while(0);
    
     /*
    
      * USB bus de-activation macro, required by the USB driver.
      */
    -#define usb_lld_disconnect_bus(usbp)   /* always connected */
    +#define usb_lld_disconnect_bus(usbp)    do { \
    +                                            palClearPad(GPIOA, GPIOA_USBDP); \
    +                                            palSetPadMode(GPIOA, GPIOA_USBDP, PAL_MODE_OUTPUT_OPENDRAIN); \
    +                                        } while(0);
    
     #if !defined(_FROM_ASM_)
     #ifdef __cplusplus
    
     
  • Tercio F Gaudencio Filho

    In my case I added a chThdSleepMilliseconds(2000); after disconnect, but I don't know if this is necessary in this #define.

     
  • Tercio F Gaudencio Filho

    Like this:

        usbDisconnectBus(usbcdc_cfg.usbp);
        // A delay is inserted in order to computer sense the change
        chThdSleepMilliseconds(2000);
        usbStart(usbcdc_cfg.usbp, &usb_cfg);
        usbConnectBus(usbcdc_cfg.usbp);
    
     
  • Giovanni Di Sirio

    • Status: open --> closed
    • Fixed in Repository: False --> True
     

Log in to post a comment.

MongoDB Logo MongoDB