SAM4S assembly help

Comments

14 comments

  • Avatar
    Jon Elliott

    Hi Angelo,

    Take a look at the led example included in the SAM4S Xplained Pro board support package - if you want to see the assembly code, right click on the project in the project explorer and select Disassemble.

    Regards,

    Jon

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    Thank you for your advice Jon Elliot!!!

    I didn't find any software included within the package... there was actually only the board in a small box...

     

    when I disassemble this:

    #include "sam4s.h"

     

    int main();

    int f;
    int main(void)
    {
    int i;

    i++;
    i= PIO_PA0;
    f++;

    return 0;
    }

    I get that:

     

    section .text

    section .data

    section .text.main
    <main>
    B480 push {r7}
    B083 sub sp, sp, #12
    AF00 add r7, sp, #0
    687B ldr r3, [r7, #4]
    F1030301 add.w r3, r3, #1
    607B str r3, [r7, #4]
    F04F0301 mov.w r3, #1
    607B str r3, [r7, #4]
    F2400300 movw r3, #0
    F2C00300 movt r3, #0
    681B ldr r3, [r3]
    F1030201 add.w r2, r3, #1
    F2400300 movw r3, #0
    F2C00300 movt r3, #0
    601A str r2, [r3]
    F04F0300 mov.w r3, #0
    4618 mov r0, r3
    F107070C add.w r7, r7, #12
    46BD mov sp, r7
    BC80 pop {r7}
    4770 bx lr

     

    This gives me no idea of how to start an assembly code with #include<> directives and how does this code actually refers to  PIO_PA0.

    Thank you very much anyway....

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    I'm referring to the led example we ship in our SAM4S Xplained Pro Board Support Package - install the board support package then click Tools > Show Installed Packages then click on the Atmel SAM4S Xplained Pro Board Support Package link then the SAM4S Xplained Pro Samples Solution link to open the solution. The led, timer_interrupt and interrupt examples all demonstrate how to use the GPIO.

    If you look at the SAM4S_Startup.s and thumb_crt0.s files used in the projects they should give you an idea how to get started writing an assembly code program.

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    This still doesn't tell me how to use IO ports from assembly code...

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    Can I ask you something more?

    I just found out that the crossworks does not allow me to write values bigger than 0xff to the registers, while the device is supposed to be 32-bit. I tried to copy-paste instructions from the device datasheet, and still it tells me that the value is out of range.  What am I doing wrong?

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    To store the 32-bit value 0x12345678 at address 0x20000000 you would do:

      ldr r0, =0x20000000
      ldr r1, =0x12345678
      str r1, [r0]
    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    Thank you very much!!!!

    This does compile, and I hope I will make some working code this time. The strange thing is that this does not match the code examples from the atmel sam4s datasheet.

    Does Crossworks have a different assembly on its own? Can you please provide me with a manual, if any?

    Thank you very much, anyway!!!

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    No it is standard - the ARM documentation for "ldr rd, =const" can be found here.

    Your confusion may be down to the fact that there are restrictions to the values you can load directly into registers using the "mov" instruction - if you use the "ldr rd, =const" pseudo-instruction the assembler will choose the most appropriate instruction based on the value being loaded.

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    Thank you for the help.

    I will ask you some more, I hope I am not very obnoxious...

    Well, I wrote the code below that is supposed to drive the pins of the PORTA low, according to the ATMEL datasheet.

     

    .text 32
    .global main
    main:

    //mov r7, #0x400E0E00


    str r3, [r7]

    ldr r0, =0x00000000
    ldr r1, =0xFFFFFFFF

    ldr r2, =0x400E0E00
    str r1, [r2]
    ldr r2, =0x400E0E04
    str r0, [r2]
    ldr r2, =0x400E0E10
    str r1, [r2]
    ldr r2, =0x400E0E14
    str r0, [r2]
    ldr r2, =0x400E0E20
    str r0, [r2]
    ldr r2, =0x400E0E24
    str r1, [r2]
    ldr r2, =0x400E0E30
    str r0, [r2]
    ldr r2, =0x400E0E34
    str r1, [r2]
    ldr r2, =0x400E0E40
    str r0, [r2]
    ldr r2, =0x400E0E44
    str r1, [r2]
    ldr r2, =0x400E0E50
    str r1, [r2]
    ldr r2, =0x400E0E54
    str r0, [r2]
    ldr r2, =0x400E0E60
    str r1, [r2]
    ldr r2, =0x400E0E64
    str r0, [r2]
    ldr r2, =0x400E0E90
    str r0, [r2]
    ldr r2, =0x400E0E94
    str r1, [r2]
    ldr r2, =0x400E0EA0
    str r1, [r2]
    ldr r2, =0x400E0EA4
    str r0, [r2]

    ldr r2, =0x400E0E34


    start:


    str r0, [r2]
    str r0, [r2]
    bl start

    It does not have any effect on the pins of the device, and anything I write to the 0x400E0E34 the pins are always at about 3.3V. I tried to fix myself, but what makes me annoy you again (I'm sorry) is that when I run and debug it through the ARM simulator the program flows nice, but when I connect to the board (CONNECT->CMSIS-DAP is the one that works, i found by chance) and then debug, an error message appears for the SAM4S_Startup.s that says "failed to set initial breakpoint Not enough hardware instruction breakpoints". 

    I also try to run the led example you mention above so I can start from somewhere with writing to the pins, but it does not run and says that there is no debug register.

    Thank you very much for your help!!!

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    I've converted the SAM4S Xplained Pro led example project (attached) to assembly code. The assembly code is:

      .syntax unified

      .text
      .global main

    #define PMC_BASE         0x400e0400
    #define PMC_PCER0_OFFSET 0x10

    #define PIOC_BASE        0x400e1200
    #define PIO_PER_OFFSET   0x0
    #define PIO_OER_OFFSET   0x10
    #define PIO_SODR_OFFSET  0x30
    #define PIO_CODR_OFFSET  0x34

    #define ID_PIOA   (11)
    #define ID_PIOC   (13)

    #define LED (1 << 23)

    .thumb_func

    main:
      /* Enable PIO clocks */
      ldr r0, =PMC_BASE
      ldr r1, =(1 << ID_PIOA) | (1 << ID_PIOC)
      str r1, [r0, #PMC_PCER0_OFFSET]  // PMC->PMC_PCER0 = (1 << ID_PIOA) | (1 << ID_PIOC);

    /* Configure LED */
      ldr r0, =PIOC_BASE
      ldr r1, =LED
      str r1, [r0, #PIO_SODR_OFFSET]  // PIOC->PIO_SODR = LED;  
      str r1, [r0, #PIO_PER_OFFSET]   // PIOC->PIO_PER = LED;
      str r1, [r0, #PIO_OER_OFFSET]   // PIOC->PIO_OER = LED;

    loop:
      /* LED on */
      str r1, [r0, #PIO_CODR_OFFSET]  // PIOC->PIO_CODR = LED;
      /* LED off */
      str r1, [r0, #PIO_SODR_OFFSET]  // PIOC->PIO_SODR = LED;
    b loop

    Use the led.hzp included in the .zip file, it has been configured to run on the SAM4S Xplained Pro board.

    >an error message appears for the SAM4S_Startup.s that says "failed to set initial breakpoint Not enough hardware instruction breakpoints"

    The hardware has a limited number of breakpoints, delete any breakpoints you don't want - you can do this with the breakpoint window (View > Breakpoints).

    >I also try to run the led example you mention above so I can start from somewhere with writing to the pins, but it does not run and says that there is no
    >debug register.

    I've tested it and it is working OK on my SAM4S Xplained Pro board - what is the precise error message and which project are you using?

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    I opened the project you sent me and I run it, it says that runs ok (the led at the bottom of the CrossWorks window lights yellow and it counts millions of cycles), but I can't count anything. I try to find some square wave with the oscilloscope ( I am very experienced with using an oscilloscope) but I don't see any signal.

    You say you have an Xplained pro yourself. How do you connect it? do you use any external power source? the Xplained  pro data sheet says it doesn't need any if you connect it via usb.

    How do you see the output signal? Do I have to add any resistor to ground before I can see the output signal?

    Can my Xplained pro be damaged? should I replace it with a new one?

    Thank you for being very cooperative so far and answering all my questions, and for making an assembly project for me.

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    The program flashes LED0 on the SAM4S Xplained Pro board, no board modifications required. The LED flashes quickly so it appears on but slightly dimmer than normal if the program is left to run.

    The board is powered from the DEBUG USB connector, no external power source required.

     

    0
    Comment actions Permalink
  • Avatar
    Angelo Skouras

    Yes, you where right. I was counting at the wrong place.

    I have to ask you for something more: the arm does not run any code unless I connect it to the computer and press the "buid and run" from the crossworks. Can I make it work independently from the computer?

    I am very grageful to you for answering all my questions.

    0
    Comment actions Permalink
  • 0
    Comment actions Permalink

Please sign in to leave a comment.