我正在尝试为Raspberry PI创建自定义的UART驱动程序。
我尝试对MMIO进行映射。但是ioremap
始终返回NULL
。
#define UART_REG_BASE_ADDR 0x7E20100
pUart = ioremap(UART_REG_BASE_ADDR, 1024);
if (pUart==NULL)
{
printk("Couldn't remap UART MMIO\n");
return -EIO;
}
dmesg
转储以下内容:[ 2906.579848] CPU: 0 PID: 4983 Comm: insmod Tainted: G D W O 3.18.5+ #1
[ 2906.590783] [<c0014b64>] (unwind_backtrace) from [<c00120ec>] (show_stack+0x20/0x24)
[ 2906.614046] [<c00120ec>] (show_stack) from [<c0549008>] (dump_stack+0x20/0x28)
[ 2906.624803] [<c0549008>] (dump_stack) from [<c0022620>] (warn_slowpath_common+0x7c/0x9c)
[ 2906.647925] [<c0022620>] (warn_slowpath_common) from [<c002266c>] (warn_slowpath_null+0x2c/0x34)
[ 2906.668656] [<c002266c>] (warn_slowpath_null) from [<c001a888>] (__arm_ioremap_pfn_caller+0x240/0x25c)
[ 2906.691936] [<c001a888>] (__arm_ioremap_pfn_caller) from [<c001a934>] (__arm_ioremap_caller+0x68/0x70)
[ 2906.713171] [<c001a934>] (__arm_ioremap_caller) from [<c001a3d0>] (__arm_ioremap+0x24/0x2c)
[ 2906.735043] [<c001a3d0>] (__arm_ioremap) from [<bf19c028>] (hello_init+0x28/0x88 [domotx])
[ 2906.755780] [<bf19c028>] (hello_init [domotx]) from [<c000873c>] (do_one_initcall+0x94/0x1e4)
[ 2906.778165] [<c000873c>] (do_one_initcall) from [<c0087e70>] (load_module+0x1848/0x1e38)
[ 2906.799410] [<c0087e70>] (load_module) from [<c008854c>] (SyS_init_module+0xec/0xf0)
[ 2906.822660] [<c008854c>] (SyS_init_module) from [<c000e980>] (ret_fast_syscall+0x0/0x48)
[ 2906.844558] ---[ end trace c7cdd8b3d5007a1b ]---
[ 2906.856382] Couldn't remap UART MMIO
我做错了什么?
最佳答案
我找到了上面报告的问题的解决方案。实际上,解决方案有两个方面:
BCM2835数据表未在其数据表中发布物理地址:
外设的物理地址范围从0x20000000到0x20FFFFFF。外设的总线地址设置为映射到从0x7E000000开始的外设总线地址范围。因此,此处在总线地址0x7Ennnnnn上发布的外围设备在物理地址0x20nnnnnn上可用。
数据表中有一个错字:
PL011 USRT映射在基本加法器0x7E20100上。必须为PL011 USRT映射到基本加法器0x7E201000。
关于linux - ioremap返回NULL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28306165/