bugAVR C Runtime Library - Bugs: bug #28756, Bug in AVR libc 1.6.7 (power.h for...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #28756: Bug in AVR libc 1.6.7 (power.h for 8-bit AVR)

Submitter:  Lucas <kukiz100>
Submitted:  Thu 28 Jan 2010 11:17:39 AM UTC
   
 
Category:  Header Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Header files
Status:  Fixed Assigned to:  joerg_wunsch
Percent Complete:  0% Open/Closed:  Closed
Release:  1.6.7 Fixed Release:  1.6.3

Jump to the original submission

Wed 03 Feb 2010 10:44:48 AM UTC, comment #14: 

At first I want to apologize for my behaviour (sending you my whole project).
Your suggestion Joerg about

   #define Set_cpu_prescaler(x) (clock_prescale_set(x))

was fine. I changed it to

   inline void Set_cpu_prescaler(clock_div_t x);
   inline void Set_cpu_prescaler(clock_div_t x)
{
clock_prescale_set(x);
}

and it works!. Thank You very much!

Lucas <kukiz100>
Wed 03 Feb 2010 08:10:46 AM UTC, comment #13: 

I can now see the problem with that code.  They stupidly
parenthesize the call to clock_prescale_set() within another
macro, like:


#define Set_cpu_prescaler(x) (clock_prescale_set(x))


While this is completely pointless for a function with void
return value (as it could never become part of an arithmetic
expression), it's still legal C code.

I guess the best solution then is to use an inlined function
rather than a macro to implement clock_prescale_set().

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 02 Feb 2010 11:26:58 AM UTC, comment #12: 

But: I cannot reproduce it with that, and obviously, your
own code /was/ fully compiled (the .rar file contains an
ELF file).

Please give me a 5 to 10 line example code that triggers this
compiler error, including the compiler command-line.

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 02 Feb 2010 10:55:11 AM UTC, comment #11: 

I wrote about it in third post, source code is in first attachment (file #19561:  test_usb_mass_storage.rar added by kukiz100)

Lucas <kukiz100>
Tue 02 Feb 2010 10:24:12 AM UTC, comment #10: 


> I have the same error with AT90USB1287


Source code?

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 02 Feb 2010 10:06:20 AM UTC, comment #9: 

I have the same error with AT90USB1287:
error: expected expression before 'do'

Lucas <kukiz100>
Tue 02 Feb 2010 08:54:47 AM UTC, comment #8: 

Yes, the ATmega128RFA1 was (accidentally) missing from the
list of supported MCUs for clock prescaling in avr-libc 1.6.6.

However, the error Timur is getting is completely different:

../main.c:105: error: expected expression before 'do'

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 02 Feb 2010 08:49:50 AM UTC, comment #7: 

I have tested out Joerg's snippet with -mmcu=atmega128rfa1 -W -Wall, using WinAVR.  With WinAVR-20090313, you get an error ("clock_div_1" undeclared, and a warning implicit declaration of function "clock_prescale_set").  This particular avr is missing from the list for the clock prescale micros.

With the WinAVR-20100110, the newer version of the library has this included, and the code compiles fine.


David Brown <davidbrown>
Tue 02 Feb 2010 07:48:57 AM UTC, comment #6: 

Thanks for the error message.  Still, I cannot reproduce
the problem.  For reference, this is my source code file:


#include "power.h"

void prescaler_1(void)
{
  clock_prescale_set(clock_div_1);
}


and compile it with

avr-gcc -O -mmcu=atmega1281 -c clkpr.c

I get a working result, regardless of whether I'm using either
of your submitted power.h include files (where one is the
stock power.h from avr-libc 1.6.6, and the other one is
your edited version from avr-libc 1.6.7), or the file from
CVS (either HEAD or the 1.6 branch, both files are the same).

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 02 Feb 2010 05:51:25 AM UTC, comment #5: 

Sorry, I was inattentive with "infinity loop" :).
When I try to reproduce error I'm force to "Clean project" in Eclipse. Here my compile error.

(file #19605)

Timur Gilfanov <timurgilfanov>
Mon 01 Feb 2010 01:05:34 PM UTC, comment #4: 

do { ... } while(0) is not an infinite loop.  Think again
about it.

Sorry, I still cannot reproduce any error.  The project in
the attachment did apparently compile fine (it contains an
ELF file, after all!), and when I recompile it, I don't get
an error at all, nor does anyone else provide an error
message.

Btw., when being asked for a sample file, it's a little
impolite to dump him half a megabyte of a complete project.
It's really not asked too much that you do your fair share
of the workload, and strip the files down to the minimum
required to reproduce the issue.

Please also quote the compiler error message in full.

Joerg Wunsch <joerg_wunsch>
Group administrator
Mon 01 Feb 2010 12:52:17 PM UTC, comment #3: 

I'm have his bug in WinAVR 20100110 too. In clock_prescale_set(x) I found infinity loop and error disappear when I remove loop:
WinAVR 20100110 power.h:
#define clock_prescale_set(x) \
do { \
        uint8_t tmp = _BV(CLKPCE); \
        _asm_ __volatile__ ( \
                "in _tmp_reg_,__SREG__" "\n\t" \
                "cli" "\n\t" \
                "sts %1, %0" "\n\t" \
                "sts %1, %2" "\n\t" \
                "out _SREG_, _tmp_reg_" \
                : /* no outputs */ \
                : "d" (tmp), \
                  "M" (_SFR_MEM_ADDR(CLKPR)), \
                  "d" (x) \
                : "r0"); \
} while (0)

WinAVR 20090313 power.h:
#define clock_prescale_set(x) \
{ \
        uint8_t tmp = _BV(CLKPCE); \
        _asm_ __volatile__ ( \
                "in _tmp_reg_,__SREG__" "\n\t" \
                "cli" "\n\t" \
                "sts %1, %0" "\n\t" \
                "sts %1, %2" "\n\t" \
                "out _SREG_, _tmp_reg_" \
                : /* no outputs */ \
                : "d" (tmp), \
                  "M" (_SFR_MEM_ADDR(CLKPR)), \
                  "d" (x) \
                : "r0"); \
}


(file #19590, file #19591)

Timur Gilfanov <timurgilfanov>
Thu 28 Jan 2010 09:41:15 PM UTC, comment #2: 

In attachment I put my whole project. I use Programmers Notepad and "make all" command (newest WinAVR - 20100110). In earlier release (20090313) I had no problems.

(file #19561)

Lucas <kukiz100>
Thu 28 Jan 2010 12:06:31 PM UTC, comment #1: 

Please attach a file to reproduce this problem, as well as
a simple Makefile or command-line you are using.

In a first attempt, I cannot find anything failing there,
neither for an ATmega1281 nor an ATmega128RFA1 (which offers
one additional prescaler value).

Joerg Wunsch <joerg_wunsch>
Group administrator
Thu 28 Jan 2010 11:17:39 AM UTC, original submission:  

There is a bug in power.h file. While I am using a macro "#define clock_prescale_set(x) \" compiler shows me error.
I think it is caused by typedef  several lines above clock_prescale macro (precisely by adding ATmega128RFA1 support).

Lucas <kukiz100>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #19605:  compile_error added by timurgilfanov (1KiB - application/octet-stream)
file #19590:  power.h added by timurgilfanov (57KiB - application/octet-stream - 1 - WinAVR 20090312; 2 - WinAVR 20100110)
file #19591:  power.h added by timurgilfanov (60KiB - application/octet-stream - 1 - WinAVR 20090312; 2 - WinAVR 20100110)
file #19561:  test_usb_mass_storage.rar added by kukiz100 (471KiB - application/octet-stream - My project)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by davidbrown (Posted a comment)
  • -email is unavailable- added by timurgilfanov (Updated the item)
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  • -email is unavailable- added by kukiz100 (Submitted the item)
  • -email is unavailable- added by kukiz100
  •  

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-02-03 joerg_wunsch StatusConfirmed Fixed
        Assigned toNone joerg_wunsch
        Open/ClosedOpen Closed
        Fixed ReleaseNone 1.6.3
    2010-02-03 joerg_wunsch StatusNeed Info Confirmed
    2010-02-02 timurgilfanov Attached File- Added compile_error, #19605
    2010-02-01 timurgilfanov Attached File- Added power.h, #19590
        Attached File- Added power.h, #19591
    2010-01-28 kukiz100 Attached File- Added test_usb_mass_storage.rar, #19561
    2010-01-28 joerg_wunsch StatusNone Need Info
    2010-01-28 kukiz100 Carbon-Copy- Added kukiz100

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code