Firefly开源社区

RK3399 GPIO3引脚如何通过mmap去控制

63

积分

0

威望

0

贡献

游客

积分
63
发表于 2017-11-2 11:06:21     
通过mmap方式可以看读写gpio1引脚,可以读gpio3,但无法写gpio3,对应的CRU寄存器也不能写,不知道个人有没有遇到的或者官方是否有相应的文档。此外,通过io命令也不能直接修改
回复

使用道具 举报

63

积分

0

威望

0

贡献

游客

积分
63
发表于 2017-11-7 10:39:27     
没有人这样用的吗
回复

使用道具 举报

63

积分

0

威望

0

贡献

游客

积分
63
发表于 2017-11-7 15:12:42     
本帖最后由 iamFirefly 于 2017-11-7 15:20 编辑
  1. </blockquote><div class="blockcode"><blockquote><blockquote>#include <sys/mman.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>        

  5. #define MMAP_PATH        "/dev/mem"
  6. #define RK3399_GPIO_DATA  0x0000
  7. #define RK3399_GPIO_DIRC  0x0004
  8. #define DIRC_OUTPUT 1
  9. #define DIRC_INPUT 0
  10. #define DATA_LOW 0
  11. #define DATA_HIGH 1

  12. static uint8_t* gpio3_clocken_base_reg = NULL;
  13. static uint8_t* gpio3_iomux_base_reg = NULL;
  14. static uint8_t* gpio3_mmap_base_reg = NULL;

  15. int gpio_mmap_fd = 0;

  16. int gpio_mmap(void)
  17. {
  18.        if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR|O_SYNC)) < 0) {
  19.            fprintf(stderr, "unable to open mmap file");
  20.            return -1;
  21.         }
  22.    return 0;
  23. }
  24. //=============GPIO 3
  25. int getGpio3State()
  26. {
  27.       uint32_t con,iom,data,dirc;
  28.      printf("\n================\n      GPIO3 Info    \n");
  29.    /* clock en   */
  30.     gpio3_clocken_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,
  31.     MAP_SHARED, gpio_mmap_fd,0xff760000);      

  32.   con = *(volatile uint32_t *)(gpio3_clocken_base_reg+0x037c);
  33.   printf(" the clock config reg is %0x \n",con);

  34.     /* iomux */
  35.   gpio3_iomux_base_reg = (uint8_t*) mmap(NULL, 4096*4, PROT_READ | PROT_WRITE,
  36.   MAP_SHARED, gpio_mmap_fd,0xff770000);
  37. iom = *(volatile uint32_t *)(gpio3_iomux_base_reg+0xe01c);
  38.    printf(" the  iomux reg is %0x \n",iom);

  39.     /* input or output  */

  40.     gpio3_mmap_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,MAP_SHARED, gpio_mmap_fd,0xFF788000);
  41.   
  42.       dirc =  *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DIRC);
  43.        printf(" the direct reg is %0x \n",dirc);

  44.        data = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA);
  45.        printf("before set the data reg  is %0x \n",data);

  46. }

  47. void setGpio3State()
  48. {
  49.     uint32_t con,iom,data,dirc;
复制代码

回复

使用道具 举报

63

积分

0

威望

0

贡献

游客

积分
63
发表于 2017-11-7 15:21:08     
代码没发全,接楼上
  1. void setGpio3State()
  2. {
  3.         uint32_t con,iom,data,dirc;

  4.        
  5.                *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA)=0x00008000;
  6.     data = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA);
  7.        printf("after set the data  is %0x \n",data);
  8.    
  9. }


  10. int main()
  11. {
  12.   
  13.    int i;
  14.    gpio_mmap();

  15.    printf("\n=========== \n     gpio-3 info:   \n");
  16.    getGpio3State();
  17.    setGpio3State();


  18.         return 0;
  19. }
复制代码
回复

使用道具 举报

63

积分

0

威望

0

贡献

游客

积分
63
发表于 2017-11-7 15:23:33     
问题就是读完data寄存器的值后,在向data寄存器写入0x00008000,寄存器内的值未发生改变,写不了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表