Skip to content

Commit

Permalink
fix cdcacm: need to force a valid OTG session if BOARD_USB_VBUS_SENSE…
Browse files Browse the repository at this point in the history
…_DISABLED

Required for example on STM32F745 boards.
  • Loading branch information
bkueng committed Jul 11, 2019
1 parent 7eabab9 commit a6d0a51
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions stm32/cdcacm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
#if INTERFACE_USB != 0
#define USB_CDC_REQ_GET_LINE_CODING 0x21 // Not defined in libopencm3

#ifndef OTG_GOTGCTL_BVALOVAL
#define OTG_GOTGCTL_BVALOVAL (1 << 7)
#endif
#ifndef OTG_GOTGCTL_BVALOEN
#define OTG_GOTGCTL_BVALOEN (1 << 6)
#endif

/*
* ST changed the meaning and sense of a few critical bits
* in the USB IP block identified as 0x00002000
Expand All @@ -56,6 +63,11 @@
*/
#define OTG_CID_HAS_VBDEN 0x00002000
#define OTG_GCCFG_VBDEN (1 << 21)
/*
* The B-peripheral session valid override (BVALOVAL and BVALOEN) bits got added
* in OTG FS CID 0x00002000
*/
#define OTG_CID_HAS_BVALOVAL 0x00002000

/* Provide the stings for the Index 1-n as a requested index of 0 is used for the supported langages
* and is hard coded in the usb lib. The array below is indexed by requested index-1, therefore
Expand Down Expand Up @@ -316,6 +328,12 @@ usb_cinit(void)

#if defined(BOARD_USB_VBUS_SENSE_DISABLED)
OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS;

if (OTG_FS_CID == OTG_CID_HAS_BVALOVAL) {
/* Force valid B-peripheral session */
OTG_FS_GOTGCTL |= OTG_GOTGCTL_BVALOEN | OTG_GOTGCTL_BVALOVAL;
}

#endif

usbd_dev = usbd_init(&otgfs_usb_driver, &dev, &config, usb_strings, NUM_USB_STRINGS,
Expand Down

0 comments on commit a6d0a51

Please sign in to comment.