7 years, 6 months ago.

P0.29 & P0.30 as GPIO

Hello Guys,

I have a small question regarding P0.29 and P0.30 (USB). I'm using a self designed board and I would like to use these pins as GPIO. Only problem is that I can't get them to work.

At first I tried the code below, but this does not work the output still remains 0V.

#include "mbed.h"

DigitalOut test(P0_29);

int main() {

    test = 1;
    
    while(1)
    {
    
    }
}

Then I tried to do it this way, but this also doesn't work.

#include "mbed.h"

int main() {

    //Set to default register value (GPIO) (P0.29 and P0.30)
    LPC_PINCON->PINSEL1 &= ~((3<<26)|(3<<28)); 
    
    //Set pin 0.29 as output;
    LPC_GPIO0->FIODIR |= (1<<29);
    
    //Set 0.29 high
    LPC_GPIO0->FIOSET |= (1<<29);
    
    while(1)
    {
    
    }
}

Does anyone known where this is going wrong? Thanks!

1 Answer

7 years, 6 months ago.

Searched in the user manual on those pins, and the issue is:

Quote:

Note that GPIO pins P0.29 and P0.30 are shared with the USB_D+ and USB_D- pins and must have the same direction. If either FIO0DIR bit 29 or 30 are configured as zero, both P0.29 and P0.30 will be inputs. If both FIO0DIR bits 29 and 30 are ones, both P0.29 and P0.30 will be outputs.

So the following seems to work:

#include "mbed.h"
 
DigitalOut test(P0_29);
DigitalOut test1(P0_30);
 
int main() {
    test1=0;
    test = 1;
    
    while(1)
    {
        wait(1);
        test = !test;
    }
}

Accepted Answer

I knew it had the USB D + en D- on them, but it didn't occur to me to make them both outputs. Thanks!

posted by David Vaessen 24 Apr 2013