We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a very simple CortexM3 based virtual platform example as below
The amba_pv_m2 is connected to a memory in the top. The BusDecoder master port address range is 0x0-0x3FFFFFFF
I have the following C program
#include <stdio.h>
int main(int argc, char *argv[]){ printf("Hello!!!\n"); return 0;}
and the following make commands
armcc --cpu=Cortex-M3 -g -O2 -c -o hello.o hello.carmlink --cpu=Cortex-M3 --ro-base 0x00000000 -o hello.axf hello.o
With that when I load the axf into the core and execute, I see the Hello is printed.
Bow I want to load the SW at 0x40000000. For that I did the following chnages
- BusDecoder master port address range 0x40000000-0x7FFFFFFF and make command as
armcc --cpu=Cortex-M3 -g -O2 -c -o hello.o hello.carmlink --cpu=Cortex-M3 --ro-base 0x40000000 -o hello.axf hello.o
with that the when I run the platform, it stucks somewhere and I am not getting the Hello output.
It seems I am missing some thing here.
Can you guys help me on this ?
Thanks
Khushi
Hi. Have you ever seen the Cortex M3 memory map?
Thanks. Can you point me to some startup code example for my specific case ?
My experience related to real targets, not virtual, in your case you can't write code to the address 0x40000000, because this is the address range of peripheral registers. Write code to Code address range.
What startup code do you want?
Sorry but actually I am new to this.
I see armlink has options --ro-base and -rw-base. How these are related with CortexM3 application if I can only load my sw on 0x000000. Also I see some folks taking about some startup and boot code etc. When these are needed ?
I am looking for some simple example where in startup code I can map.
Thanks for your help
Ok, step by step.
Armlink - linker which links compiled code (object files) into an executable file, then this executable file will be flashed (by flashloader or debugger) into the memory of microcontroller or microprocessor (memory can be onboard or external to chip).
Read Only - for example flash memory of microcontroller which commonly starts at 0x0 memory address.
Read Write - this can be SRAM memory (SRAM for code, SRAM for data), DRAM or other external memory (always look at the memory map of microcontroller or microprocessor where the particular memory starts).
Different chipmakers implement different boot sequences for their chips.
First, when you power your chip it starts with special reset sequence to configure system (for example, configuring clocks for processor, system bus, flash memory), then it starts booting from reset address (it is in the vector table in the flash memory) and jumps to code section.
Startup code configures your system for work (your chip has to be configured to be ready to carry out your tasks), you can write this code to configure different clock frequencies or processor modes, to enable and to configure different controllers implemented on the chip (peripherals).
Only after reset and boot sequences your own code will be executed (for example, in your case the code from function main).
To start, you have to understand that Cortex M3 is only a core of processor or heart of processor, major manager of microcontroller.
Read appropriate literature about architecture of ARM Cortex M3 to understand how it works (ARM Cortex M3 Processor Technical Reference Manual, Cortex M3 Devices Generic User Guide, also you can read ARMv7-M Architecture Reference Manual for deeper understanding).
http://infocenter.arm.com/help/index.jsp
In addition to the excellent advice already given, you might want to consider getting a decent textbook to help you to properly understand the Cortex M3 architecture?
Joseph Yiu's book "The Definitive Guide to Arm Cortex M3 and Cortex M4 Processors" is a popular choice is highly recommended by many.
Another excellent book for beginners is Daniele Lacamera's book "Embedded Systems Architecture" (published by Packt in 2018) since this has chapters describing the boot process and memory layout for Arm-v8M MCUs. You can often get ebook versions of Packt books from their website for as little as $10 (or even free) so it is worth taking a look to see if there is anything else that might help you get started.
A few things to add:
Cortex-M3's initial vector table address is fixed at address 0x00000000. (This is different in Cortex-M7/M23/M33, which allows the initial vector table address to be configured by chip designers.
Startup code usually contain vector tables as well as some startup related code.
Example startup code for Cortex-M3 can be found in CMSIS github
https://github.com/ARM-software/CMSIS_5/tree/develop/Device/ARM/ARMCM3/Source
As Vanhealsing mentioned, the architecture used by Cortex-M processors has a predefined memory map, and address 0x40000000 is predefined as peripheral region and cannot be used for program code storage (same restriction for Device and system spaces). The predefined memory map simplifies startup as you don't need to configure which region to be cacheable.
regards,
Joseph