Missing symbols in avr-libc

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using an ATtiny861a, and noticed iotn861a.h has several macros defined under "Device Pin Definitions", for example:

#define PB0_DDR   DDRDOSI
#define PB0_PORT  PORTMOSI
#define PB0_PIN   PINMOSI
#define PB0_BIT   MOSI

But I can't find the definitions for any of the symbols on the right.  Unfortunately, neither can my compiler.  e.g. When I try to use PB0_PORT I get a compiler error like "'PORTMOSI' undeclared (first use in this function)". 

 

I suspect there's supposed to be lines somewhere (maybe in iotnx61.h) like:

#define DDRMOSI   DDRB
#define PORTMOSI  PORTB
#define PINMOSI   PINB
#define MOSI      0

Is this a bug in the library?  If so, where can I report it?  Note I'm using AtmelStudio 7 (and whatever avr-libc came with it).

 

The macros would be handy so I can use them to construct helpers like:

#define LED PB0
SETBIT(PORTNAME(LED), BITINDEX(LED))

I'd prefer to pull pin pinid-to-port-mappings from the stock headers rather than define them myself for each chip.

 

EDIT: I noticed some further issues.  e.g. PB4_PORT and PA4_PORT are defined as the same thing, which strikes me as obviously wrong.

Last Edited: Thu. Oct 10, 2019 - 03:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It should be called garbage instead of bugs.
The macro you like will still be realizable.

 

#include <avr/io.h>

// MACROS
#define SETBIT(PORT, BIT)   PORT |= BIT
#define CLRBIT(PORT, BIT)   PORT &= ~BIT
#define TGLBIT(PORT, BIT)   PORT ^= BIT

// DEFINES
#define LED_PORT    PORTB
#define LED_BIT     _BV(0)


int main(void)
{
    SETBIT(LED_PORT, LED_BIT);
    CLRBIT(LED_PORT, LED_BIT);
    TGLBIT(LED_PORT, LED_BIT);

    while (1){}
}

 

It will be necessary to devise more in order to obtain two information of port name and bit field from one word "PB0".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the tip, but that's not quite what I'm after.

I started going through the header and making corrections - I see what you mean about the "garbage" comment.  The mistakes are so obvious - how come nobody's fixed it?  How do I submit my corrections back to the project?

Last Edited: Thu. Oct 10, 2019 - 07:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it is appropriate for you to become a member here and make an effort to be hired. Please do your best.

https://www.nongnu.org/avr-libc/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.  I was hoping that wasn't the up-to-date home page.  Will try to figure out where their repository is and how to submit fixes...

 

(ps. I removed the example from my last post as I realized in retrospect it needs some work)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remembered one thing.

In Arduino UNO, PORTB-BIT0 is indicated by only one word “D8”.
It may be helpful to see how the digitalWrite function gets the port name and bitfield.

I don't know how the implementation is done, but it's a function created by very clever people, so it might be made that way if it can be done with macros.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rkagerer wrote:
I was hoping that wasn't the up-to-date home page.
Note that there are two parallel developments of avr-gcc/AVR-LibC, one in the open by FSF GNU and one inside Microchip/Atmel. The latest device support is done first in Microchip then slowly makes it way to the open copy of AVR-LibC. If you look at 

 

https://www.nongnu.org/avr-libc/

 

you are looking at the "open" one.

 

Note also that to try and remedy the situation the stuff that Microchip hold in advance of the core AVR-LibC is now made available in "Device Packs" and can be used with -b on the build tools.