SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Running Cortex-M0 DesignStart Simulation in ModelSim on Linux
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

Running Cortex-M0 DesignStart Simulation in ModelSim on Linux

Scott Allen
Last updated: October 5, 2023 9:58 am
Scott Allen 8 Min Read
Share
SHARE

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.

Contents
PrerequisitesSetting Up the Simulation EnvironmentCompiling the Simulation ModelsRunning a SimulationSimulating Other ExamplesSimulating Your Own CodeSimulation PerformanceSimulation TroubleshootingNext Steps

Prerequisites

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:

make compile

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:

make hello

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:

make gui

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:

  1. Write your firmware code – this will be C/assembly code compiled for the Cortex-M0.
  2. Add a Makefile to build your code – use the examples as a reference.
  3. Re-run make compile to build your code.
  4. Create a testbench – copy an existing one and modify it to load your code.
  5. Run your testbench – make mytest will 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.

Simulation Performance

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.

Simulation Troubleshooting

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 rtl_work by running make compile.
  • 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.

Next Steps

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!

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Staying under code size limits when simulating Cortex-M0 in ModelSim Student
Next Article Fixing “unknown compiler option ‘-lint’” error when compiling Cortex-M0 in ModelSim
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

What is the purpose of the MMU?

The MMU, or Memory Management Unit, is a component in…

9 Min Read

Determining Stack Requirements When Using an RTOS on Arm Cortex-M

When developing embedded systems using an RTOS (real-time operating system)…

5 Min Read

Cortex M0 toggle pins not responding

If you are working with a Cortex M0 microcontroller and…

7 Min Read

Why ARM Processors are Low Power?

ARM processors are designed to be power-efficient and low-power for…

6 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account