Turning ON an external LED using QNX RTOS

1,328 views
Skip to first unread message

Salman Feroze

unread,
Jul 3, 2015, 12:02:18 PM7/3/15
to beagl...@googlegroups.com
Hey guys,

I am relatively new in this forum, so please bear with me if the questions I ask would sound unintelligent. I am currently working with the Beagle Bone Black that is running QNX RTOS. I am trying to get my head around this board by developing simple programs such as turning ON an external LED that is connected to the board. So far, I have manage to identify a GPIO pin and set it to be an input using the data direction register (DDR) function. However, I am unable to move on from here.

Since I have enabled the pin to act as input, how would I be able to use it to turn ON an LED? What should be my next step be?

Any input/suggestion would be much appreciated.

Max

unread,
Jul 3, 2015, 1:58:19 PM7/3/15
to beagl...@googlegroups.com
If the pin acts as the input then it should read an external state. I would configure this pin as the output and then write 0/1 to a necessary bit position

Отправлено с iPad

3 июля 2015 г., в 19:02, Salman Feroze <salmanf...@gmail.com> написал(а):

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

William Hermans

unread,
Jul 3, 2015, 2:35:20 PM7/3/15
to beagl...@googlegroups.com
Salman, bear with me, as I know very little about QNX. If you could explain how you identified, and set the pin to input. That might help us better answer your question. WIth Debian, there are a few options, but no idea which of these options, if any are available with QNX.

Salman Feroze

unread,
Jul 4, 2015, 11:49:10 AM7/4/15
to beagl...@googlegroups.com
Hey guys,

Thanks in getting back to me I have posted the code that I used to enable a GPIO to act as input or an output below;


#include <stdlib.h>
#include <stdio.h>
#include <hw/inout.h>
#include <sys/mman.h>
#include <sys/neutrino.h>
#include <stdint.h>
#include <BeagleBoneIO.h>

 
uintptr_t MapIO(uintptr_t gpio_base, uint32_t BaseAddress)

{
    gpio_base = mmap_device_io(AM335X_GPIO_SIZE, BaseAddress);
    if(gpio_base == MAP_DEVICE_FAILED)
    {
        perror("Can't map device I/O for GPIO");
        printf("Main Terminated...!\n");
        return 0;
    }
    return gpio_base;
}
 

int WriteIO(uintptr_t gpio_base, int value, uint32_t BitsToModify)

{
    uint32_t val = 0;
    val  = in32(gpio_base + GPIO_DATAOUT);    // value that is currently on the GPIO port
 
    if (value==0)
    {
        val &= ~BitsToModify; // clear the bits
    }
    else
    {
        val |= BitsToModify;  // set the bits
    }
 
    out32(gpio_base + GPIO_DATAOUT, val);
 
    return 0;
}
 
 
int SetDDR(uintptr_t gpio_port, int Direction, uint32_t BitsToSet)

{
    uint32_t val = 0;

    // Read GPIO output enable register
    //  0 The corresponding GPIO port is configured as an output.
    //  1 The corresponding GPIO port is configured as an input.
    val  = in32(gpio_port + GPIO_OE);

    printf("value of register output enable register= %#010x\n", val);
   
if(Direction== 0)
        val &= ~(BitsToSet); // make sure they are 0
    else
        val |= BitsToSet;     // make sure they are set to 1
 
    out32(gpio_port + GPIO_OE, val); // write value to output enable
 
    val  = in32(gpio_port + GPIO_OE);
    printf("Modified value of register output enable register= %#010x\n", val);
 
    return 0;
}
 
uint32_t ReadIO(uintptr_t gpio_base, uint32_t BitsToRead)

{
    uint32_t val = 0;
    val  = in32(gpio_base + GPIO_DATAIN);    // value that is currently on the GPIO port
 
    printf("\nvalue of data register = %#010x\n", val);
 
    val &= BitsToRead; // mask bit
 
    printf("value of data register after masking it = %#010x\n", val);
 
    return val;
}
 
 
int main(int argc, char *argv[])

{
    printf("Welcome to the QNX Momentics BeagleBone GPIO Reader\n");
 
    uintptr_t    gpio0_port = 0;
    uintptr_t    gpio1_port = 0;
    uintptr_t    gpio2_port = 0;
    uintptr_t    gpio3_port = 0;
    uint32_t    val = 0;
 
    ThreadCtl(_NTO_TCTL_IO,NULL);    // Request I/O privileges; let the thread execute the I/O opcodes
                                    // in, ins, out, outs, cli, sti on architectures where it has the
                                    // appropriate privilege, and let it attach IRQ handlers. You need
                                    // root permissions to use this command. If a thread attempts to use
                                    // faults with a SIGSEGV when the opcode is attempted.
 
 
    uintptr_t gpio_base;
 
    gpio_base = mmap_device_io(0x08, 0x44e10844);
  
 if(gpio_base == MAP_DEVICE_FAILED)
  
 {
        perror("Can't map Control Base Module");
        printf("Main Terminated...!\n");
        return 0;
    }
   
printf("Device gpio_base\t = %#010x\n", gpio_base);
 

     gpio1_port = MapIO(gpio1_port, AM335X_GPIO1_BASE);
 
 
    // set the data direction
 
    SetDDR(gpio1_port,1, GPIO1_28); // Main function of setting up pin 28 as an input

    munmap_device_io(gpio1_port, AM335X_GPIO_SIZE);
 
    printf("\nAll good - Main Terminated...!\n");
    return EXIT_SUCCESS;
 
}


So what I've done above is, writing up a data direction register function and writing to GPIO 28 to be an input(1). If I were to set GPIO 28 as an output, I have to to just change   SetDDR(gpio1_port, 0, GPIO1_28).

Hope it helps!

You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/sRd8cPOoKEU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.

William Hermans

unread,
Jul 4, 2015, 11:08:10 PM7/4/15
to beagl...@googlegroups.com
Ok, so you used mmap. I have not  read your whole source listing there but that seems evident.

I can say though that you already have more experience in this area than me. As I've not written any C / mmap code to directly manipulate gpio registers.

With that said, there are many blogposts on the subject of beaglebone using mmap with GPIO, etc on the internet. There was even a hackaday post on someone talking about sysfs versus mmap and mmap being close to 1000x faster. Anyway this person also posted code on guthub . . .

Short of telling you to "search the web and find information". What is it exactly that you need help understanding ? As I may not personally be able to give you a 100% correct answer off the top of my head. But I *may* be able to point you to a resource that could answer your question. Just keep in mind when I say there is a "lot" of information out there on the subject. There really is.

Keywords "beaglebone black mmap gpio" will give lots of information on the subject. Otherwise.

Salman Feroze

unread,
Aug 1, 2015, 2:20:06 AM8/1/15
to beagl...@googlegroups.com
Sorry for the delay in getting back to you. I got the issue sorted out! Thanks a lot for your help :)

dhaneshwa...@gmail.com

unread,
Mar 21, 2017, 7:46:34 AM3/21/17
to BeagleBoard
HI Salman, 

Can you please upload your beagleboneio.h header file here?
I am unable to understand the parameters passed as arguments in below line.
    gpio_base = mmap_device_io(AM335X_GPIO_SIZE, BaseAddress); 
what should i give if Ineed to blink  LED on GPIO1_17 pin?

Regards,
Dhaneshwari
Reply all
Reply to author
Forward
0 new messages