This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

New to Arm cortex m3

Note: This was originally posted on 9th June 2009 at http://forums.arm.com

Hi everyone,
I recently got an Arm cortex m3 microcontroller (stm32f103ret6).  I'm interested in programming in assembly only.  I received some software with the kit I bought (keil uvision, IAR workbench kickstart and ride7) but i find all of these a little confusing to use.  Reading the book "the definitive guide to arm cortex m3", I beleive the simplest way to compile and build assembly code is using arm tools, I found some of these in the keil software directory (armasm, armlink, fromelf).  the book describes assembling using this command line:

armasm --cpu cortex-m3 -o test.o test.s

this however doesn't work I realized i had to replace the "--cpu cortex-m3" with "--device stm32".  This makes me wonder if there are different arm tools or variations in different software or if the book was just wrong? Or is this what your supposed to use on linux (I'm using windows)?

the next thing to do is to link the object I seen an example using the following command:

armlink --rw-base 0x20000000 --ro-base 0x0 --map -o test.elf test.o

my question is: is the ro (read only) supposed to be your code that goes into the flash? and rw is the data that goes to the ram?

My microcontroller's flash starts at 0x80000000 (i think), when linking should i set the ro-base at the address 0x80000000 or at 0x0, I've used flash loader demo to successfully upload sample code to my microcontroller.

I have also seen "startup code" on some programs, looking at the code it looks like it sets up the interrupt vector table and stack.  is this absolutely necessary or can you get away with omitting this code and just setup the vectors you will be using?  If someone can elaborate on this.

Any help would be greatly appreciated
  • Note: This was originally posted on 9th June 2009 at http://forums.arm.com

    armasm --cpu cortex-m3 -o test.o test.s

    this however doesn't work I realized i had to replace the "--cpu cortex-m3" with "--device stm32".  This makes me wonder if there are different arm tools or variations in different software or if the book was just wrong? Or is this what your supposed to use on linux (I'm using windows)?


    To answer this part... No it's the same tool.  The --device option is a wrapper that will select the right CPU and any other options.  I think it's likely that the book was written against either the RealView Compilation Tools, or an earlier version of the Keil tools.
  • Note: This was originally posted on 11th June 2009 at http://forums.arm.com

    The assembly examples in the book are written using RealView Development Suite (RVDS).  The command line options for KEIL ARM-MDK (Microcontroller Development Kit) are slightly different. 
    KEIL ARM ARM-MDK is target at microcontroller devices, while RVDS is targetted at supporting the general ARM architecture.

    If you want to learn assembly programming with KEIL ARM-MDK, the easiest way to to use the uVision IDE to create a new project.  The Cortex-M3 book has already got examples of creating C projects. Creating assembly project is similar, and this will create the correct compiler and linker settings for you.

    Please notice that the errors in the book is listed on
    [url="http://www.arm.com/miscPDFs/21948.pdf"]http://www.arm.com/miscPDFs/21948.pdf[/url]

    regards,
    joseph
  • Note: This was originally posted on 16th June 2009 at http://forums.arm.com

    Hi everyone,
    I recently got an Arm cortex m3 microcontroller (stm32f103ret6).  I'm interested in programming in assembly only.  I received some software with the kit I bought (keil uvision, IAR workbench kickstart and ride7) but i find all of these a little confusing to use.


    Hello,

    I'm only a tiny bit farther along, also using a board with an STM32f103 series chip. 
    I found the info on this: [url="http://<a%20href="http://wiki.fosstronics.com/"%20target="_blank">http://wiki.fosstronics.com/</a>"]Fosstronics_Wiki[/url]
    to be most helpful in setting up a toolchain, and using it. 

    In particular, this site has an article titled [url="http://wiki.fosstronics.com/arm_cortex-m3/stm32/minimal-c-program"]"Writing a minimal C program for the STM32 Primer" [/url]
    that is
        (a) really minimal (under 20 lines, not counting comments) and self contained,
        (b) detailed, including snippets of console log,
        © gives enough detail (e.g. on linker scripts and how to look at the raw bytes) to get one started doing more. 

    I was able to adapt this (from the STM32 primer) to a different board, and get it working via serial download. 
    If you're willing to dip a toe into the C language, this may be a good way to start.  (And if not, it shows the assembly code that results, so you could work from that if you prefer.)

    FYI, some more details, and a couple screen shots are online on my [url="http://repstrap-cerberus.blogspot.com/"]repRap build blog[/url] in the entry dated may 24, 2009. 

    Hope this helps,

    Larry
  • Note: This was originally posted on 23rd June 2009 at http://forums.arm.com

    I have also seen "startup code" on some programs, looking at the code it looks like it sets up the interrupt vector table and stack.  is this absolutely necessary or can you get away with omitting this code and just setup the vectors you will be using?  If someone can elaborate on this.


    Hi,
       First of all, one thing here is Cortex M3 has been designed to be programmed almost entirely in C. There is no asm wrappers or startup code required. So my best advice would be to try using C, coz thats what it has been designed for ! However, you could easily make it run you assembly language program, provided you give it the proper startup values. Unlike most other processors, M3 doesn't start executing from location 0. It expects the initial value of Stack Pointer at location 0x00000000, and the starting address of your program at location 0x00000004. If you place these properly, there shouldnt be any trouble running you r code..
  • Note: This was originally posted on 23rd June 2009 at http://forums.arm.com

    Hi,
       First of all, one thing here is Cortex M3 has been designed to be programmed almost entirely in C. There is no asm wrappers or startup code required. So my best advice would be to try using C, coz thats what it has been designed for ! However, you could easily make it run you assembly language program, provided you give it the proper startup values. Unlike most other processors, M3 doesn't start executing from location 0. It expects the initial value of Stack Pointer at location 0x00000000, and the starting address of your program at location 0x00000004. If you place these properly, there shouldnt be any trouble running you r code..



    Greetings all,

    You might get away with not setting up the vector table for a simple learning exercise, but longer term, it leaves you vulnerable to *ugly* bugs.  Sooner or later, one of those interrupts will be enabled, so leaving the vector table unset is a bad habit.  I suggest you (at minimum) point all of the other interrupt vectors at a (common) do-nothing interrupt service routine.  There's example code out that does this, as mentioned previously in this thread.   Compared to other architectures, the setup needed for running (compiled from) C code is simple, straightforward and free to use.  Why not take advantage of it?

    -- Larry
  • Note: This was originally posted on 23rd June 2009 at http://forums.arm.com

    Thanks for all the responses everyone,

    I guess some of you are wondering why i asked to program in assembly, the reason is to familiarize myself with the arm microprocessor(and the new thumb instructions) and because I always thought that when using higher level language the coding is not very efficient.  But i guess using C won't make too much of a difference (only make my life easier)...I didn't know it was designed to be programmed in C.  I was actually following the book "the definitive guide to arm cortex m3". also I found most software a little confusing to use (keil and IAR workbench).
  • Note: This was originally posted on 23rd June 2009 at http://forums.arm.com

    Chapter 20 of the book is "Getting Start with the KEIL RealView Microcontroller Development Kit".  Maybe this chapter would help you.  Also, this link might help too (errors found on the book : [url="http://www.arm.com/miscPDFs/21948.pdf)"]http://www.arm.com/miscPDFs/21948.pdf)[/url]
  • Note: This was originally posted on 18th April 2012 at http://forums.arm.com

    Just got your book on my Kindle Fire. Can't wait to march thru it cover to cover. I too, would like to program in assembly ... it's what I've used my entire 40 years of micro programming. I have several realtime systems under my belt, written in assembly, mostly 8 bitters. I've looked at C and have started an on-line course to learn it, but I don't spend much time with it. I've got the lite version of ARM-MDK installed.

    Kenny


    The assembly examples in the book are written using RealView Development Suite (RVDS).  The command line options for KEIL ARM-MDK (Microcontroller Development Kit) are slightly different. 
    KEIL ARM ARM-MDK is target at microcontroller devices, while RVDS is targetted at supporting the general ARM architecture.

    If you want to learn assembly programming with KEIL ARM-MDK, the easiest way to to use the uVision IDE to create a new project.  The Cortex-M3 book has already got examples of creating C projects. Creating assembly project is similar, and this will create the correct compiler and linker settings for you.

    Please notice that the errors in the book is listed on
    http://www.arm.com/miscPDFs/21948.pdf

    regards,
    joseph