├── .gitignore ├── library.json ├── library.properties ├── src ├── Dump.h └── Dump.cpp ├── examples └── memDump │ └── memDump │ └── memDump.ino └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .pioenvs 3 | .clang_complete 4 | .gcc-flags.json 5 | .piolibdeps 6 | /debug 7 | .gitignore 8 | !/.gitignore 9 | lib 10 | .travis.yml 11 | !/.travis.yml 12 | /TODO.txt 13 | platformio.ini 14 | !/platformio.ini 15 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dump", 3 | "keywords": "memory ram flash progmem debug utility print", 4 | "description": "AVR dump RAM and Flash", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/neu-rah/Dump", 9 | "branch": "master" 10 | }, 11 | "frameworks": "arduino", 12 | "platforms": "*" 13 | } 14 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Dump 2 | version=1.0.2 3 | author=Rui Azevedo, ruihfazevedo@gmail.com 4 | maintainer=neu-rah, ruihfazevedo@gmail.com 5 | sentence=AVR dump RAM and Flash 6 | paragraph=Utility for debugging memory locations 7 | category=Other 8 | url=https://github.com/neu-rah/Dump 9 | dot_a_linkage=false 10 | architectures=* 11 | includes=Dump.h 12 | -------------------------------------------------------------------------------- /src/Dump.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | #include 3 | #include 4 | 5 | unsigned char memByteRam(const void* x); 6 | unsigned char memBytePgm(const void* x); 7 | void dump(Print& out,void const*at,int sz,unsigned char (*memByte)(const void*)); 8 | void dumpRam(Print& out,void const*at,int sz); 9 | void dumpPgm(Print& out,void const*at,int sz); 10 | -------------------------------------------------------------------------------- /examples/memDump/memDump/memDump.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const unsigned char ramTest[] ="@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@"; 4 | const unsigned char pgmTest[] PROGMEM="@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@#@"; 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | while(!Serial); 9 | delay(2000); 10 | } 11 | 12 | void loop() { 13 | Serial.println("Dump RAM example"); 14 | dumpRam(Serial,ramTest,64); 15 | Serial.println(); 16 | Serial.println("Dump Flash/Progmem example"); 17 | dumpPgm(Serial,pgmTest,64); 18 | Serial.println(); 19 | delay(2000); 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dump 2 | 3 | Simple memory dump for AVR RAM and Flash (progmem) 4 | 5 | ## API 6 | 7 | ### RAM 8 | 9 | ```c++ 10 | void dumpRam(Print& out,void const*at,int sz) 11 | ``` 12 | dump ram values to output where: 13 | 14 | - **out** : The output device, ex: Serial 15 | - **at** : The memory pointer 16 | - **sz** : The size o memory in bytes 17 | 18 | ### Flash / PROGMEM 19 | ```c++ 20 | void dumpPgm(Print& out,void const*at,int sz) 21 | ``` 22 | dump flash memory values to output where: 23 | 24 | - **out** : The output device, ex: Serial 25 | - **at** : The memory pointer 26 | - **sz** : The size o memory in bytes 27 | 28 | ## Output example 29 | 30 | ```text 31 | Dump RAM example 32 | 0x100: ......e. ......0. 00 00 00 00 E9 00 65 00 B2 00 90 00 A4 00 30 01 33 | 0x110: ...=.0.0 x.: .Dum 0D 0A 00 3D 00 30 00 30 78 00 3A 20 00 44 75 6D 34 | 0x120: p RAM ex ample.Du 70 20 52 41 4D 20 65 78 61 6D 70 6C 65 00 44 75 35 | 0x130: mp Flash /Progmem 6D 70 20 46 6C 61 73 68 2F 50 72 6F 67 6D 65 6D 36 | 37 | Dump Flash/Progmem example 38 | 0x100: .+...... !....... 89 2B 11 F4 7E 01 02 C0 21 96 EC CF C7 01 DF 91 39 | 0x110: ........ ........ CF 91 1F 91 0F 91 FF 90 EF 90 DF 90 CF 90 08 95 40 | 0x120: ........ a....... FC 01 91 8D 82 8D 98 17 61 F0 82 8D DF 01 A8 0F 41 | 0x130: ..]..... ._.s.... B1 1D 5D 96 8C 91 92 8D 9F 5F 9F 73 92 8F 90 E0 42 | ``` 43 | -------------------------------------------------------------------------------- /src/Dump.cpp: -------------------------------------------------------------------------------- 1 | #include "Dump.h" 2 | 3 | unsigned char memByteRam(const void* x) {return *(char*)x;} 4 | unsigned char memBytePgm(const void* x) {return pgm_read_byte(x);} 5 | 6 | void dump(Print& out,void const*at,int sz,unsigned char (*memByte)(const void*)) { 7 | while(sz>0) { 8 | out.print("0x"); 9 | out.print((unsigned long)at < 0x10 ? "000" : (unsigned long)at<0x100 ? "00" : (unsigned long)at<0x1000 ? "0" : ""); 10 | out.print((unsigned long)at,HEX); 11 | out.print(": "); 12 | for(int c=0;c<16;c++) { 13 | if (c==8) out.write(' '); 14 | if (sz-c>0) { 15 | // Because ISO C forbids `void*` arithmetic, we have to do some funky casting 16 | void *memAddress = (void *)((int)at + c); 17 | unsigned char v = memByte(memAddress); 18 | 19 | out.write((v>=32&&v<='z'/*&&v!=0xBF*/)?v:'.'); 20 | } else out.write(' '); 21 | } 22 | out.write(' '); 23 | for (int c=0; c<16 && sz; c++, sz--) { 24 | // Because ISO C forbids `void*` arithmetic, we have to do some funky casting 25 | unsigned char v=memByte(at); 26 | at = (void *)((int)at + 1); 27 | 28 | if (c==8) out.write(' '); 29 | out.print(v<16?"0":""); 30 | out.print(v,HEX); 31 | out.write(' '); 32 | } 33 | out.println(); 34 | } 35 | } 36 | 37 | void dumpRam(Print& out,void const*at,int sz) {return dump(out,at,sz,memByteRam);} 38 | void dumpPgm(Print& out,void const*at,int sz) {return dump(out,at,sz,memBytePgm);} 39 | --------------------------------------------------------------------------------