USB LLD macros for connect/disconnect in OTGv1 driver

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
LHelge
Posts: 15
Joined: Sun Sep 21, 2014 10:58 pm
Been thanked: 1 time

USB LLD macros for connect/disconnect in OTGv1 driver

Postby LHelge » Tue Jul 07, 2015 7:34 am

I'm currently playing around with a Olimex STM32-P405 board together with ChibiOS 3.0.0p5. The board is essentialy the same as the P103 but with an STM32F405RG micro instead. I made my own board definition based on the included one for P103 mixed up with the one for STM32F4Discovery.

I've run into some problems with the OTGv1 driver that is used instead of USBv1 for the P103 board. In the board definitions the lld macros for connecting and disconnecting the USB is redefined:

Code: Select all

/*
 * USB bus activation macro, required by the USB driver.
 */
#define usb_lld_connect_bus(usbp) palClearPad(GPIOC, GPIOC_USB_DISC)

/*
 * USB bus de-activation macro, required by the USB driver.
 */
#define usb_lld_disconnect_bus(usbp) palSetPad(GPIOC, GPIOC_USB_DISC)


This works fine for the USBv1 driver, but not OTGv1 I changed the usb_lld.h from

Code: Select all

/**
 * @brief   Connects the USB device.
 *
 * @api
 */
#define usb_lld_connect_bus(usbp) ((usbp)->otg->GCCFG |= GCCFG_VBUSBSEN)

/**
 * @brief   Disconnect the USB device.
 *
 * @api
 */
#define usb_lld_disconnect_bus(usbp) ((usbp)->otg->GCCFG &= ~GCCFG_VBUSBSEN)

to

Code: Select all

/**
 * @brief   Connects the USB device.
 *
 * @api
 */
#if !defined(usb_lld_connect_bus)
#define usb_lld_connect_bus(usbp) ((usbp)->otg->GCCFG |= GCCFG_VBUSBSEN)
#endif

/**
 * @brief   Disconnect the USB device.
 *
 * @api
 */
#if !defined(usb_lld_disconnect_bus)
#define usb_lld_disconnect_bus(usbp) ((usbp)->otg->GCCFG &= ~GCCFG_VBUSBSEN)
#endif


Similar to the implementation in USBv1, and got rid of a lot of compiler warnings. Is there a reason for omitting this check in the OTGv1 driver, or was this just missed?

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

Re: USB LLD macros for connect/disconnect in OTGv1 driver

Postby Giovanni » Tue Jul 07, 2015 9:35 am

Hi,

The OTGv1 driver does not require the definition of those macros externally because the peripheral can handle it without dependencies on the board design.

Remove them from board.h.

Also note that board.h should be generated not written by hand, there is a generator tool in ChibiStudio that generates them starting from an XML description (that .chcfg file).

Giovanni

LHelge
Posts: 15
Joined: Sun Sep 21, 2014 10:58 pm
Been thanked: 1 time

Re: USB LLD macros for connect/disconnect in OTGv1 driver

Postby LHelge » Tue Jul 07, 2015 10:15 am

How will I then get enumeration to begin? The pull-up on the data line on this particular board is enabled by GPIOC_11, is there some way I can make the driver point to this pin for enabling the pull-up?

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

Re: USB LLD macros for connect/disconnect in OTGv1 driver

Postby Giovanni » Tue Jul 07, 2015 10:39 am

Hi,

OTG is able to activate an internal pull-up, I think that the external pull-up is there because the board is the same old P103 and the STM32F1xx required the external pull up.

Just try the driver as-is. Make sure to take all files from a project for the F4.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 3 guests