Build and run a simple hello world program

Asked by Vikram K S

Hi,
I'm trying to build a simple hello world program and trying to run it on qemu simulator for cortex-m4. i'm able to build successfully but not able to run. I think i'm missing something or doing it wrongly.
Can someone please provide me steps to build and run a simple hello world program on qemu for cortex-m4?

Thanks,
Vikram

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Jiangning Liu
Solved:
Last query:
Last reply:
Revision history for this message
Best Jiangning Liu (liujiangning) said :
#1

Vikram,

Did you work on cortex-m3 already? I'm not sure your question is cortex-m4 specific or you only want to know how to build helloworld to run it on qemu.

Anyway, refer to screen copy&paste for cortex-m3 as below. I didn't try cortex-m4 yet, but I guess it wouldn't be different.

$ cat helloworld.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    fprintf (stdout, "Hello World!\n");
    return 0;
}
$ arm-none-eabi-gcc -Wl,-Map=output.map -mcpu=cortex-m3 -mthumb -specs=rdimon.specs -lrdimon -lc -lrdimon helloworld.c
$ qemu-system-arm -cpu cortex-m3 -nographic -serial null -monitor null -semihosting -kernel ./a.out
Hello World!
$

Thanks,
-Jiangning

Revision history for this message
Vikram K S (ksvikram) said :
#2

Hi Jiangning,
Thanks a lot... It works.. Actually i was not using appropriate options. This is the 1st time i'm trying all these.. i did not work on cortex-m3 already.

Thanks once again..

Regards,
Vikram

Revision history for this message
Mahavir (mahavirpj) said :
#3

Sorry to continue same thread...

Is it possible to change default memory map in above application (custom .text, .data etc.)? I am using codesourcery toolchain and it provides generic linker scripts (like generic-m-hosted.ld etc) which can be modified as per memory map of specific target device. It is really helpful to get semihosted application running on actual target device in early bringup phase.

[ref: http://balau82.wordpress.com/2011/09/03/using-codesourcery-bare-metal-toolchain-for-cortex-m3/]

Thanks,
Mahavir

Revision history for this message
Terry Guo (terry.guo) said :
#4

Hi Mahavir,

I am not linker script expert. In the readme.tex of our tool chain, there is a section which introduces an example linker scripts. Maybe it is helpful.

BR,
Terry

Revision history for this message
Terry Guo (terry.guo) said :
#5

Sorry for the typo. It is readme.txt in which you also can find a URL. Here is its short cut http://www.onarm.com/cmsis/download/18/cmsis-2-1-patch5-templates-for-gcc-arm-embedded-4-6/.

Revision history for this message
Mahavir (mahavirpj) said :
#6

Hi Terry,

Thanks for your reply. I will take a look.

Thanks,
Mahavir