This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Raw GPIO output without using API Functions?

Probably frowned upon but like being able to work from raw datasheet, so I know that I can. So given that the datasheet would suggest that changing a GPIO pin to be an output is as simple as setting a bit, as a specific address, to 1. So I would expect the code:

int main(int argc, char **argv)
{
    uint32_t *p0_outset = (uint32_t *)0x50000508;
    uint32_t *p0_dirset = (uint32_t *)0x50000518;

    *p0_dirset |= 0x01 << 17;
    *p0_dirset |= 0x01 << 18;

    *p0_outset |= 0x01 << 17;
    while (1) {
    }
}

to illuminate the LED on pin P0.18, as the uC is on the low side of the LED. Either that or the LED on pin P0.17 to light. As it is neither LED lights and I'm confused as to why. The GPIO section of the datasheet doesn't mention having to specifically enable that Peripheral?

Parents Reply Children
  • The purpose of this piece of code is to verify the build process and flashing of the target device. As soon as those stages have been verified the code will be dumped. So I'm not really going for human readable here. I want the compiler to be able to read it and the uC to be able to execute the resulting output hex file.

    Since nobody has pointed out any errors in the code, apart from no being to their individual taste and style I'll assume that the code's functionality is correct and the problem lies elsewhere.

Related