The Cortex-M0 DesignStart is a free and easy way to start developing and prototyping designs using the Cortex-M0 processor from ARM. It includes everything needed to simulate the processor using ModelSim on Linux. This allows you to get up and running quickly without needing to buy expensive tools or IP upfront.
Before you can start simulating the Cortex-M0 DesignStart in ModelSim, you’ll need to have the following installed and configured on your Linux machine:
- ModelSim – this provides the simulation environment. You’ll need at least the ModelSim PE Student Edition, which is free for non-commercial use.
- GCC cross compiler – this compiles code to run on the Cortex-M0. The DesignStart includes a pre-built version.
- Perl – some of the simulation scripts use Perl, so you’ll need a Perl interpreter installed.
- Make – the build system uses Make to compile and simulate.
You’ll also need to have downloaded and unpacked the Cortex-M0 DesignStart files either from ARM directly or from GitHub. The DesignStart contains RTL code for the Cortex-M0 processor as well as testbenches and example code.
Setting Up the Simulation Environment
To simulate the DesignStart Cortex-M0 using ModelSim there are a few key environment variables that need to be configured:
- DESIGN_DIR – set this to the directory containing the extracted DesignStart files.
- PERL – set this to point to the Perl binary, e.g. /usr/bin/perl.
- MODELSIM_BIN – set this to the ModelSim executable, e.g. /tools/modelsim/bin/vsim.
There are scripts provided with the DesignStart that will check these variables are set correctly and warn if not. So it’s good practice to run:
source setup.sh checkenv.pl
This will help catch any issues with the environment before trying to simulate.
Compiling the Simulation Models
The next step is to compile the simulation models, testbenches, and example code. This is done by changing to the
sims directory under
DESIGN_DIR and running:
This will use the provided GCC cross compiler to build the simulation models and firmware examples. It will take a minute or two to run. You should see a “Build complete” message if it ran successfully.
Some key outputs from this process are:
rtl_work– the compiled simulation models for the Cortex-M0 DesignStart.
firmware– example firmware executables for running on the processor.
Running a Simulation
Now you are ready to actually simulate the Cortex-M0 DesignStart in ModelSim. There are testbenches provided for running different simulations. For example:
This will run the
hello test which loads a firmware image that prints “Hello World” to the UART output. The testbench instantiates the Cortex-M0 DesignStart RTL, connects up memory, clocks, etc., loads the firmware, and then advances time to execute the code.
To see the output of the simulation, open the ModelSim GUI using:
This will open the waveform viewer. You can add signals to see the processor executing instructions, cache hits/misses, bus activity, and peripheral IO. The UART output from the firmware will be printed to the ModelSim transcript window.
Simulating Other Examples
The process above can be repeated to simulate other examples. Some additional tests provided with the DesignStart include:
make dhrystone– runs the Dhrystone benchmark
make coremark– runs the CoreMark benchmark
make device– executes code using flash memory and SRAM models
Each example requires first compiling the firmware code, then executing the testbench that loads that firmware image. The ModelSim GUI can be opened to view simulation waveforms for any of the tests.
Simulating Your Own Code
In addition to the provided examples, you can also simulate your own firmware code on the Cortex-M0 DesignStart. This involves a few steps:
- Write your firmware code – this will be C/assembly code compiled for the Cortex-M0.
- Add a Makefile to build your code – use the examples as a reference.
make compileto build your code.
- Create a testbench – copy an existing one and modify it to load your code.
- Run your testbench –
make mytestwill simulate your code.
This allows you to fully exercise and debug your firmware on the Cortex-M0 RTL model before running it on real hardware.
Running gate-level simulations of a processor like the Cortex-M0 requires significant CPU time. The DesignStart examples take 5-10 minutes each to run on a typical modern Linux PC or Mac. There are a few options to improve simulation speed:
- Use more CPU cores – ModelSim simulations can run multiple threads.
- Reduce clock speed – the 1 MHz default clock allows visibility, a faster clock will run faster.
- Simulate for less cycles – edit the testbench to stop sooner.
Even with optimizations, simulating an entire real-world firmware application will take time. The DesignStart focuses on smaller directed tests and benchmarks to allow efficiently validating the Cortex-M0 model and getting started with firmware development.
Here are some common issues seen when simulating the Cortex-M0 DesignStart and how to resolve them:
- Errors compiling firmware – check the compiler is in the path and matches the target (arm-none-eabi-).
- Testbench fails to load – verify the ModelSim libraries are compiled into
- Simulation runs slow – try reducing the clock speed or number of cycles simulated.
- “Hello World” doesn’t print – check the UART is connected in the testbench and verify any changes made to the firmware code.
The DesignStart resources page also contains helpful tips for troubleshooting issues with simulation and compiling firmware.
Once you have successfully simulated examples and your own firmware on the Cortex-M0 in ModelSim, some next steps could include:
- Synthesizing the DesignStart onto an FPGA to run in hardware.
- Comparing simulation performance to running on real hardware.
- Stepping up to more advanced processor models like the Cortex-M3 or Cortex-M4.
- Leveraging ARM keil tools to develop and debug firmware.
The free Cortex-M0 DesignStart provides a simple yet powerful way to get started with ARM processors in ModelSim. The ability to simulate real-world firmware improves confidence prior to hardware testing and helps bring-up time once running on actual devices. Start simulating today and see what the DesignStart can do!