Firefly开源社区
标题:
RK3399 GPIO3引脚如何通过mmap去控制
[打印本页]
作者:
iamFirefly
时间:
2017-11-2 11:06
标题:
RK3399 GPIO3引脚如何通过mmap去控制
通过mmap方式可以看读写gpio1引脚,可以读gpio3,但无法写gpio3,对应的CRU寄存器也不能写,不知道个人有没有遇到的或者官方是否有相应的文档。此外,通过io命令也不能直接修改
作者:
iamFirefly
时间:
2017-11-7 10:39
没有人这样用的吗
作者:
iamFirefly
时间:
2017-11-7 15:12
本帖最后由 iamFirefly 于 2017-11-7 15:20 编辑
</blockquote><div class="blockcode"><blockquote><blockquote>#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MMAP_PATH "/dev/mem"
#define RK3399_GPIO_DATA 0x0000
#define RK3399_GPIO_DIRC 0x0004
#define DIRC_OUTPUT 1
#define DIRC_INPUT 0
#define DATA_LOW 0
#define DATA_HIGH 1
static uint8_t* gpio3_clocken_base_reg = NULL;
static uint8_t* gpio3_iomux_base_reg = NULL;
static uint8_t* gpio3_mmap_base_reg = NULL;
int gpio_mmap_fd = 0;
int gpio_mmap(void)
{
if ((gpio_mmap_fd = open(MMAP_PATH, O_RDWR|O_SYNC)) < 0) {
fprintf(stderr, "unable to open mmap file");
return -1;
}
return 0;
}
//=============GPIO 3
int getGpio3State()
{
uint32_t con,iom,data,dirc;
printf("\n================\n GPIO3 Info \n");
/* clock en */
gpio3_clocken_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_SHARED, gpio_mmap_fd,0xff760000);
con = *(volatile uint32_t *)(gpio3_clocken_base_reg+0x037c);
printf(" the clock config reg is %0x \n",con);
/* iomux */
gpio3_iomux_base_reg = (uint8_t*) mmap(NULL, 4096*4, PROT_READ | PROT_WRITE,
MAP_SHARED, gpio_mmap_fd,0xff770000);
iom = *(volatile uint32_t *)(gpio3_iomux_base_reg+0xe01c);
printf(" the iomux reg is %0x \n",iom);
/* input or output */
gpio3_mmap_base_reg = (uint8_t*) mmap(NULL, 4096, PROT_READ | PROT_WRITE,MAP_SHARED, gpio_mmap_fd,0xFF788000);
dirc = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DIRC);
printf(" the direct reg is %0x \n",dirc);
data = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA);
printf("before set the data reg is %0x \n",data);
}
void setGpio3State()
{
uint32_t con,iom,data,dirc;
复制代码
作者:
iamFirefly
时间:
2017-11-7 15:21
代码没发全,接楼上
void setGpio3State()
{
uint32_t con,iom,data,dirc;
*(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA)=0x00008000;
data = *(volatile uint32_t *)(gpio3_mmap_base_reg+RK3399_GPIO_DATA);
printf("after set the data is %0x \n",data);
}
int main()
{
int i;
gpio_mmap();
printf("\n=========== \n gpio-3 info: \n");
getGpio3State();
setGpio3State();
return 0;
}
复制代码
作者:
iamFirefly
时间:
2017-11-7 15:23
问题就是读完data寄存器的值后,在向data寄存器写入0x00008000,寄存器内的值未发生改变,写不了
欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/)
Powered by Discuz! X3.1