Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
fossatienrico
PostPosted: Sep 26, 2007 - 05:54 PM
Rookie


Joined: Jul 31, 2007
Posts: 20


Hello,
I try to write this code to change a value of a bit in a register but I receive an error on "rcall subr":

Code:

.byte GCC_GNU
.include <avr32/gpio_100.h>

.byte GPIO_BASE_ADD      -61440


.section  .reset

   lddpc   pc,_main
       
        .align  2
      
_main:
   .section  code32

main:   
   nop

   rcall   subr
   
   mov   r0,GPIO_BASE_ADD
   mov   r0,AVR32_GPIO_GPER0
   
   mov   r1,0
   sbr   r1,1   
   st.w   r0[AVR32_GPIO_GPER0],r1
   
   nop

subr:
   mov   r0,GPIO_BASE_ADD
   ld.w   r1,r0[AVR32_GPIO_GPER0]
   sbr   r1,0
   st.w   r0[AVR32_GPIO_GPER0],r1

   ret   r12   
   
   .align  2
   .end


Compiler error is:
make -k all
Building file: ../main.s
Invoking: AVR32/GNU Assembler
avr32-as -mpart=uc3a0512 -g -o"main.o" "../main.s"
../main.s: Assembler messages:
../main.s:56: Error: misaligned operand (required alignment: 2)
make: *** [main.o] Error 1
make: Target `all' not remade because of errors.

and the line is "rcall subr". Sorry but Idon't know if I use correctly ".align" and ".section".

Thank you very much.
 
 View user's profile Send private message  
Reply with quote Back to top
how
PostPosted: Sep 26, 2007 - 06:23 PM
Posting Freak


Joined: Apr 26, 2006
Posts: 1079
Location: Trondheim, Norway

I suggest you put ".align 2" right before your "main:" and "subr:" labels. You can probably get away with ".align 1" though.

Btw, you don't seem to have any contents at your _main label...?
 
 View user's profile Send private message  
Reply with quote Back to top
fossatienrico
PostPosted: Sep 26, 2007 - 06:38 PM
Rookie


Joined: Jul 31, 2007
Posts: 20


Thank you very much for your advice.
But the entire code is:
Code:

// scelta del tipo di compilatore utilizzare
.byte GCC_GNU
//#define GCC_IAR   

// include   
.ifdef GCC_GNU   
   .include <avr32/iouc3a0512.h>
   .include <avr32/gpio_100.h>
.endif
.ifdef GCC_IAR
   //#include <avr32/iouc3a0512.h>
   #include <avr32/gpio_100.h>
.endif

// definizione delle costanti
.ifdef GCC_GNU
   .byte GPIO_BASE_ADD      -61440
.endif
.ifdef GCC_IAR
   #define   GPIO_BASE_ADD   -61440      // 0xFFFF1000
.endif


.ifdef GCC_IAR
   RSEG   RESET
.endif
.ifdef GCC_GNU
   .section  .reset
.endif

   lddpc   pc,_main
.ifdef GCC_IAR
   ALIGN   2
.endif
   
_main:

.ifdef GCC_IAR   
   DC32   main
.endif      
   
.ifdef GCC_IAR   
   RSEG   CODE32
.endif
.ifdef GCC_GNU
   .section  code32
.endif

.ifdef GCC_IAR
   ALIGN   2
.endif
main:   
   nop

   rcall   subr
   
   mov   r0,GPIO_BASE_ADD
   mov   r0,AVR32_GPIO_GPER0
   
   mov   r1,0
   sbr   r1,1   
   st.w   r0[AVR32_GPIO_GPER0],r1
   
   nop

.ifdef GCC_IAR
   ALIGN   2
.endif   
subr:
   mov   r0,GPIO_BASE_ADD
   ld.w   r1,r0[AVR32_GPIO_GPER0]
   sbr   r1,0
   st.w   r0[AVR32_GPIO_GPER0],r1
;
   ret   r12   
   
.ifdef GCC_IAR
   ALIGN   2
   END
.endif
.ifdef GCC_GNU
   .align  2
   .end
.endif


I would write code for IAR GCC code and GNU GCC code but the differences are directive for preprocessor. If I write like you advice me I receive this errors:
make -k all
Building file: ../main.s
Invoking: AVR32/GNU Assembler
avr32-as -mpart=uc3a0512 -g -o"main.o" "../main.s"
Finished building: ../main.s

Building target: prasm1.elf
Invoking: AVR32/GNU C++ Linker
avr32-g++ -mpart=uc3a0512 -o"prasm1.elf" ./main.o
/usr/lib/gcc/avr32/4.1.2/../../../../avr32/lib/uc/crt0.o: In function `_stext':
/home/rpmbuild/rpmbuild/BUILD/gcc-4.1.2/newlib/libc/sys/avr32/crt0.SSad.text+0x94): undefined reference to `main'
./main.oSad.text+0x0): undefined reference to `GCC_GNU'
./main.o: In function `main':
../main.s:60: undefined reference to `GPIO_BASE_ADD'
../main.s:61: undefined reference to `AVR32_GPIO_GPER0'
../main.s:65: undefined reference to `AVR32_GPIO_GPER0'
./main.o: In function `subr':
../main.s:73: undefined reference to `GPIO_BASE_ADD'
../main.s:74: undefined reference to `AVR32_GPIO_GPER0'
../main.s:76: undefined reference to `AVR32_GPIO_GPER0'
collect2: ld returned 1 exit status
make: *** [prasm1.elf] Error 1
make: Target `all' not remade because of errors.
Build complete for project prasm1

I think that the problem is on first line of my code :
Code:

.byte GCC_GNU
//#define GCC_IAR   

I think that ".byte" is not same of "#define".

Thank you very much.
 
 View user's profile Send private message  
Reply with quote Back to top
fossatienrico
PostPosted: Sep 27, 2007 - 09:09 AM
Rookie


Joined: Jul 31, 2007
Posts: 20


I solved some problems but I have anothuer problems with linker; I write this code
Code:

// scelta del tipo di compilatore utilizzare
.equ GCC_GNU,1
//#define GCC_IAR   

// include   
.ifdef GCC_GNU   
   //.include <avr32/uc3a0512.h>
   //.include "avr32/gpio_100.h"
.endif
.ifdef GCC_IAR
   #include <avr32/iouc3a0512.h>
   #include <avr32/gpio_100.h>
.endif

// definizione delle costanti
.ifdef GCC_GNU
   .equ GPIO_BASE_ADD,      -61440
   .equ AVR32_GPIO_GPER0,   0x00000000
.endif
.ifdef GCC_IAR
   #define   GPIO_BASE_ADD   -61440      // 0xFFFF1000
.endif


.ifdef GCC_IAR
   RSEG   RESET
.endif
.ifdef GCC_GNU
   .section  .reset
.endif

   lddpc   pc,_main
.ifdef GCC_IAR
   ALIGN   2
.endif
.ifdef GCC_GNU
   .align   2
.endif
   
_main:

.ifdef GCC_IAR   
   DC32   main
.endif      
   
.ifdef GCC_IAR   
   RSEG   CODE32
.endif
.ifdef GCC_GNU
   .text
.endif

.ifdef GCC_GNU
   .align   2
.endif
main:   
   nop

   rcall   subr
   
   mov   r0,GPIO_BASE_ADD
   mov   r0,AVR32_GPIO_GPER0
   
   mov   r1,0
   sbr   r1,1   
   st.w   r0[AVR32_GPIO_GPER0],r1
   
   nop

.ifdef GCC_GNU
   .align   2
.endif   
subr:
   mov   r0,GPIO_BASE_ADD
   ld.w   r1,r0[AVR32_GPIO_GPER0]
   sbr   r1,0
   st.w   r0[AVR32_GPIO_GPER0],r1
;
   ret   r12   
   
.ifdef GCC_IAR
   ALIGN   2
   END
.endif

.ifdef GCC_GNU
   .align  2
.endif

.end   

and the error is:
**** Build of configuration Debug for project prasm1 ****

make -k all
Building file: ../main.s
Invoking: AVR32/GNU Assembler
avr32-as -I/usr/avr32/include -mpart=uc3a0512 -g -o"main.o" "../main.s"
Finished building: ../main.s

Building target: prasm1.elf
Invoking: AVR32/GNU C++ Linker
avr32-g++ -mpart=uc3a0512 -o"prasm1.elf" ./main.o
/usr/lib/gcc/avr32/4.1.2/../../../../avr32/lib/uc/crt0.o: In function `_stext':
/home/rpmbuild/rpmbuild/BUILD/gcc-4.1.2/newlib/libc/sys/avr32/crt0.SSad.text+0x94): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [prasm1.elf] Error 1
make: Target `all' not remade because of errors.
Build complete for project prasm1


Sorry, another question: where I can find a correct documentation for preprocessor and assembler?
Thank you very much
 
 View user's profile Send private message  
Reply with quote Back to top
how
PostPosted: Sep 27, 2007 - 02:48 PM
Posting Freak


Joined: Apr 26, 2006
Posts: 1079
Location: Trondheim, Norway

If you use avr32-gcc instead of avr32-as and call the file main.S (with a capital S) the regular C-style preprocessor directives will work.

You can find some documentation here (assembler, linker, etc.):
http://sourceware.org/binutils/docs-2.17/

and some documentation here (compiler, preprocessor, etc.):
http://gcc.gnu.org/onlinedocs/
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits