fabriziop / EEWL

The EEWL library allows to extend the EEPROM life by distributing data writes along a circular buffer.
GNU Lesser General Public License v3.0
10 stars 1 forks source link

LGT8F328P: compile error #4

Closed fulvioalessio closed 1 year ago

fulvioalessio commented 1 year ago

Hi, using platformio:

[env:LGT8F328P]
platform = lgt8f
board = LGT8F328P
framework = arduino
board_build.f_cpu=16000000L
;internal clock
board_build.clock_source=1
lib_deps = fabriziop/EEWL

When I try to compile the code copied from countPowerCyclesDebug, I get this error:

Dependency Graph
|-- EEWL @ 0.5.3
|   |-- E2PROM
Building in release mode
Compiling .pio/build/LGT8F328P/src/lgt8f328p/main.cpp.o
Archiving .pio/build/LGT8F328P/lib441/libE2PROM.a
Indexing .pio/build/LGT8F328P/lib441/libE2PROM.a
In file included from src/lgt8f328p/main.cpp:27:0:
.pio/libdeps/LGT8F328P/EEWL/src/eewl.h: In member function 'void EEWL::begin()':
.pio/libdeps/LGT8F328P/EEWL/src/eewl.h:47:36: error: no match for 'operator[]' (operand types are 'EEPROMClass' and 'int')
     #define EE_READ( addr ) (EEPROM[(int)( addr )])
                                    ^
.pio/libdeps/LGT8F328P/EEWL/src/eewl.h:121:11: note: in expansion of macro 'EE_READ'
       if (EE_READ(addr) != 0xff) {
           ^~~~~~~
.pio/libdeps/LGT8F328P/EEWL/src/eewl.h:38:43: error: no match for 'operator[]' (operand types are 'EEPROMClass' and 'int')

(I added on top of example)

Using Arduino IDE, example works fine. I'm missing something ? TIA f.

fabriziop commented 1 year ago

Hi, it seems to me that the EEPROM.h of LGT8F328P sdk lacks the [] operator. From what I've read, this micro is also different because it doesn't have a real EEPROM and creates one by simulating it with Flash memory. So I can say that the LGT8F328P is not supported by the EEWL library. I have not found board support for LGT8F328P in the Arduino IDE. Have you compiled for LGT8F328P or for an other micro in the Arduino IDE? Anyway, PlatformIO compiles fine the countPowerCyclesDebug example for the ATmega328 with the following .ini


  [env:nanoatmega328]
  platform = atmelavr
  board = nanoatmega328
  framework = arduino
  lib_deps = fabriziop/EEWL
fulvioalessio commented 1 year ago

Hi Fabrizio,

I've changed my eewl.h in this way, now countPowerCyclesDebug compile and works with LGT8F328P cpu with platformio.ini configuration of the previous message:

#ifdef EEWL_RAM
  #define EE_WRITE( addr , val ) (buffer[(int)( addr )] = val)
  #define EE_READ( addr ) (buffer[(int)( addr )])
#else
  #ifdef __AVR__
    #if defined(__LGT8FX8P__)
      #define EE_WRITE( addr , val ) (EEPROM.write((uint16_t)( addr ), val))
      #define EE_READ( addr ) (EEPROM.read((uint16_t)( addr )))
    #else
      #define EE_WRITE( addr , val ) (EEPROM[ (int)( addr )  ].update( val ))
      #define EE_READ( addr ) (EEPROM[(int)( addr )])
    #endif
  #elif defined(ESP8266) || defined(ESP32)
    #define EE_WRITE( addr , val ) (EEPROM.write((int)( addr ),( val )))
    #define EE_READ( addr ) (EEPROM[(int)( addr )])
  #else
    #error ERROR: unsupported architecture 
  #endif
#endif

output:

power cycles = 8
blk_size:   5
blk_num:    10
blk_addr:   33
blk_mark:   FE
start_addr: 10
end_addr:   42
10: FF-1 0 0 0 
15: FF-2 0 0 0 
1A: FF-3 0 0 0 
1F: FF-4 0 0 0 
24: FF-5 0 0 0 
29: FF-6 0 0 0 
2E: FF-7 0 0 0 
33: FE-8 0 0 0 
38: FF-10 A0 FF 2 
3D: FF-FF C8 B4 FF
fabriziop commented 1 year ago

I have found this EEPROM library (https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json), installed on arduino IDE and updated to version 2.0.0 it has full API compatibility with ATMega EEPROM library. The EEWL example compiles fine both on Arduino IDE and on PlatformIO with this library. So no changes are needed to EEWL. Since I have no experience with PlatformIO library upgrade, I copied EEPROM files manually as follow cp ./.arduino15/packages/lgt8fx/hardware/avr/2.0.0/libraries/E2PROM/EEPROM.h ./.platformio/packages/framework-lgt8fx/libraries/E2PROM/EEPROM.h cp ./.arduino15/packages/lgt8fx/hardware/avr/2.0.0/libraries/E2PROM/EEPROM.cpp ./.platformio/packages/framework-lgt8fx/libraries/E2PROM/EEPROM.cpp I hope this can help.

fulvioalessio commented 1 year ago

Hi Fabrizio, thank you. I'll use your tips until LGT8F* receive an update