Skip to content

Commit

Permalink
Migrate firmware examples to pru-gcc
Browse files Browse the repository at this point in the history
The firmware examples have been moved to gnupru
(https://github.com/dinuxbg/gnupru). The modifications done are:
1. header files - The register declarations for CT_CFG, CT_MBX and
CT_INTC have been changed.
2. fimware : main - __R30 and __R31 are not available. Instead
write_r30(), read_r30(), write_r31() and read_r31() have been used.
3. firmware: resource tables - modified according to the pru-gcc way of
generating elf files.
4. Makefiles - Modified to use pru-gcc
  • Loading branch information
MuneebMohammed committed Jun 19, 2018
1 parent e4583a0 commit 6260772
Show file tree
Hide file tree
Showing 24 changed files with 482 additions and 568 deletions.
177 changes: 83 additions & 94 deletions examples/firmware_examples/blinky/Makefile
@@ -1,97 +1,86 @@
# PRU_CGT environment variable must point to the TI PRU code gen tools directory. E.g.:
#(Desktop Linux) export PRU_CGT=/path/to/pru/code/gen/tools/ti-cgt-pru_2.1.2
#(Windows) set PRU_CGT=C:/path/to/pru/code/gen/tools/ti-cgt-pru_2.1.2
#(ARM Linux*) export PRU_CGT=/usr/share/ti/cgt-pru
# Copyright (c) 2015, Dimitar Dimitrov
# All rights reserved.
#
# *ARM Linux also needs to create a symbolic link to the /usr/bin/ directory in
# order to use the same Makefile
#(ARM Linux) ln -s /usr/bin/ /usr/share/ti/cgt-pru/bin

ifndef PRU_CGT
define ERROR_BODY

*******************************************************************************
PRU_CGT environment variable is not set. Examples given:
(Desktop Linux) export PRU_CGT=/path/to/pru/code/gen/tools/ti-cgt-pru_2.1.2
(Windows) set PRU_CGT=C:/path/to/pru/code/gen/tools/ti-cgt-pru_2.1.2
(ARM Linux*) export PRU_CGT=/usr/share/ti/cgt-pru

*ARM Linux also needs to create a symbolic link to the /usr/bin/ directory in
order to use the same Makefile
(ARM Linux) ln -s /usr/bin/ /usr/share/ti/cgt-pru/bin
*******************************************************************************

endef
$(error $(ERROR_BODY))
endif

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(notdir $(patsubst %/,%,$(dir $(MKFILE_PATH))))
PROJ_NAME=$(CURRENT_DIR)
LINKER_COMMAND_FILE=./AM335x_PRU.cmd
LIBS=--library=../../lib/rpmsg_lib.lib
INCLUDE=--include_path=../../include --include_path=../../include/am335x
STACK_SIZE=0x100
HEAP_SIZE=0x100
GEN_DIR=gen

#Common compiler and linker flags (Defined in 'PRU Optimizing C/C++ Compiler User's Guide)
CFLAGS=-v3 -O2 --display_error_number --endian=little --hardware_mac=on --obj_directory=$(GEN_DIR) --pp_directory=$(GEN_DIR) -ppd -ppa
#Linker flags (Defined in 'PRU Optimizing C/C++ Compiler User's Guide)
LFLAGS=--reread_libs --warn_sections --stack_size=$(STACK_SIZE) --heap_size=$(HEAP_SIZE)

TARGET=$(GEN_DIR)/$(PROJ_NAME).out
MAP=$(GEN_DIR)/$(PROJ_NAME).map
SOURCES=$(wildcard *.c)
#Using .object instead of .obj in order to not conflict with the CCS build process
OBJECTS=$(patsubst %,$(GEN_DIR)/%,$(SOURCES:.c=.object))

all: printStart $(TARGET) printEnd

printStart:
@echo ''
@echo '************************************************************'
@echo 'Building project: $(PROJ_NAME)'

printEnd:
@echo ''
@echo 'Output files can be found in the "$(GEN_DIR)" directory'
@echo ''
@echo 'Finished building project: $(PROJ_NAME)'
@echo '************************************************************'
@echo ''

# Invokes the linker (-z flag) to make the .out file
$(TARGET): $(OBJECTS) $(LINKER_COMMAND_FILE)
@echo ''
@echo 'Building target: $@'
@echo 'Invoking: PRU Linker'
$(PRU_CGT)/bin/clpru $(CFLAGS) -z -i$(PRU_CGT)/lib -i$(PRU_CGT)/include $(LFLAGS) -o $(TARGET) $(OBJECTS) -m$(MAP) $(LINKER_COMMAND_FILE) --library=libc.a $(LIBS)
@echo 'Finished building target: $@'

# Invokes the compiler on all c files in the directory to create the object files
$(GEN_DIR)/%.object: %.c
@mkdir -p $(GEN_DIR)
@echo ''
@echo 'Building file: $<'
@echo 'Invoking: PRU Compiler'
$(PRU_CGT)/bin/clpru --include_path=$(PRU_CGT)/include $(INCLUDE) $(CFLAGS) -fe $@ $<

.PHONY: all clean

# Remove the $(GEN_DIR) directory
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of the copyright holders nor the names of
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Very simple makefile to cross-compile for PRU


# Common flags
CROSS_COMPILE ?= pru-
CFLAGS += -g -Os
CFLAGS += -Wall -Wextra

# Headers needed by the TI rpmsg library.
CFLAGS += -I../../include -I../../include/am335x

# Define this to squeeze code size by removing atexit, exit, constructors
# and destructors from CRT.
CFLAGS += -minrt

# Per-PRU core flags. The -mmcu option will select the correct linker
# script and will predefine mcu-specific macros.
CFLAGS0 += -mmcu=am335x.pru0
CFLAGS1 += -mmcu=am335x.pru1

# List of source files to compile for each PRU core.
SRC0 :=
SRC1 := PRU_gpioToggle.c

# GCC's -MMD does not yield the needed C dependencies when compiling all
# C source files at once. So manually list headers here.
HEADERS := $(wildcard *.h) $(wildcard ../include/*.h ../include/am335x/*.h)

# Where to output compiled objects
OUT := gen

# Final ELF image file names
ELF0 :=
ELF1 := $(OUT)/blinky.elf

# ============================ DO NOT TOUCH BELOW ============================
all: $(ELF0) $(ELF1)
@echo Success: $^

%.s : %.elf
$(CROSS_COMPILE)objdump -S -d $< > $@

$(OUT):
mkdir $(OUT)

$(ELF0): $(SRC0) $(HEADERS) | $(OUT)
$(CROSS_COMPILE)gcc $(CFLAGS) $(CFLAGS0) $(SRC0) $(LDFLAGS) -o $@

$(ELF1): $(SRC1) $(HEADERS) | $(OUT)
$(CROSS_COMPILE)gcc $(CFLAGS) $(CFLAGS1) $(SRC1) $(LDFLAGS) -o $@

clean:
@echo ''
@echo '************************************************************'
@echo 'Cleaning project: $(PROJ_NAME)'
@echo ''
@echo 'Removing files in the "$(GEN_DIR)" directory'
@rm -rf $(GEN_DIR)
@echo ''
@echo 'Finished cleaning project: $(PROJ_NAME)'
@echo '************************************************************'
@echo ''

# Includes the dependencies that the compiler creates (-ppd and -ppa flags)
-include $(OBJECTS:%.object=%.pp)
$(RM) -fr $(ELF0) $(ELF1) $(OUT)

cscope:
cscope -bRk

.PHONY: all clean cscope
11 changes: 7 additions & 4 deletions examples/firmware_examples/blinky/PRU_gpioToggle.c
@@ -1,4 +1,6 @@
/*
* Source Modified by Mohammed Muneeb
*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
*
*
Expand Down Expand Up @@ -32,15 +34,15 @@
*/

#include <stdint.h>
#include <pru/io.h>
#include <pru_cfg.h>
#include "resource_table_empty.h"

volatile register uint32_t __R30;
volatile register uint32_t __R31;

void main(void)
int main(void)
{
volatile uint32_t gpio;
volatile uint32_t R30 = read_r30();

/* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
Expand All @@ -50,7 +52,8 @@ void main(void)

/* TODO: Create stop condition, else it will toggle indefinitely */
while (1) {
__R30 ^= gpio;
R30 ^= gpio;
write_r30(R30);
__delay_cycles(100000000);
}
}
Expand Down
21 changes: 14 additions & 7 deletions examples/firmware_examples/blinky/resource_table_empty.h
Expand Up @@ -58,14 +58,21 @@ struct my_resource_table {

uint32_t offset[1]; /* Should match 'num' in actual definition */
};
#if !defined(__GNUC__)
#pragma DATA_SECTION(resourceTable, ".resource_table")
#pragma RETAIN(resourceTable)
#define __resource_table
#else
#define __resource_table __attribute__((section(".resource_table")))
#endif

#pragma DATA_SECTION(pru_remoteproc_ResourceTable, ".resource_table")
#pragma RETAIN(pru_remoteproc_ResourceTable)
struct my_resource_table pru_remoteproc_ResourceTable = {
1, /* we're the first version that implements this */
0, /* number of entries in the table */
0, 0, /* reserved, must be zero */
0, /* offset[0] */
struct my_resource_table pru_remoteproc_ResourceTable __resource_table = {
{
1, /* we're the first version that implements this */
0, /* number of entries in the table */
{ 0, 0 }, /* reserved, must be zero */
},
{ 0 }, /* offset[0] */
};

#endif /* _RSC_TABLE_PRU_H_ */
Expand Down

0 comments on commit 6260772

Please sign in to comment.