Hi !
Software access to Custom IP's registers under the Linux world can be done in so many ways !
This large choice of possibilities leaves beginners quite lost on how to start !
In this post we will start slowly and very easilly !
Let's do it old school using PEEK and POKE commands.
Even thow they are based on mmap that will see later in another post, these comands are still the same ! I read or write a physical address directly.
As this post is quite long, here are the main sections of this post for a quick jump :
Step 1 : Activate the PEEK and POKE commands in PetaLinux
Stage 1
The activation of the PEEK and POKE commands is done during the configuration step of the Rootfs in the PetaLinux tool.
So go the project's folder and use the following command.
Stage 2
This opens the configuration menu.
Then go to the apps menu.
And select the peekpoke application.
Then press escape several times to get out of the configuration menu.
Before leaving, you will be asked to save the modifications. Select Yes.
Then the configuration modification is done.
Now that configuration is done, you have to use the build comand again to generate the files.
Stage 3
The PEEK and POKE commands are in fact two Linux applications which source files can be found in project-spec/meta-user/recipes-apps/peekpoke/files/.
You'll see that these source codes are based on a system call named mmap (Memory Map).
You have to open the virtual file /dev/mem of the system memory, then make a mmap system call to the /dev/mem file to gain access to a physical address from the user space. More precisely, mmap will map an entire physical memory page, then your pointer can manipulate every offset in this memory page.
Step 2 : Use the PEEK and POKE commands in PetaLinux
Stage 1
First step here is to load the files to the MiniZed board.
Like the following previous post, we will use the JTAG commands from the PetaLinux tool.
2.7 - Generate a basic Linux over the custom IP
And then we will try the PEEK and POKE commands in a Putty terminal.
When in the terminal, try the commands to see if they are available.
OK, everything is ready !
Stage 2
Now, we have to find where are located the registers to access. This is the absolue physical address of our custom IP.
You can find the information :
- In the device tree file pl.dtsi, or
- In the VIVADO project, with the address mapping of the Block Design Editor.
So, for us it is 0x43C0_0000.
Stage 3
Now, to force the output led to ON, we only have to do the same steps as in the LED_TEST_IP_SetLedOn function of our driver.
Which gives.
And there you go !
The led is ON on the MiniZed board.
Stage 4
Now, to force the output led to ON, we only have to do the same steps as in the LED_TEST_IP_SetLedOff function of our driver.
Which gives.
And there you go !
The led is OFF on the MiniZed board.
Stage 5
Now, to force the output led to BLINK, we only have to do the same steps as in the LED_TEST_IP_SetLedBlink function of our driver.
Which gives.
And there you go !
The led blinks on the MiniZed board.
Post Conclusion
Now we have :
- Configured our Linux to have the PEEK and POKE commands available,
- Used the PEEK and POKE commands from the terminal to control the behavior of our custom IP.
For now we did not write a single line of software !
But yet with these commands we can control from the embedded Linux the registers of our IP, it can be usefull to make some debug tests. You can even write scripts to chain commands.
- Configured our Linux to have the PEEK and POKE commands available,
- Used the PEEK and POKE commands from the terminal to control the behavior of our custom IP.
For now we did not write a single line of software !
But yet with these commands we can control from the embedded Linux the registers of our IP, it can be usefull to make some debug tests. You can even write scripts to chain commands.









No comments:
Post a Comment