关于r3b的物理地址
重点是:
If there is no kernel driver available, and a program needs to access a peripheral address directly with mmap, it needs to know where in the virtual memory map the peripheral bus segment has been placed. This varies according to which model of Raspberry Pi is being used, so there are three helper function available to provide platform independence. Note: please use these functions rather than hardcoded values, as this will ensure future compatibility.
unsigned bcm_host_get_peripheral_address()
This returns the ARM-side physical address where peripherals are mapped. This is 0x20000000 on the Pi Zero, Pi Zero W, and the first generation of the Raspberry Pi and Compute Module, and 0x3f000000 on the Pi 2, Pi 3 and Compute Module 3.
所以,r3b的IO基址装载在物理地址0x3F000000处。
再参考下图:
1、VC CPU总线地址
2、ARM物理地址
3、ARM虚拟地址。
1、2之间通过VC/ARM MMU进行映射。
2、3之间通过ARM MMU来映射。
规格书上写的都是1。
内核操作的是2。
ioremap之后得到的应该是3。
比如现在要操作GPIO,IO在VC CPU总线上的基址是0x7E000000,在物理地址上的基址是0x3F000000。
我们看规格书:
GPFSEL0寄存器VC CPU总线地址是0x7E200000,相对基址偏移0x00200000,那么ARM物理地址也是偏移这么多,其ARM物理地址是0x3f200000。
同理,GPSET0的ARM物理地址是0x3f20001C。
用mmap函数或者ioremap函数将这两个ARM物理地址映射成虚拟地址,就等同于直接操作GPIO硬件地址了。
关于r3b的gpio控制寄存器
我们计划控制gpio4。
关注三个寄存器,即复用,set,clear。