PB2 not defined

Hi

I'd like to write to an SD card and the reference is the library: www.roland-riegel.de - sd-reader: MMC/SD/SDHC card library

I've change the code a little, in fact exactly the same way as others in the forum have done to create a new SD library from this lib

So i've changed 4 define in sd_raw_config.h:
#define configure_pin_available() 0
#define configure_pin_locked() 0
#define get_pin_available() 0
#define get_pin_locked() 0

and added a defined(AVR_ATmega328P) (I've feedbacked roland to support this new uC)

=> It would compile perfectly if PB2 was defined, it's in fact a keyword in arduino, however I've never found a #define PB2 somewhere in the code

Last thing, PB2 has always been defined in roland lib and, it used to compile nicely before

So maybe arduino code has changed on this PB2 ? no more a keyword ? it would be nice to define it again for compatibility

PB2 seems to be the SPI pin /SS (Slave Select pin)
I think it's 10 according to http://www.arduino.cc/en/Tutorial/SPIEEPROM

Hi again

In fact I've found #define PB2 in avr-libc package

I'm using ubuntu 8.10 and as avr is broken, i use ubuntu 9.04 (jaunty) packages, that are:
ii avr-libc 1:1.6.2.cvs20080610-2 Standard C library for Atmel AVR development
ii binutils-avr 2.18-4ubuntu1 Binary utilities supporting Atmel's AVR targ
ii gcc-avr 1:4.3.2-1 The GNU C compiler (cross compiler for avr)

Anyone has ever compiled whatever SD lib for a 328p ? (all sd lib are based on roland lib)

I answer to myself again

In fact this problem concerns avr and roland lib, arduino has nothing to do in it

I can compile with no problem the lib of rolande for an ATmega168, but no way for a 328p, because of the lack of PB2 defined, as it's used in sd_raw_config.h

Sorry for disturbance, i contact directly Roland Riegel

Cheers

Hi again again,

I've been able to compile roland lib SD card now, except fat.c, 2 errors again

For information, i've changed *.c => *.cpp

i've added in sd_raw_config.h in the big test:
#elif defined(AVR_ATmega328P)
#define configure_pin_mosi() DDRB |= (1 << DDB3)
#define configure_pin_sck() DDRB |= (1 << DDB5)
#define configure_pin_ss() DDRB |= (1 << DDB2)
#define configure_pin_miso() DDRB &= ~(1 << DDB4)

#define select_card() PORTB &= ~(1 << PINB2)
#define unselect_card() PORTB |= (1 << PINB2)

and changed:
#define configure_pin_available() DDRC &= ~(1 << DDC4)
#define configure_pin_locked() DDRC &= ~(1 << DDC5)

#define get_pin_available() ((PINC >> PC4) & 0x01)
#define get_pin_locked() ((PINC >> PC5) & 0x01)

into:
#define configure_pin_available() //DDRC &= ~(1 << DDC4)
#define configure_pin_locked() //DDRC &= ~(1 << DDC5)

#define get_pin_available() 0 //((PINC >> PC4) & 0x01)
#define get_pin_locked() 0 //((PINC >> PC5) & 0x01)

But as I said, i still have 2 errors when compiling fat.c in arduino (but the lib compiles perfectly now with 328p with the Makefile) :

fat.cpp: In function 'uint8_t fat_dir_entry_read_callback(uint8_t*, offset_t, void*)':
fat.cpp:1491: error: invalid conversion from 'void*' to 'fat_read_dir_callback_arg*'
fat.cpp: In function 'offset_t fat_get_fs_free(const fat_fs_struct*)':
fat.cpp:2250: error: 'UINTPTR_MAX' was not declared in this scope

If anyone has an idea to how to resolve these last 2 errors, I would be very interested !!

PB2 is normally defined in the hierarchy of files included via <avr/io.h>;
In the 168 case, this includes <avr/iom168.h>, which includes <avr/iomx8.h> (definitions common to all Atmega*8), which actually defines PB2.

For the 328, assuming you have a recent compiler installed, the equivalent <avr/iom328.h> does NOT include <avr/iomx8.h>, nor does it define PB2. I don't know why.

Yes I've seen that

And I've stolen the patch applied in AF_Wave
That is, no more use PB2, but PINB2 instead, and it compiles

Except the last errors
Roland has answered me on the fact it's a nonsense to just rename fat.c in fat.cpp

However, Every lib I've seen on arduino to write on SD, just do this very bad thing...

I've been trying to figure this out, too. The value of UINTPTR_MAX is defined in:

..\hardware\tools\avr\avr\include\stdint.h

and this file is included by Roland's fat.h file. So, it's puzzling to me that this value is not picked up by the compiler...

I'd like to know the correct way to fix this but, in the end, I got the code to compile by replacing the value with 0xFFFE, which is what I believe the compiled value of UINTPTR_MAX - 1 would be.

Wayne

BTW, on the issue of why PB2 is not defined for the 328P, it appears that the include file io.h has a series of conditionals, like this:

#elif defined (AVR_ATmega328P)

include <avr/iom328p.h>

...
#elif defined (AVR_ATmega168)

include <avr/iom168.h>

that select the proper include file based on the processor type. The file avr/iom168.h #includes avr/iomx8.h which, in turn, contains #defines for both PINBn and PBn values. However, the file avr/iom328p.h seems to contain only #defines for PINBn values.

It appears that the design of the avr/iom328p.h makes it more of a standalone file that includes definitions for both pins and fuses whereas the avr/iom168.h defines fuse values and then includes avr/iomx8.h to define the pins.

However, I notice that there is also a file named avr/iom168p.h that is in the same combined style as avr/iom328p.h. But, apparently, this file is not selected when compiling for a 168-based Arduino. I'm new to the AVR family, so I find this all a bit confusing, but perhaps it makes sense to someone else...

Wayne

In looking over stdint.h, I finally noticed that the code contains this conditional:

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)

Since I also converted Roland's .c files to .cpp to get them to compile and link, it looks like this change broke the ability to reference the values in stdint.h. So, to fix it, I added a:

#define __STDC_LIMIT_MACROS 1

at the top of fat.cpp.

Wayne

That is, no more use PB2, but PINB2 instead, and it compiles

No-- don't do that. PB2 is meant to represent output, while PINB2 is meant to represent input. Change it to PORTB2 or just to the number '2' but DO NOT change it to PINB2.

this looks like the thread I need as I came from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/8 with the same errors you guys are reporting. tried to implement your changes

    defined(__AVR_ATmega168__)
    #define configure_pin_mosi() DDRB |= (1 << DDB3)
    #define configure_pin_sck() DDRB |= (1 << DDB5)
    #define configure_pin_ss() DDRB |= (1 << DDB2)
    #define configure_pin_miso() DDRB &= ~(1 << DDB4)
    #define select_card() PORTB &= ~(1 << PB2)
    #define unselect_card() PORTB |= (1 << PB2)
#elif defined(__AVR_ATmega328P__)
   #define configure_pin_mosi() DDRB |= (1 << DDB3)
   #define configure_pin_sck() DDRB |= (1 << DDB5)
   #define configure_pin_ss() DDRB |= (1 << DDB2)
   #define configure_pin_miso() DDRB &= ~(1 << DDB4)

   #define select_card() PORTB &= ~(1 << PORTB2)
   #define unselect_card() PORTB |= (1 << PORTB2)

and

#define configure_pin_available() //DDRC &= ~(1 << DDC4)
#define configure_pin_locked() //DDRC &= ~(1 << DDC5)

#define get_pin_available() 0 //((PINC >> PC4) & 0x01)
#define get_pin_locked() 0 //((PINC >> PC5) & 0x01)

but I get

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:13: error: 'byte' does not name a type

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:16: error: 'byte' does not name a type

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void setup()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:22: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:23: error: 'delay' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void loop()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:39: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:41: error: 'incomingByte' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int sample()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:61: error: 'byte' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:61: error: expected `;' before 'low'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:62: error: expected `;' before 'high'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:63: error: expected `;' before 'inByte'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:65: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:72: error: 'inByte' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:75: error: 'analogRead' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:76: error: 'DEC' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:80: error: 'low' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:81: error: 'high' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:86: error: 'tempBytes' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:94: error: 'delay' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int readDisk()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:106: error: 'byte' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:106: error: expected `;' before 'low'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:107: error: expected `;' before 'high'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:108: error: expected `;' before 'info'

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:111: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:114: error: 'info' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:119: error: 'low' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:120: error: 'high' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:124: error: 'DEC' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void printWelcome()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:132: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int print_disk_info()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:153: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:155: error: 'HEX' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:161: error: 'DEC' was not declared in this scope

any ideas?

how about if anyone has the library with modifications that I can download so I know I didn't mess up what I was supposed to patch?

Thanks a bunch

ok fixed the byte errors with

#define byte uint8_t

but i still get

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void setup()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:23: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:24: error: 'delay' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void loop()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:40: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int sample()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:66: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:76: error: 'analogRead' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:77: error: 'DEC' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:95: error: 'delay' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int readDisk()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:112: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:125: error: 'DEC' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'void printWelcome()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:133: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp: In function 'int print_disk_info()':

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:154: error: 'Serial' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:156: error: 'HEX' was not declared in this scope

/home/sirus/arduino/hardware/libraries/SDcard/arduino sd card example.cpp:162: error: 'DEC' was not declared in this scope

I think you need to include this (or something similar) at the start of the file:

#include "WProgram.h"

--Philip;

thanks for the reply but there is no change. also the IDE seems to be really really really buggy. I can only save a sketch once and then it gets set to read only. trying to save again gives me an error message. going into windows explorer and changing the permissions doesnt work as the ide sets them right back to read only. every time i have to save a new sketch to a new directory and delete the old one. my IDE doesnt even resize correctly I get black bars. I've tried on 3 different computers. 1 ubuntu and 2 windows 7. is 17 just a buggy build? should i go to 16?

I can't speak for windoze, but 017 runs quite OK on linux.

The missing PB2 or PORTB2 definitions are caused by

../include/avr/portpins.h

The windows version of 017 comes with an older version of avr-libc that still has that problem. Later versions of avr-libc have it fixed.

The fixed version of that file has entries like

#if defined(PB2) && !defined(PORTB2)
#  define PORTB2 PB2
#elif defined(PORTB2) && !defined(PB2)
#  define PB2 PORTB2
#endif

which works both ways. Half of that is missing in 017 on windows.

i think i have the pb2 and portb2 stuff figured out but what cant it figure out what Serial HEX DEC and that stuff is? works with simple sketches but now when i try to build anything complicated like this

anyone get this working?

bump

I am also looking for a fix to this issue

ok, I took a different approach. Working great in windows, with a 328 chip on V17.

First, you are going to need the working code :slight_smile: God bless GPL!
http://github.com/nseidle/OpenLog/tree/master/Code/

Grab sd_raw.c sd_raw.h, sd_raw_config.h
rename sd_raw.c to sd_raw.cpp

Place those 3 files in a new libraries file. Mine looks like this "C:\Program Files (x86)\arduino-0017\hardware\libraries\sdcard"
And all 3 are in the "sdcard" dir.

Time for hello world!

#include "sd_raw_config.h"
#include "sd_raw.h"

void setup()  
{                  
  Serial.begin(9600);
}

void loop()                     
{
  sd_raw_init();
  
  struct sd_raw_info disk_info;
  if(!sd_raw_get_info(&disk_info))
  {
      //return 0;
  }
    
  Serial.println();
  Serial.print("rev:    "); 
  Serial.print(disk_info.revision,HEX); 
  Serial.println();
  Serial.print("serial: 0x"); 
  Serial.print(disk_info.serial,HEX); 
  Serial.println();
  Serial.print("date:   "); 
  Serial.print(disk_info.manufacturing_month,DEC); 
  Serial.println();
  Serial.print(disk_info.manufacturing_year,DEC); 
  Serial.println();
  Serial.print("size:   "); 
  Serial.print(disk_info.capacity,DEC); 
  Serial.println();
  Serial.print("copy:   "); 
  Serial.print(disk_info.flag_copy,DEC); 
  Serial.println();
  Serial.print("wr.pr.: ");
  Serial.print(disk_info.flag_write_protect_temp,DEC); 
  Serial.print('/');
  Serial.print(disk_info.flag_write_protect,DEC); 
  Serial.println();
  Serial.print("format: "); 
  Serial.print(disk_info.format,DEC); 
  Serial.println();
  Serial.print("free:   "); 
  delay(10000);
}

You should see something like this show up:

rev:    3
serial: 0x3032057D
date:   7
5
size:   125698048
copy:   0
wr.pr.: 0/0
format: 0
free:   1

Next on the list.. Round Robin FS(RRFS)!