miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.75k stars 1.43k forks source link

A series of compiler errors are thrown when using this library with ATtiny804 device #523

Closed TomWS1 closed 4 years ago

TomWS1 commented 4 years ago

Step 1: Describe your environment

Step 2: Describe the problem

The compiler throws errors when compiling for a board using ATtiny804 device and the megaTinyCore. The issue is that the boards package redefines __FlashStringHelper as char due to the fact that there is no helper function required to access program memory as data with this series of processors.

This can be fixed with the 'hack' of renaming __FlashStringHelper in MFRC522.h and MFRC522.cpp to MEM_REF_HELPER and adding to MFRC522.h:

if defined(__AVR_ATtinyx04__)

define MEM_REF_HELPER char

else

define MEM_REF_HELPER __FlashStringHelper

endif

Affected file(s) or example(s):

Steps to reproduce:

  1. Select Board "ATtiny1614/1604/...", Chip: ATtiny804

  2. Compile any code using the MFRC522 library

Observed Results:

Expected Results:

Relevant Code:

  // TODO(you): code here to reproduce the problem

errors.txt

src.zip

Rotzbua commented 4 years ago

Must be fixed by the framework of the board. The simple solution was to typedef __FlashStringHelper as char and define F() macro which does not modify the string. But then the RAM consumption is high.

TomWS1 commented 4 years ago

Not quite as simple as that as all functions that attempt to overload with _FlashStringHelper then fail as duplicate overloads. I suppose one way around it is to implement FlashStringHelper so that it beningly returns a char*

Rotzbua commented 4 years ago

@TomWS1 Arduino.h of megatinycore 2.0.5 does redefine F() with type char:

#undef F
#define F(str) (str)

String.h has a different definition with type __FlashStringHelper.

So basically the framework has a problem with different behavior of a macro. That problem must be solved on framework site.