Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. /dev/mem
Forum Updated to NodeBB v4.3 + New Features

/dev/mem

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 7.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f.vanalmetelevic.com
    wrote on last edited by
    #1

    I have to address gpio's on an embedded device (with MX27 processor) from my Qt application. I think I can do it via memory mapping, i.e. using /dev/mem. I found some examples in C code using mmap. However, I don't know how to do it in Qt. Is it possible to use QFile for opening the device (and then use map() function to do the mapping) ? Or do I have to subclass QIODevice and implement things myself ? Are there better alternatives to address gpio ? Maybe an example ?

    Thanks !

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jbarron
      wrote on last edited by
      #2

      There is an abstraction for mmap in QFile:

      "http://doc.trolltech.com/4.6/qfile.html#map":http://doc.trolltech.com/4.6/qfile.html#map

      1 Reply Last reply
      0
      • F Offline
        F Offline
        f.vanalmetelevic.com
        wrote on last edited by
        #3

        This is the way I do it :

        @ uchar *gpio;
        QFile f("/dev/mem");
        if (f.open(QIODevice::ReadWrite) == false)
        {
        std::cerr << "Could not open /dev/mem : " << strerror(errno) << std::endl;
        exit (1);
        }

        f.flush();
        gpio = f.map(0x10015000UL, 4096);
        
        if (gpio == 0)
        {
          std::cerr << "Mapping failed : " << strerror(errno) << std::endl;
        }
        

        @

        However, when running the application I get the following message on the console output :

        QFSFileEngine::map: Mapping a file beyond its size is not portable

        And I get the "Mapping failed" message indicating the map function returned a 0.
        Did I make a mistake in using QFile and map ?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          f.vanalmetelevic.com
          wrote on last edited by
          #4

          As a first experiment, I build my application for my host (Ubuntu 10.04). Can it be a problem when I use /dev/mem of the host pc to test mapping functionality ?

          I also tested the mapping in its 'basic' way :

          @ int fd;
          void* map_base;

          if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
          {
            std::cerr << "Failed to open /dev/mem : " << strerror(errno) << std::endl;
            exit (1);
          }
          
          std::cerr << "Open successful" << std::endl;
          
          map_base = mmap (0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x10015000UL);
          
          if (map_base == MAP_FAILED)
          {
            std::cerr << "Mapping failed : " << strerror(errno) << std::endl;
            exit (2);
          }
          
          std::cerr << "mapped on :" << map_base << std::endl;
          

          @

          But this also fails. The opening of the device is successful, but the mapping fails with :

          Mapping failed : Operation not permitted

          Any ideas ?

          1 Reply Last reply
          0
          • F Offline
            F Offline
            f.vanalmetelevic.com
            wrote on last edited by
            #5

            The second way of working, using mmap (see previous message), seems to work on my embedded device. Mmap is returning a valid address. So, it looks like it will work that way. Still have to test if I can really address the hardware on these addresses...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved