This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Some asm for ek-lm4f120xl



When starting new uC environment the best way is to start with assembly things (my opinion). But never found asm-only example for the lm4f120h5qr Stellaris Launchpad (with Cortex M4 core) produced by CCS asm compiler directives. I got some hints from http://users.ece.utexas.edu/~valvano/index.html and with this manual http://users.ece.utexas.edu/~valvano/arm/ConvertKeilCCS.pdf produced this "nice" asm example:

            ;comment __stack definition in lm4f120h5qr.cmd file
            .thumb                ;1)
            .data                 ;2)
            .align 4             ;3)
            .global M             ;4)
M             .field 32             ;5)
            .align 2             ;6)
            .text                 ;7)
            .retain                ;try compiling without these retains...
            .retainrefs            ;and see current warning message
                                   ;(entry point missing)
PtM         .field M,32          ;8)
PORTA         .field 0x400043FC,32 ;8)
BIT5         .equ 0x20              ;9)
JOKUPORT    .field 0x200000F, 32
            .global InputPA5     ;10)
            .thumbfunc InputPA5 ;11)
InputPA5:     .asmfunc             ;12)

            ;disable all interrupts (except nmi and hard fault)
            mov r0, #1
            msr PRIMASK, r0

            LDR R0,PORTA         ;13)
            ;LDR R1,[R0]
            AND R1,R1,#BIT5
            LDR R2,PtM             ;13)
            LDR r8, JOKUPORT
            MRS r1, IPSR

            MOV r0, #1
            MOV r1, #2
            MOV r2, #3
            PUSH {r1-r3}
            POP {r1-r3}

            ADD r0, r1, r2        ; r0 = 5 ; should be

            ;ADDNES R0, R0, R2
            ;Condition codes not allowed outside
            ;of IT blocks in Thumb.

            TEQ r0, #0
            TEQS r0, #0

            ;.W indicates 32 bit Thumb-2 instruction
            ;from book definitive guide to the arm cortex m3
            ; Read memory[R0], with R1
            ; updated to R1+offset
            LDR.W r1, [r0], #1

Loop:        B Loop
            STR R1,[R2]            ;do not write into memory
            BX LR

            .endasmfunc         ;12)
            .end                 ;14)

Same with picture :

Now i'm stucked because of there are no manuals, free books and lessons how to produce asm-only projects with Code Composer 5.3 environment. I'm using free license version of CCS 5.3.


(I manually created targetConfigs folder and copied its content from c-project)

  • Pentti Itkonen said:
    the best way is to start with assembly things (my opinion).

    Grossly, patently UNTRUE!  (as you've just found/confirmed!)

    LMI attracted TI - many believe - primarily due to the inclusion of the wondrous, StellarisWare - which is almost exclusively delivered in "C."  Tens of thousands have used - and succeeded - with this free, C Source.

    And then there are those few who "cling" to the exotica of Assembly - and the dearth of, "manuals, free books, and lessons."  (your findings - your words!)

    Cannot you write your code in "C" - and then review the disassembly - if you must?  New compilers are extremely clever - doubt that most of us can match...

    Believe, any/all "facts in evidence" line up strongly against your, "best way to Start" assertion...  Case dismissed!

  • As an old timer (who even hates C) -- I have two words for Assembler: NEVER AGAIN!

  • Also as an old timer (started with Z80) my words are: "do no neglect the assembler!"

    The first example when you need it is the boot loader project, the startup file. You have a lot of stuff and info there.

    So, as general rule, do it this way:

    1. Start with C,  look at disassembly and learn the thinking way of the compiler.
    2. Learn the assembler - specially the link with C files.

    This approach is good for: debugging, extending with asm routines when needed, optimizations for speed (memcpy routines are more efficient in .asm than in C - useful for lwip for instance)

    Petrei 

  • Thanks Petrei. I found bootloader file from C:\StellarisWare\boot_loader and the startup asm file written with ccs syntax: C:\StellarisWare\boot_loader\bl_startup_ccs.s

    Edit : Those were the days :

  • @ old timer/Petrei: (fellow, past Z80 developer)

    Everything you list is true/agreed.

    However poster urged that we, "START with Assembly" - which remains total folly!  (1960 databook - not withstanding)

    You've "dialed that down" to, "Do not neglect" which is far more reasonable.

    However - w/the complexity of the ARM - and many challenges of mastering multiple peripherals - "neglect" may be the necessary "byproduct" of , "Proper - project organization and prioritization!"

  • Seems that commercial and production codes since Cortex-M3 are typically written in ANSI c and only the exception vector is written in assembler. And the CMSIS seems to be in focus when thinking RTOS integrated into Cortex-M4F environment.

    But i am a hobbyist coder and i do what i want to do when i'm studying new technology.






  • Pentti Itkonen said:
    But i am a hobbyist coder and i do what i want to do

    And - of course - that is your right.  But the earlier assertion, "Best to Start w/Assembler" may fall upon "new eyes" - and lead them down a mistaken path.  And - worse still - if they have a "boss" and time of "delivery" is important - yours may not be the best means to achieve, "Job Security..."

  • If you enjoy working on large projects in assembler, that's great. As someone who likes to be able to maintain my projects over a long period of time, though, I am delighted to not have to use assembler except in the direst of circumstances!

    You mention using assembler for interrupt service routines. The ARM Cortex M microcontroller code was actually designed to allow you to write all your handlers in C without the need for compiler-specific hacks. The hardware interrupt stack frame is compliant with the C calling convention so all your handlers can be C functions and you never need assembler veneers or whatever.

    As far as performance goes, I was disappointed to discover 4 or 5 years ago that the compilers can now, generally, do a better job of optimizing the assembler than I can. On the few occasions I've felt like rewriting a function to improve the speed, I've looked at the compiler output and found it to be a whole lot tighter than any hand-coded assembler I would have generated!

    While I'm not against people using assembler, I would strongly recommend you try C on a Cortex-M device and see what you think.

  • Well. Thank for you all for your comments.

    I am already over 50 year old and i do not have enough remaining days in my life
    to code all my ideas with assembly language. So i am using c -language too when
    needed. And i am using conditional goto-statements in c too.

    And i like this too :
    http://www.youtube.com/watch?v=94AF_-RIl0E










  • Pentti:

    It's nice to see young people taking an interest in embedded computing. (tic)

    However, I just must comment on this...

    I am already over 50 year old and i do not have enough remaining days in my life to code all my ideas with assembly language. So i am using c -language too when needed. And i am using conditional goto-statements in c too.

    Bad programmer! Bad Programmer. No gotos!

    Actually a GOTO starts up branch prediction logic -- which is always a crapshoot.

    Anyway the GOTO addiction can be cured -- I am offering a 12 step program... All major credit cards accepted... weekend only programs available!

    Welcome to the madhouse!

  • Conditional goto's are fundamentally no different than switch statements, or if-else groups, or even standard looping logic.  All of these start up branch prediction logic because at the bottom level they all create conditional branches.

    While goto's can always be avoided, and almost always should be, at times the resultant code is much harder to read and more convoluted than when a simple goto is used.

  • All this discussion of goto (which, incidentally, our coding standard prohibits), got me thinking back to the wonderful (or, at least, amusing) language of INTERCAL which uses "COME FROM" instead. :-)