juribeparada / MMDVM_HS

MMDVM HotSpot: firmware for ZUMspot or MMDVM_HS based boards (D-Star, DMR, YSF, P25, NXDN and POCSAG)
GNU General Public License v2.0
358 stars 141 forks source link

GPIO pin configuration for USB-CDC #108

Open jg1uaa opened 5 years ago

jg1uaa commented 5 years ago

Recently I got USB supported MMDVM_HS_Hat from AliExpress, and it is programmed USB-CDC capable firmware. I build recent MMDVM_HS firmware and installed, OpenBSD (I don't know about other OSes) cannot recognized MMDVM board like this.

Nov  6 05:48:12 framboise /bsd: ugen1 at uhub9 port 3 "LeafLabs Maple 003" rev 1.00/2.01 addr 4
Nov  6 05:48:13 framboise /bsd: ugen1 detached
Nov  6 05:48:15 framboise /bsd: uhub9: port 3, set config 0 at addr 4 failed
Nov  6 05:48:15 framboise /bsd: uhub9: device problem, disabling port 3

generic_boot20_pc13_long_rst.bin bootloader works fine, but it looks a problem when switching bootloader to MMDVM_HS software. I used USB analyzer to investigate and I found there is a moment that MMDVM_HS cannot respond from Host(OpenBSD)'s request. Here is the log.

         SETUP ADR=3   ENP=0 DATA0 00 09 01 00 00 00 00 00   ACK  SET_CONFIGURATION
                                                                  Conf.val = 1
          I N  ADR=3   ENP=0 DATA1                           ACK
SOF=159 - 56D
SOF=71F - 7FF:000 - 03F
SOF=040  SETUP ADR=0   ENP=0 DATA0 80 06 00 01 00 00 08 00        GET_DESCRIPTOR
                                                                  (device)
         SETUP ADR=0   ENP=0 DATA0 80 06 00 01 00 00 08 00        GET_DESCRIPTOR
                                                                  (device)
         SETUP ADR=0   ENP=0 DATA0 80 06 00 01 00 00 08 00        GET_DESCRIPTOR
                                                                  (device)
         SETUP ADR=0   ENP=0 DATA0 82 00 00 00 00 00 02 00        GET_STATUS
         SETUP ADR=0   ENP=0 DATA0 82 00 00 00 00 00 02 00        GET_STATUS
         SETUP ADR=0   ENP=0 DATA0 82 00 00 00 00 00 02 00        GET_STATUS
SOF=041 - 0A2

SET_CONFIGURATION is processed by bootloader. Launched MMDVM_HS disconnects and reconnects USB, and OpenBSD sends GET_DESCRIPTOR(device) request but there is no ACK handshake. (note: OpenBSD always starts GET_DESCRIPTOR(device) request when USB device is connected)

Simply I tried to get rid of GPIO_Mode_IN_FLOATING setting to GPIO_Pin_11/12 like my repo (see https://github.com/jg1uaa/MMDVM_HS/commit/f8d18f18c383a5d6555f53eb996d7f08833926ef), it works fine.

Nov  6 06:39:28 framboise /bsd: ugen1 at uhub9 port 3 "LeafLabs Maple 003" rev 1.00/2.01 addr 4
Nov  6 06:39:29 framboise /bsd: ugen1 detached
Nov  6 06:39:31 framboise /bsd: umodem0 at uhub9 port 3 configuration 1 interface 0 "LeafLabs Maple" rev 2.00/2.00 addr 4
Nov  6 06:39:31 framboise /bsd: umodem0: data interface 1, has CM over data, has break
Nov  6 06:39:31 framboise /bsd: umodem0: status change notification available
Nov  6 06:39:31 framboise /bsd: ucom1 at umodem0

I don't know what causes this problem. But I think there is some misconfiguration of GPIO and mismatch between software and hardware about controlling USB connect/disconnect GPIO.

usb/usb_serial.cpp in STM32F10x_Lib controls USB connect/disconnect by GPIO PB10 (https://github.com/juribeparada/STM32F10X_Lib/blob/1debc23063f3942608e2bd62d04d5e1249c47fa3/usb/usb_serial.cpp#L50), but is this already used by I2C module? (Used bootloader is enahnced version of LeafLab's Maple board, this uses PB9 to control USB connection).

Is there any good resolution to solve this problem??

jg1uaa commented 5 years ago

I found this problem occurs JumboSPOT as USB bus-powered device, not occurs as self-powered device.