Using USB as GPIO Input

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SaWr_4498541
Level 1
Level 1
Welcome!

I'm using the CY8C6347BZI-BLD54 and want to configure USBDM (AKA PORT14_PIN1) as a digital input.

I attempt to do this with the Cy_GPIO_Pin_FastInit() function. However, no matter the logical state of the pin, the Cy_GPIO_Read() function always returns 0.

I expect the following to light an LED, but it is not:

int main(void) {

Cy_GPIO_Pin_FastInit( GPIO_PRT14, 1, CY_GPIO_DM_HIGHZ, 1, HSIOM_SEL_GPIO );

for(;;)

{

if(Cy_GPIO_Read(EXT_GPIO5_PORT, EXT_GPIO5_NUM) == 1UL) {

     // Light LED

}

}

}

Does anyone know why this wouldn't be functioning as I expect?

0 Likes
1 Solution
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

Below two registers should be configured to enable use USBIO as GPIO input pin.

/*Set USBIO to GPIO mode*/

*(uint32 *)CYREG_USBFS0_USBDEV_USBIO_CR1 |= (0x01u << CYFLD_USBFS_USBDEV_IOMODE__OFFSET);

/*  Set GPIO input enable */

*(uint32 *)CYREG_USBFS0_USBLPM_USBIO_CTL  |= ((0x01u << CYFLD_USBFS_USBLPM_DM_P__OFFSET) | (0x01u << CYFLD_USBFS_USBLPM_DM_M__OFFSET));

View solution in original post

4 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

When I tried with PSoC Creator at first I got  following error.

It seems that USBDM can be either CMOS_OUTPUT or HI_Z_ANALOG.

001-error.JPG

So I changed the pin to Hi-Z analog.

Since it's an analog input, I think that we need some trick to make it readable from the digital side.

So how about trying something like below?

(I have not tested it as I don't have a board with this MCU)

000-schematic.JPG

moto

0 Likes

Thanks for the reply moto.

I'm using PSoC Creator 4.3.0.1445 and those errors don't appear for me.

Annotation 2020-05-30 094005.jpg

Annotation 2020-05-30 094005 - 2.jpg

I'm happy to post my project too, if that is helpful and allowed on these forums.

The MCU has all other pins accounted for in our product, so using a USB pin as a GPIO Input would be a quick fix to a problem we are having.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I'm sorry for my insufficient description.

I'm also using PSoC Creator 4.3 (4.3.0.1445).

024-PSoC-Creator.JPG

First of all, I got the error when I set the pin as "Digital Input Resistive Pull Up"

020-Digital-Input-Pulled-Up.JPG

The error message was

Error: plm.M0046: E2728: <EXT_GPIO5(0)> cannot be placed at <P14[1]> because USB pins do not support drive modes other than CMOS_OUT and HI_Z_ANALOG.

021-error-at-generate-application.JPG

So I assumed that the only valid choice(s) were either "CMOS_OUT" or "HI_Z_ANALOG" in the previous reply.

I also tried

(1) High Impedance Digital

022-Hi_Z_Digital_Input.JPG

(2) High Impedance Analog

023-HI_Z_Analog_Input.JPG

Then to make the analog signal readable from the digital, I connected it through comparator to status register

025-analog-schematic.JPG

As the circuit it seemed fine, but as I tried to compile, I got the following error.

Error: fit.M0059: FFB and IO placement failed: Invalid pin assignment USBDM. This pin does not support ANALOG. (App=cydsfit)

So, although the first error message suggested that USBDM supports only CMOS_OUT and HI-Z-Analog,

the only choice the PSoC Creator allows is HI-Z-Digital, which you are using.

Then in the PSoC 63 with BLE Architecture Technical Reference Manual (TRM),

I found following lines

===================

30.3.1.5 GPIO Mode Logic

The D+ and D– pins can be used either as GPIO pins or

USB I/O pins. This is controlled by the IOMODE bit of the

USBDEV_USBIO_CR1 register. This bit should be set HIGH

for GPIO functionality and LOW for USB operation.

===================

In the PSoC 63 with BLE Registers Technical Reference Manual (TRM)

USBFS0_USBDEV_USBIO_CR1 0x403F0048

026-USBDEV_USBIO_CR1.JPG

So, how about trying

*(uint32_t *)CYREG_USBFS0_USBDEV_USBIO_CR1 |= (0x01 << CYFLD_USBFS_USBDEV_IOMODE__OFFSET) ;

moto

0 Likes
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

Below two registers should be configured to enable use USBIO as GPIO input pin.

/*Set USBIO to GPIO mode*/

*(uint32 *)CYREG_USBFS0_USBDEV_USBIO_CR1 |= (0x01u << CYFLD_USBFS_USBDEV_IOMODE__OFFSET);

/*  Set GPIO input enable */

*(uint32 *)CYREG_USBFS0_USBLPM_USBIO_CTL  |= ((0x01u << CYFLD_USBFS_USBLPM_DM_P__OFFSET) | (0x01u << CYFLD_USBFS_USBLPM_DM_M__OFFSET));