Using CMake for PRU
Directions on having the CMake build system copy the PRU folder to the NFS folder.
Start with the suggested CMake project folder structure for assignments and then make the following changes. It will then automatically copy your PRU folder into the NFS folder each time you rebuild with CMake. Once copied to NFS, built the PRU code on the target.
-
In your CMake project (which already has a
hal/
andapp/
folder), add anpru-as4/
folder for the PRU files (such asresource_table_empty.h
,AM335x_PRU.cmd
, and your PRU's.c
file). -
Put the shared memory
.h
file inpru-as4/
. -
Add the following to
app/CMakeLists.txt
(orhal/CMakeLists.txt
, depending on where your put your code which doesmmap()
) to include the shared memory.h
file from the PRU folder:include_directories(../pru-as4/)
-
Configure CMake to copy
pru-as4/
to~/cmpt433/public/pru/
anytime CMake rebuilds the app: a) Add the following to/CMakeLists.txt
:add_subdirectory(pru-as4)
b) Create
pru-as4/CMakeLists.txt
with the content:# Always run our custom command to copy PRU code to NFS # Source: https://stackoverflow.com/a/31518137 add_custom_target( my_custom_target_that_always_runs ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/__this_file_never_exists__.h ) # Copy the PRU code folder to NFS add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/__this_file_never_exists__.h # fake! ensure we run! COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/pru-as4" "~/cmpt433/public/pru/pru-as4" COMMENT "=======> Copying PRU code to public NFS directory... You must build /install on BBG <=======" )
-
Each time you change the PRU code and build with CMake, also run the PRU folder’s makefile on the BBG. It will build the firmware and then install it onto the PRU:
(bbg) $ cd /mnt/remote/pru/pru-as4
(bbg) $ make
(bbg) $ sudo make install_PRU0