HAL PeriBase wrong for Pi4
Timo Hartong (2813) 204 posts |
Today I have collected enough energy to continue on bluetooth. To work on the UART’s I use the variable ‘PeriBase’ this is set in line 290 in s.Top in the HAL sources. When I modify s.UART to give me the peribase in the function ‘HAL_UARTDevice’ by LDR a2, PeriBase I get the value &F700000 back instead of &FE000000 on a Pi400. With a model Pi 3B it is not even close.. |
Jon Abbott (1421) 2651 posts |
Unless I’m mistaken, is that not the physical address? |
Timo Hartong (2813) 204 posts |
If it were 7E oid it would say it is close. But this ‘bug’ can be closed I solved it diffently I now went for : |
Jeffrey Lee (213) 6048 posts |
Nothing is wrong. The CPU contains an MMU which the OS is able to use to adjust the memory map of the system. The CPU accesses memory & peripherals by using logical addresses, and the MMU uses a lookup table (the “page tables”) to remap those logical addresses to physical addresses. This is the magic that allows multiple Wimp tasks to all think that they’re running from &8000 – whenever a task switch occurs, the OS updates the page table entries for &8000+ so that they point to the physical memory containing the new task. This is much quicker than if there were no MMU and it had to copy the memory around. The MMU is also used for dynamic areas, and remapping peripherals. By remapping everything using the MMU, the OS is able to work around any potential quirks in the physical memory map. E.g. imagine how awkward it would be for RISC OS if there was a non-remappable hardware peripheral at &8000. So &F7000000 is the logical address of the peripherals, which will map to the correct physical address of &FE000000. Chances are that other models of Pi will also have a PeriBase value in the &Fx000000 range. Note: Don’t write code that makes assumptions about the logical addresses of peripherals. Under RISC OS 5 the address assignment is dynamic, and the base address which the allocations start from has moved a few times over the years. |
Timo Hartong (2813) 204 posts |
Of course how could I have overlooked this. The HAL looks to bare metal programming but it is isn’t. There is a an OS ;-) and a MMU how could I be so stupid ?. Thanks. I will change it back…and make a revised unit test. |