MicroZed Chronicles: Implementing Arm Cortex-M1 Processor Solution From Scratch, Software Solution

Creating the software solution for the Arm M1 processors in Xilinx FPGA.

Adam Taylor
4 years ago

Last week we examined how to implement an Arm Cortex-M1 processor core from scratch using the IP provided by the Arm DesignStart program. In this week’s blog, I am going to demonstrate how to configure the software element of the build.

Having used Vivado Design Suite to generate the bitstream which contained the processor and its tightly coupled instruction and data memories. Now, we need to create a board support package and the actual application. Once these have been created, we will be updating the tightly coupled instruction and data memories in the bitstream with the new application.

To create this software, we need to use the following tools:

1. Xilinx Software Development Kit (SDK) – This generates the board support package (BSP) which contains all the drivers and APIs for the hardware elements.

2. Arm Keil Microcontroller Development Kit (essentials version) – Generates the application executable.

We will also need the following scripts and batch files from the Arm example project. They are available under the hardware and software directories:

1. Make_mmi_file.tcl – Used in Vivado to create a file defining the memories used for the instruction and data memories.

2. Make_prog_files.bat – This will merge the BIT file with the ELF file created in Arm Keil to update the developed SW application.

3. Make_prog_files.tcl – TCL file sourced by the batch file above.

4. Make_hex_s7.bat – Used by ARM Keil to create the ELF and HEX files required.

Copy all these files into the working directory of the Vivado project.

Once the design is completed implementation in Vivado, we need to open the implemented project and use the TCL window to source the make_mmi_file.tcl. Make sure the working directory of the Vivado project is the project directory. This script must be run each time the BIT file is regenerated as the BRAM memories used may have changed.

With the MMI file generated, close the implementation view and export the hardware from the Vivado project and then open SDK. Note we do not need to include the BIT file.

For this example, I exported the hardware definition and set the workspace to be local to the project.

Opening Xilinx SDK from Vivado will result in SDK importing the hardware definition. The next thing we need to do is create a BSP. Select File->New-> Board Support Package.

Leave the project name as default and ensure the CPU is shown as the Cortex-M1 and click finish.

This will open a BSP configuration dialog. Check that the stdin and stdout are shown as axi_uartlite_0 on the standalone tab.

Once the BSP is generated, we have completed our use of Xilinx SDK. We can close the tool.

With the BSP completed, the next step is to create a new Keil project. Open Keil and create a new project in the same directory as the Vivado project.

Follow the open project dialog and select the Arm Cortex-M1 processor. On the next dialog, select CORE (under CMSIS) and startup (under device).

With the project created, the next step is to ensure the project options are correctly set. Make sure the name of the executable is set as m1_from_scratch and the HEX file output is enabled.

To ensure the HEX file is created on the user tab, we need to set the Make_hex_s7.bat batch file to be run after the compilation is completed.

On the C/C++ tab, the next step is to set the include paths to include the BSP just created in Xilinx SDK. You will find these files under:

<project directory>/<project_name>.sdk/standalone_bsp_0/cortexm1_axi_0/include

The final step is to ensure we have defined the scatter file and the misc. controls are set correctly. You can find the scatter file under the objects directory.

Finally, to enable Keil to be able to build the object files for the APIs defined in the BSP include directory, we need to include the source files as well.

The source files are available under the Xilinx SDK in the libsrc directory. For each of the functions used, we need to create a new project item in Arm Keil.

Under these project items, we need to include the source for that element. In this example, I needed to create just three project items because I am just going to say “hello world."

1) Main – The main application file of main.c will be created under here.

2) Xilinx_UART – The source files for the AXI UART Lite will be added under here. These are available from the BSP Lib Src directory.

3) Standalone_6_7 – This will include the files from the standalone 6.7 BSP which provide printf capability.

With the project created, we can create a simple “hello world” application and run it on the target.

Before we can build the project, we need to edit the scripts and batch files we copied across earlier to be updated for the new project name.

Edit the file Make_hex_s7.bat to reflect the name of the project. In this case, m1_from_scratch.

Similarly, edit the Make_prog_files.tcl script to include the updated source file location for the new project.

With these modifications completed, we can build the application in Keil and we should see HEX and ELF files with the correct time stamp appearing in the Vivado project directory.

Double click on the make_prog_files.bat and you will see a new programming file created which contains the program just created in Keil. Unlike a full Vivado implementation, this will not take very long to create.

Once this is created, we are able to open Hardware Manager in Vivado and connect to the Arty S7-50 Spartan-7 FPGA board and program the BIT file just created.

When you do this, make sure you have a terminal program connected first otherwise the “hello world” message might be missed. Remember unless you changed the baud rate, it will be 9600, no parity and one stop BIT.

When I ran this, I saw the output below.

Over the last two blogs, we have learned how to implement the Arm Cortex-M1 processor core from scratch in Xilinx FPGAs. Doing so is very easy and over the next few weeks we will look further at some of the advanced elements of the Arm Cortex-M1 core.

See My FPGA / SoC Projects: Adam Taylor on Hackster.io

Get the Code: ATaylorCEngFIET (Adam Taylor)

Access the MicroZed Chronicles Archives with over 300 articles on the FPGA / Zynq / Zynq MpSoC updated weekly at MicroZed Chronicles.

Adam Taylor
Adam Taylor is an expert in design and development of embedded systems and FPGA’s for several end applications (Space, Defense, Automotive)
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles