SFRs in assembly code

View: New views
13 Messages — Rating Filter:   Alert me  

SFRs in assembly code

by Daniel Otte-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I'm having problems assembling the following code:
[...]
19    #include "config.h"
20    #include <avr/io.h>
21
22    .global uart0_init
23    uart0_init:
24    #define BAUD UART0_BAUD_RATE
25    #include <util/setbaud.h>
26     ldi r24, UBRRH_VALUE
27    #if _SFR_IO_REG_P(UBRRH0)
28     out _SFR_IO_ADDR(UBRRH0), r24
29    #else
30     sts _SFR_MEM_ADDR(UBRRH0), r24
31    #endif
[...]

The Errors I get are:
avr-gcc -mmcu=atmega644   -c -o uart_ni-asm.o uart_ni-asm.S
uart_ni-asm.S: Assembler messages:
uart_ni-asm.S:28: Error: constant value required
uart_ni-asm.S:28: Error: number must be positive and less than 64

I've read http://www.nongnu.org/avr-libc/user-manual/group__avr__sfr__notes.html
but it seems to not offer a solution.

Thanks for your help in advance,
  Daniel



_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

signature.asc (196 bytes) Download Attachment

Re: SFRs in assembly code

by Heike C. Zimmerer-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Daniel Otte" <daniel.otte@...> writes:

> Hi all,
> I'm having problems assembling the following code:
> [...]
> 28     out _SFR_IO_ADDR(UBRRH0), r24
> The Errors I get are:
> avr-gcc -mmcu=atmega644   -c -o uart_ni-asm.o uart_ni-asm.S
> uart_ni-asm.S: Assembler messages:
> uart_ni-asm.S:28: Error: constant value required


It's UBRR0H (last two chars reversed).  As it is written now, the
assembler must assume that is an externally defined symbol (thus not a
constant).

Heike


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Daniel Otte-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Heike C. Zimmerer schrieb:
> It's UBRR0H (last two chars reversed).  As it is written now, the
> assembler must assume that is an externally defined symbol (thus not a
> constant).
Thanks for the advice, but now I'm facing some troubles with <utils/setbaud.h>.
my config.h includes the following:
[...]
#include <avr/io.h>
#define F_CPU 16000000
#define UART0_BAUD_RATE 38400
[...]

I get the following errors:
uart_ni-asm.S: Assembler messages:
uart_ni-asm.S:27: Error: missing ')'
uart_ni-asm.S:27: Error: missing ')'
uart_ni-asm.S:27: Error: missing ')'
uart_ni-asm.S:27: Warning: constant out of 8-bit range: 16000008
[...]

while line 27 is:
        ldi r24, UBRRH_VALUE

thanks very much,
  Daniel



_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

signature.asc (196 bytes) Download Attachment

Re: SFRs in assembly code

by Heike C. Zimmerer-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Daniel Otte" <daniel.otte@...> writes:

> Heike C. Zimmerer schrieb:
>> It's UBRR0H (last two chars reversed).  As it is written now, the
>> assembler must assume that is an externally defined symbol (thus not a
>> constant).
> Thanks for the advice, but now I'm facing some troubles with <utils/setbaud.h>.
> my config.h includes the following:
> [...]
> #include <avr/io.h>
> #define F_CPU 16000000
> #define UART0_BAUD_RATE 38400
> [...]
>
> I get the following errors:
> uart_ni-asm.S: Assembler messages:
> uart_ni-asm.S:27: Error: missing ')'
[..]
> while line 27 is:
> ldi r24, UBRRH_VALUE

Given that UBBR_VALUE is defined to be something like
 
 #define UBRR_VALUE (((F_CPU) + 4UL * (BAUD)) / (8UL * (BAUD)) -1UL)

I'd guess that there's a spurious semicolon somewhere within the
#defines which are used to calculate the final value.  This makes the
rest of the assembly line after the semicolon into a comment, thus the
closing brace(s) is/are missed.

Just a guess, of course.

Heike


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Daniel Otte-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I investigated a little bit more and included the definition of UBRR_VALUE into
my code-file.
It seems that the preprocessor of gas doesn't handle the UL suffix correct.

#define UBRR_VALUE  ((((F_CPU) + (8 * (BAUD)))/ (16 * (BAUD))) -1)

works, while

#define UBRR_VALUE ((((F_CPU) + (8UL * (BAUD))) /(16UL * (BAUD))) -1UL)

yields a lot of " Error: missing ')'" messages.

can anyone verify that?
Should I file a bug report for gas?

best regards,
  Daniel



_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

signature.asc (196 bytes) Download Attachment

RE: SFRs in assembly code

by Weddington, Eric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

> -----Original Message-----
> From: avr-chat-bounces+eric.weddington=atmel.com@...
> [mailto:avr-chat-bounces+eric.weddington=atmel.com@...]
>  On Behalf Of Daniel Otte
> Sent: Wednesday, July 22, 2009 3:51 PM
> To: AVR-chat@...
> Subject: Re: [avr-chat] SFRs in assembly code
>
> Hi,
> I investigated a little bit more and included the definition
> of UBRR_VALUE into
> my code-file.
> It seems that the preprocessor of gas doesn't handle the UL
> suffix correct.
>
> #define UBRR_VALUE  ((((F_CPU) + (8 * (BAUD)))/ (16 * (BAUD))) -1)
>
> works, while
>
> #define UBRR_VALUE ((((F_CPU) + (8UL * (BAUD))) /(16UL *
> (BAUD))) -1UL)

First off, where is this definition of UBRR_VALUE coming from? Somehow -1 and UL should not go together (an *unsigned* long -1??).
 


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

RE: SFRs in assembly code

by Weddington, Eric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

> -----Original Message-----
> From: avr-chat-bounces+eric.weddington=atmel.com@...
> [mailto:avr-chat-bounces+eric.weddington=atmel.com@...]
>  On Behalf Of Weddington, Eric
> Sent: Wednesday, July 22, 2009 4:01 PM
> To: Daniel Otte; AVR-chat@...
> Subject: RE: [avr-chat] SFRs in assembly code
>
>  
> > #define UBRR_VALUE ((((F_CPU) + (8UL * (BAUD))) /(16UL *
> > (BAUD))) -1UL)
>
> First off, where is this definition of UBRR_VALUE coming
> from? Somehow -1 and UL should not go together (an *unsigned*
> long -1??).

Bah, nevermind! I mistook it for a negative of 1, and instead it's a subtraction of 1.

Off to go get more caffeine.... :-/


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Daniel Otte-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Weddington, Eric wrote:
> First off, where is this definition of UBRR_VALUE coming from? Somehow -1 and UL should not go together (an *unsigned* long -1??).
>  
>
I took the line from <util/setbaud.h>
(http://cvs.savannah.gnu.org/viewvc/avr-libc/include/util/setbaud.h?revision=1.1&root=avr-libc&view=markup)
which works very well if included in C code.



_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

signature.asc (196 bytes) Download Attachment

Re: SFRs in assembly code

by Heike C. Zimmerer-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Daniel Otte" <daniel.otte@...> writes:

> It seems that the preprocessor of gas doesn't handle the UL suffix correct.
>
> #define UBRR_VALUE  ((((F_CPU) + (8 * (BAUD)))/ (16 * (BAUD))) -1)
>
> works, while
>
> #define UBRR_VALUE ((((F_CPU) + (8UL * (BAUD))) /(16UL * (BAUD))) -1UL)
>
> yields a lot of " Error: missing ')'" messages.
>
> can anyone verify that?

Yes. indeed, the error message is triggered by the 'UL'.  The simple
assembler line

 .equ test, (34UL)

gives (among others)

 ./added/fastload.h: Assembler messages:
 ./added/fastload.h:203: Error: missing ')'

> Should I file a bug report for gas?

No.  While you can use the C preprocessor with gas, you cannot use C
constructs with gas.  34UL is not a valid gas constant, since gas
doesn't know anything about things like 'unsigned long' (and it would
have no meaning whatsoever in it).

This #define is meant for use with C and only expands to something
meaningful when used in C.  The error messages you've got are somewhat
misleading, however.  My above test line gave after the part cited
above:

 ./added/fastload.h:203: Error: junk at end of line, first unrecognized
 character is `U'

which points to the problem.


Heike



_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Joerg Wunsch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

lists@... (Heike C. Zimmerer) wrote:

>> Should I file a bug report for gas?

> No.  While you can use the C preprocessor with gas, you cannot use C
> constructs with gas.

But of course, if someone wouldn't want to go ahead, and make
<util/setbaud.h> also work for assembly source files (that could be
conditionalized on __ASSEMBLER__), we'd gladly accept that patch.

--
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Heike C. Zimmerer-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

j@... (Joerg Wunsch) writes:

> But of course, if someone wouldn't want to go ahead, and make
> <util/setbaud.h> also work for assembly source files (that could be
> conditionalized on __ASSEMBLER__), we'd gladly accept that patch.

This looks fairly simple and may be useful to others as well.  Is there
any special way to submit the patch (the patch tracker on Savannah seems
to not allow me to submit anything)?


Heike


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

RE: SFRs in assembly code

by Weddington, Eric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 

> -----Original Message-----
> From: avr-chat-bounces+eric.weddington=atmel.com@...
> [mailto:avr-chat-bounces+eric.weddington=atmel.com@...]
>  On Behalf Of Heike C. Zimmerer
> Sent: Wednesday, August 05, 2009 2:24 AM
> To: avr-chat@...
> Subject: Re: [avr-chat] SFRs in assembly code
>
> j@... (Joerg Wunsch) writes:
>
> > But of course, if someone wouldn't want to go ahead, and make
> > <util/setbaud.h> also work for assembly source files (that could be
> > conditionalized on __ASSEMBLER__), we'd gladly accept that patch.
>
> This looks fairly simple and may be useful to others as well.
>  Is there
> any special way to submit the patch (the patch tracker on
> Savannah seems
> to not allow me to submit anything)?

IIRC, you have to register a username/password in Savannah in order to do submit items. Have you already done this?


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat

Re: SFRs in assembly code

by Bob Paddock-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> IIRC, you have to register a username/password in Savannah in order to do submit items. Have you already done this?

BTW, there was a message on Savannah that they were considering
purging inactive accounts.  So anyone that
has an account they want to keep, should at least login once every year or so.


_______________________________________________
AVR-chat mailing list
AVR-chat@...
http://lists.nongnu.org/mailman/listinfo/avr-chat