New place for eeprom programming program

This commit is contained in:
Hakan Bastedt
2024-12-10 20:57:16 +01:00
parent 44d2324a03
commit 2871fd7905
12 changed files with 299 additions and 238 deletions

5
Utils/EEPROM_store_valid/.gitignore vendored Executable file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@@ -0,0 +1,17 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_port = COM3
monitor_speed = 115200
lib_deps = robtillaart/I2C_EEPROM

View File

@@ -0,0 +1,163 @@
// Write a valid eeprom for LAN9252.
//
#include <Wire.h>
#include <I2C_eeprom.h>
// Define LAN9252 or AX58100
// Output below from binary eeprom: xxd --include eeprom_data.bin
// #define LAN9252
// #define AX58100
#define LAN9252
//#define PROGRAM_EEPROM
// Don't define PROGRAM_EEPROM if you only want to read out contents
#ifdef LAN9252
#define ESC_STRING "LAN9252"
const uint8_t eeprom_data[] = {
0x04, 0x0f, 0x00, 0x44, 0x10, 0x27, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xd4, 0x00, 0xd8, 0x04, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x1c, 0x00,
0x02, 0x0d, 0x4c, 0x41, 0x4e, 0x39, 0x32, 0x35, 0x32, 0x2d, 0x44, 0x49,
0x47, 0x49, 0x4f, 0x28, 0x39, 0x32, 0x35, 0x32, 0x20, 0x38, 0x20, 0x43,
0x68, 0x2e, 0x20, 0x44, 0x69, 0x67, 0x2e, 0x20, 0x49, 0x6e, 0x2d, 0x2f,
0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x32, 0x78, 0x4d, 0x49, 0x49,
0x20, 0x28, 0x4e, 0x6f, 0x20, 0x44, 0x43, 0x29, 0x1e, 0x00, 0x10, 0x00,
0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00,
0x01, 0x02, 0x29, 0x00, 0x08, 0x00, 0x01, 0x0f, 0x00, 0x00, 0x44, 0x00,
0x01, 0x03, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0xff, 0xff
};
#endif
#ifdef AX58100
#define ESC_STRING "Ax58100"
// xxd --include eeprom_data.bin
unsigned char eeprom_data[] = {
0x04, 0x0d, 0x00, 0x44, 0x10, 0x27, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc1, 0x00, 0x95, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x1b, 0x00,
0x02, 0x0b, 0x41, 0x58, 0x35, 0x38, 0x31, 0x30, 0x30, 0x5f, 0x45, 0x56,
0x42, 0x28, 0x41, 0x58, 0x35, 0x38, 0x31, 0x30, 0x30, 0x20, 0x45, 0x56,
0x42, 0x20, 0x28, 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x31,
0x36, 0x2d, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x2f, 0x31, 0x36, 0x2d, 0x4f,
0x75, 0x74, 0x70, 0x75, 0x74, 0x29, 0x1e, 0x00, 0x10, 0x00, 0x01, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x01, 0x00, 0x01, 0x02,
0x29, 0x00, 0x0c, 0x00, 0x02, 0x0f, 0x00, 0x00, 0x44, 0x00, 0x01, 0x03,
0x03, 0x0f, 0x00, 0x00, 0x44, 0x00, 0x01, 0x03, 0x00, 0x10, 0x00, 0x00,
0x00, 0x00, 0x01, 0x04, 0xff, 0xff};
#endif
// 32 kbit bytes
#define EEPROM_MAXBYTES 32 * 1024 / 8
// the address of your EEPROM
#define DEVICEADDRESS (0x50)
I2C_eeprom eeprom(DEVICEADDRESS, EEPROM_MAXBYTES);
void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
void printHex(byte b);
void setup()
{
Serial.begin(115200);
while (!Serial)
;
Serial.println();
Serial.println("IT IS BEGINNING");
Serial.println("WAIT FOR IT");
Wire.begin();
eeprom.begin();
#ifdef PROGRAM_EEPROM
Serial.println("----------------------------------------------");
Serial.print("Writing ");
Serial.print(sizeof(eeprom_data));
Serial.print(" long data for ");
Serial.println(ESC_STRING);
uint8_t ok;
ok = eeprom.writeBlockVerify(0, eeprom_data, sizeof(eeprom_data));
if (ok)
{
Serial.println("Success writeBlockVerify");
Serial.println("\nThat's it. It worked\n");
}
else
{
Serial.println("Failed writeBlockVerify");
}
Serial.println("----------------------------------------------");
#endif
dumpEEPROM(0, sizeof(eeprom_data));
}
void loop()
{
// Nothing to do during loop
}
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
{
const int BLOCK_TO_LENGTH = 12;
Serial.print(" ");
for (int x = 0; x < 10; x++)
{
if (x != 0)
Serial.print(" ");
Serial.print(x, HEX);
}
Serial.println("\n--------------------------------------------------------");
// block to defined length
memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
// length = (length + BLOCK_TO_LENGTH - 1) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
byte b = eeprom.readByte(memoryAddress);
for (unsigned int i = 0; i < length; i++)
{
char buf[16];
if (memoryAddress % BLOCK_TO_LENGTH == 0)
{
if (i != 0)
Serial.println();
if (memoryAddress == 0)
Serial.print(" ");
else if (memoryAddress < 100)
Serial.print(" ");
else if (memoryAddress < 1000)
Serial.print(" ");
Serial.print(memoryAddress);
Serial.print(": ");
}
printHex(b);
b = eeprom.readByte(++memoryAddress);
}
Serial.println("\n-----------------------------------");
}
void printHex(byte b)
{
char buf[20];
sprintf(buf, "0x%02x ", b);
Serial.print(buf);
}

View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html