Skip to content

Commit b2d97ae

Browse files
author
Alasdair Allan
authored
Merge pull request #1847 from michaelstoops/issues/1771
Added peripheral address for BCM2711 in response to #1771
2 parents bbae479 + 76abdb8 commit b2d97ae

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,56 @@
11
# Peripheral Addresses
22

3-
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.
3+
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 functions in [bcm_host.c](https://github.com/raspberrypi/userland/blob/3fd8527eefd8790b4e8393458efc5f94eb21a615/host_applications/linux/libs/bcm_host/bcm_host.c) to help provide platform independence.
4+
5+
**Note**: please use these functions rather than hardcoded values, as this will ensure future compatibility.
46

57
`unsigned bcm_host_get_peripheral_address()`
68

7-
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.
9+
This returns the ARM-side physical address where peripherals are mapped.
810

911
`unsigned bcm_host_get_peripheral_size()`
1012

11-
This returns the size of the peripheral's space, which is 0x01000000 for all models.
13+
This returns the size of the peripheral's space.
1214

1315
`unsigned bcm_host_get_sdram_address()`
1416

15-
This returns the bus address of the SDRAM. This is 0x40000000 on the Pi Zero, Pi Zero W, and the first generation of the Raspberry Pi and Compute Module (GPU L2 cached), and 0xC0000000 on the Pi 2, Pi 3 and Compute Module 3 (uncached).
17+
This returns the bus address of the SDRAM.
1618

17-
## Building a C program using these functions
19+
Here are the current values as of this writing, in table form:
1820

19-
The `include` file and library are installed by default on a Raspberry Pi OS system.
21+
| SoC | Peripheral Address | Peripheral Size | SDRAM Address | Source |
22+
| --- | --- | --- | --- | --- |
23+
| BCM2835 | 0x20000000 | 0x01000000 | 0x40000000 | [bcm2835.dtsi](https://github.com/raspberrypi/linux/blob/7f465f823c2ecbade5877b8bbcb2093a8060cb0e/arch/arm/boot/dts/bcm2835.dtsi#L21) |
24+
| BCM2836 | 0x3f000000 | 0x01000000 | 0xC0000000 | [bcm2836.dtsi](https://github.com/raspberrypi/linux/blob/7f465f823c2ecbade5877b8bbcb2093a8060cb0e/arch/arm/boot/dts/bcm2836.dtsi#L10) |
25+
| BCM2837 | 0x3f000000 | 0x01000000 | 0xC0000000 | [bcm2837.dtsi](https://github.com/raspberrypi/linux/blob/7f465f823c2ecbade5877b8bbcb2093a8060cb0e/arch/arm/boot/dts/bcm2837.dtsi#L9) |
26+
| BCM2711 | 0xfe000000 | 0x01800000 | 0xc0000000 | [bcm2711.dtsi](https://github.com/raspberrypi/linux/blob/7f465f823c2ecbade5877b8bbcb2093a8060cb0e/arch/arm/boot/dts/bcm2711.dtsi#L41) |
2027

21-
Add the following line to your C program:
28+
## Building a C program using these functions
29+
30+
The include file and library are installed by default on a Raspberry Pi OS system. Just add the following line to your C program:
31+
```C
32+
#include <bcm_host.h>
2233
```
34+
35+
Example:
36+
```C
37+
#include <stdio.h>
2338
#include <bcm_host.h>
39+
40+
int main(void) {
41+
printf("bcm_host_get_peripheral_address -> 0x%08x\n", bcm_host_get_peripheral_address());
42+
printf("bcm_host_get_peripheral_size -> 0x%08x\n", bcm_host_get_peripheral_size());
43+
printf("bcm_host_get_sdram_address -> 0x%08x\n", bcm_host_get_sdram_address());
44+
45+
return 0;
46+
}
2447
```
48+
2549
Link with:
2650
```
2751
-lbcm_host
2852
```
2953
So a simple command line compile might be:
30-
```
54+
```shell
3155
cc myfile.c -I/opt/vc/include -L/opt/vc/lib -lbcm_host -o myfile
3256
```

0 commit comments

Comments
 (0)