├── Schemes ├── Scheme.fzz └── Scheme Flash Memory Programmer.png ├── GUI_python3 ├── avr.png └── FlashMemoryProgrammer_GUI.py ├── CartridgeProgrammer.png ├── .gitattributes ├── README.md ├── .gitignore ├── Arduino_program └── FLASH_EEPROM_5V_PROGRAMMER │ └── FLASH_EEPROM_5V_PROGRAMMER.ino ├── LICENSE.txt └── FlashMemoryProgrammer_GUI.py.old /Schemes/Scheme.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warber0x/FMPUNO/HEAD/Schemes/Scheme.fzz -------------------------------------------------------------------------------- /GUI_python3/avr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warber0x/FMPUNO/HEAD/GUI_python3/avr.png -------------------------------------------------------------------------------- /CartridgeProgrammer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warber0x/FMPUNO/HEAD/CartridgeProgrammer.png -------------------------------------------------------------------------------- /Schemes/Scheme Flash Memory Programmer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/warber0x/FMPUNO/HEAD/Schemes/Scheme Flash Memory Programmer.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Finally FMPUNO Is now compatible with python3 :gift: 2 | - Nickname in arduino forum: BlackSharp (to search through the arduino forum discussion) 3 | - Date of the first release: 12/24/2013. 4 | - Date of last release: 24/11/2021 5 | - Date Github publish: 06/05/2014. 6 | - Video link: https://www.youtube.com/watch?v=Dh3tBewMzdY 7 | 8 | 9 | ![Cartridge Programmer](CartridgeProgrammer.png) 10 | 11 | After so many years, I wanted to bring to life this project that I made before and make it more stable especially the GUI app. Now, the application is more stable and works like a charm. 12 | 13 | **IMPORTANT NOTICE: The diagram wiring image has an issue** 14 | * PIN 32 -> VCC 15 | * PIN 16 -> Ground 16 | 17 | ## Introduction: 18 | This project is a Flash memory programmer based on Arduino UNO. 19 | 20 | The main reason for creating this project is to be able to program a flash memory, put it in gameboy cartidge and play any game you want. The commercial programmer is expensive and creating your own is fun ... 21 | 22 | In this repo you'll find the graphic scheme of the project in JPEG format as well as in Fritzing format. 23 | 24 | If you wan to build this, it's not difficult. Just respect the wiring and everything will be okay. 25 | 26 | The diagram is not perfect I know but it helps ... Maybe one day I will make it better :zzz: 27 | 28 | Some resistors are not added in the diagram. Therefore, don't forget to add resistor for every input especially for Adresses and Data chip pins, the same for arduino and the shift registers (The floating state values is the main problem if it doesn't work). All of the resistors in the project are in 10Kohms. 29 | 30 | You must have a gameboy cartidge that has a flash instead of ROM chip 31 | 32 | Adding to this, I have programmed a Python GUI software to make a chip programming more easier. The supported chips are: 33 | 34 | - Amic A29040. 35 | - AMD AM29F040. 36 | - AMD AM29F010. 37 | 38 | The GUI app works with python3. It crashes sometimes when the upload is finished. You are free to increase or customize the code (But keep my name plz). 39 | 40 | ## REQUIREMENTS: 💾 41 | - Computer with linux/Windows 7. Linux is recommanded (I was testing on KALI) 42 | - Tested with python3 (There were major bugs in python2) 43 | - Wxpython library (pip3 install wxpython) 44 | - Pubsub lib 45 | - Arduino IDE with the Flash_memory_programmer Sketch. 46 | - Circuit, Diagram ... you know what I mean :wink: 47 | - Chip AM29F010-40, A29010-40 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /Arduino_program/FLASH_EEPROM_5V_PROGRAMMER/FLASH_EEPROM_5V_PROGRAMMER.ino: -------------------------------------------------------------------------------- 1 | /* @Author: Radouane SAMIR 2 | @Version: 0.1 3 | @Chip version: AM29F010 A29040 4 | 5 | This code is tested on AM29F010. 6 | 7 | For AM29F040B the command sequence are little bit different: 8 | 0x555 rather than 0x5555 see the datasheet. But the timing is the same 9 | 10 | You are free to modify the code as you want, but please keep my name as is. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | /* Flash SIZE, used only in read operation*/ 17 | #define FLASHSIZE 131072 18 | 19 | uint32_t address = 0; 20 | uint32_t gameSize = 0; 21 | 22 | char buffer[20] = {0}; 23 | char cmd = 0; 24 | int index = 0; 25 | char tab[10] = {0}; 26 | 27 | /* Need a fast change mode IN/OUT */ 28 | 29 | void flash_change_pins_mode(boolean io) 30 | { 31 | if (io) { 32 | DDRD &= ~(1<<2); 33 | DDRD &= ~(1<<3); 34 | DDRD &= ~(1<<4); 35 | DDRD &= ~(1<<5); 36 | DDRD &= ~(1<<6); 37 | DDRD &= ~(1<<7); 38 | DDRB &= ~(1<<0); 39 | DDRB &= ~(1<<1); 40 | } 41 | else 42 | { 43 | DDRD |= (1<<2); 44 | DDRD |= (1<<3); 45 | DDRD |= (1<<4); 46 | DDRD |= (1<<5); 47 | DDRD |= (1<<6); 48 | DDRD |= (1<<7); 49 | DDRB |= (1<<0); 50 | DDRB |= (1<<1); 51 | } 52 | } 53 | 54 | void flash_ctrl_deselect() 55 | { 56 | digitalWrite(10, HIGH); //CE 57 | digitalWrite(12, HIGH); //WE 58 | digitalWrite(11, HIGH); //OE 59 | } 60 | 61 | void flash_ctrl_rd() 62 | { 63 | digitalWrite(11, LOW); 64 | _delay_us(1); 65 | digitalWrite(10, LOW); 66 | _delay_us(1); 67 | } 68 | 69 | void flash_ctrl_wr() 70 | { 71 | digitalWrite(10, LOW); 72 | _delay_us(1); 73 | digitalWrite(12, LOW); 74 | _delay_us(1); 75 | } 76 | 77 | /************************************************** 78 | Function to access to 79 | the highest addresses in the chip 80 | Highest 16bits is given to the function 81 | and do a bit manipulation to set pins High/Low 82 | ***************************************************/ 83 | 84 | void flash_set_highest_addresses(uint16_t addr) 85 | { 86 | /* Highest addresses */ 87 | 88 | if (addr&bit(0)) 89 | PORTC |= _BV(PORTC2); 90 | else 91 | PORTC &= ~_BV(PORTC2); 92 | 93 | if (addr&bit(1)) 94 | PORTC |= _BV(PORTC1); 95 | else 96 | PORTC &= ~_BV(PORTC1); 97 | 98 | if (addr&bit(2)) 99 | PORTC |= _BV(PORTC0); 100 | else 101 | PORTC &= ~_BV(PORTC0); 102 | } 103 | 104 | /**** 105 | * Shift registers manipulation 106 | *******************************/ 107 | 108 | void flash_enable_latch() 109 | { 110 | /* Shift register Latch */ 111 | digitalWrite(A4, HIGH); 112 | } 113 | 114 | void flash_disable_latch() 115 | { 116 | /* Shift register Latch */ 117 | digitalWrite(A4, LOW); 118 | } 119 | 120 | void flash_enable_serial_clock() 121 | { 122 | /* Shift register Serial clock */ 123 | digitalWrite(A3, HIGH); 124 | } 125 | 126 | void flash_disable_serial_clock() 127 | { 128 | digitalWrite(A3, LOW); 129 | } 130 | 131 | /** 132 | * Calculated the given address 133 | * shift register manipulation 134 | **************************************/ 135 | 136 | void flash_send_serial_data(uint16_t data) 137 | { 138 | /* Shift register manipulation */ 139 | /* Respect the wiring */ 140 | 141 | uint16_t addr = 0; 142 | byte octect1 = 0; 143 | byte octect2 = 0; 144 | 145 | addr = (data<<8); 146 | octect1 = (addr>>8); 147 | 148 | addr = (data>>8); 149 | octect2 = addr; 150 | 151 | flash_disable_latch(); 152 | for (int i=7;i>=0; i--) 153 | { 154 | flash_disable_serial_clock(); 155 | if (octect2&(1<=0; i--) 164 | { 165 | flash_disable_serial_clock(); 166 | if (octect1&(1<>16); 188 | 189 | flash_send_serial_data(LSB); 190 | flash_set_highest_addresses(MSB); 191 | } 192 | 193 | /** 194 | * Calculate the data given and set change pins state 195 | *****************************************************/ 196 | 197 | void flash_data_set(uint8_t data) 198 | { 199 | uint8_t temp; 200 | uint8_t temp2; 201 | 202 | temp = (data<<2); 203 | temp2 = (data>>6); 204 | 205 | for (int i = 2; i < 8; i++) 206 | { 207 | if (temp&bit(i)) 208 | { 209 | DDRD |= (1<>7); 279 | while (octect!=(data>>7)); 280 | flash_ctrl_deselect(); 281 | return true; 282 | } 283 | 284 | boolean flash_DQ7_erase_poll() 285 | { 286 | byte octect = 0; 287 | flash_change_pins_mode(1); 288 | octect = (flash_data_get()>>7); 289 | 290 | while (octect!=1) 291 | octect = (flash_data_get()>>7); 292 | 293 | if (octect) 294 | Serial.println("Erasure complete"); 295 | 296 | flash_ctrl_deselect(); 297 | return true; 298 | } 299 | 300 | /**** 301 | * Set command sequence and send it to the chip 302 | ***********************************************/ 303 | 304 | void flash_send_command(uint32_t addr, uint8_t data) 305 | { 306 | /* Send command sequence */ 307 | 308 | flash_addr_set(addr); 309 | delayMicroseconds(1); 310 | flash_ctrl_wr(); 311 | 312 | flash_data_set(data); 313 | delayMicroseconds(1); 314 | } 315 | 316 | /**** 317 | * Autoselect mode to get info from the chip 318 | * It's useful to test the chip before any operation 319 | ******************************************************/ 320 | 321 | void flash_device_id() 322 | { 323 | /* This is used to get code identification 324 | * from the chip in autoselect mode 325 | * See the datasheet 326 | ******************************************/ 327 | 328 | flash_ctrl_deselect(); 329 | 330 | //digitalWrite(11, HIGH); 331 | 332 | delay(1000); 333 | 334 | flash_change_pins_mode(0); 335 | 336 | flash_send_command(0x5555, 0xAA); 337 | flash_ctrl_deselect(); 338 | 339 | 340 | flash_send_command(0x2AAA, 0x55); 341 | flash_ctrl_deselect(); 342 | 343 | flash_send_command(0x5555, 0x90); 344 | flash_ctrl_deselect(); 345 | 346 | delay(1000); 347 | 348 | flash_change_pins_mode(1); 349 | 350 | flash_addr_set(0x01); 351 | delay(1); 352 | flash_ctrl_rd(); 353 | 354 | Serial.print(flash_data_get(), HEX); 355 | //Serial.print("Get device ID complete, Please wait restarting the chip ... "); 356 | delay(1); 357 | flash_reset_chip(); 358 | //Serial.println("Done."); 359 | delay(1000); 360 | flash_ctrl_deselect(); 361 | } 362 | 363 | /** AM29F040 **/ 364 | /***************/ 365 | 366 | void flash_get_id_40() 367 | { 368 | /* This is used to get code identification 369 | * from the chip in autoselect mode 370 | * See the datasheet 371 | ******************************************/ 372 | 373 | byte data = 0x00; 374 | 375 | flash_ctrl_deselect(); 376 | 377 | //digitalWrite(11, HIGH); 378 | 379 | delay(1000); 380 | 381 | flash_change_pins_mode(0); 382 | 383 | flash_send_command(0x555, 0xAA); 384 | flash_ctrl_deselect(); 385 | 386 | flash_send_command(0x2AA, 0x55); 387 | flash_ctrl_deselect(); 388 | 389 | flash_send_command(0x555, 0x90); 390 | flash_ctrl_deselect(); 391 | 392 | delay(1000); 393 | 394 | flash_change_pins_mode(1); 395 | 396 | flash_addr_set(0x00); 397 | flash_ctrl_rd(); 398 | 399 | data = flash_data_get(); 400 | 401 | if (data < 0x0A) 402 | Serial.print("0"); 403 | 404 | Serial.print(data, HEX); 405 | 406 | flash_ctrl_deselect(); 407 | 408 | flash_reset_chip(); 409 | delay(1000); 410 | } 411 | 412 | 413 | void flash_get_id() 414 | { 415 | /* This is used to get code identification 416 | * from the chip in autoselect mode 417 | * See the datasheet 418 | ******************************************/ 419 | 420 | byte data = 0x00; 421 | 422 | flash_ctrl_deselect(); 423 | 424 | //digitalWrite(11, HIGH); 425 | 426 | delay(1000); 427 | 428 | flash_change_pins_mode(0); 429 | 430 | flash_send_command(0x5555, 0xAA); 431 | flash_ctrl_deselect(); 432 | 433 | flash_send_command(0x2AAA, 0x55); 434 | flash_ctrl_deselect(); 435 | 436 | flash_send_command(0x5555, 0x90); 437 | flash_ctrl_deselect(); 438 | 439 | delay(1000); 440 | 441 | flash_change_pins_mode(1); 442 | 443 | flash_addr_set(0x00); 444 | flash_ctrl_rd(); 445 | 446 | data = flash_data_get(); 447 | 448 | if (data < 0x0A) 449 | Serial.print("0"); 450 | 451 | Serial.print(data, HEX); 452 | 453 | flash_ctrl_deselect(); 454 | 455 | flash_reset_chip(); 456 | delay(1000); 457 | } 458 | 459 | void flash_read_memory(uint32_t addr) 460 | { 461 | /* Read the chip until the address given */ 462 | int c = 0; 463 | 464 | flash_change_pins_mode(1); 465 | 466 | for (uint32_t i = 0; i < addr; i++) 467 | { 468 | flash_ctrl_deselect(); 469 | 470 | flash_addr_set(i); 471 | 472 | flash_ctrl_rd(); 473 | 474 | Serial.print(flash_data_get(),HEX); 475 | flash_ctrl_deselect(); 476 | } 477 | } 478 | 479 | /* This is the sequence to program a byte on the memory * 480 | * 0x5555 0x2AAA is for AM29F010 481 | * 0x555 0x2AA is for AM29F040 A29F040 482 | ********************************************************/ 483 | 484 | boolean flash_program_byte(uint32_t addr, uint8_t data) 485 | { 486 | flash_ctrl_deselect(); 487 | 488 | flash_send_command(0x5555, 0xAA); 489 | flash_ctrl_deselect(); 490 | 491 | flash_send_command(0x2AAA, 0x55); 492 | flash_ctrl_deselect(); 493 | 494 | flash_send_command(0x5555, 0xA0); 495 | flash_ctrl_deselect(); 496 | 497 | //Program Address & Program data 498 | flash_send_command(addr, data); 499 | flash_ctrl_deselect(); 500 | 501 | /** Data Polling **/ 502 | while (!flash_DQ7_byte_poll(addr, data)); 503 | 504 | return true; 505 | } 506 | 507 | /* This is the sequence to program a byte on the memory * 508 | * 0x5555 0x2AAA is for AM29F010 509 | * 0x555 0x2AA is for AM29F040 A29F040 510 | ********************************************************/ 511 | 512 | void flash_reset_chip() 513 | { 514 | /* This is reset command for the AM29F010 */ 515 | 516 | flash_ctrl_deselect(); 517 | 518 | flash_send_command(0x5555, 0xAA); 519 | flash_ctrl_deselect(); 520 | 521 | flash_send_command(0x2AAA, 0x55); 522 | flash_ctrl_deselect(); 523 | 524 | flash_send_command(0x5555, 0xF0); 525 | flash_ctrl_deselect(); 526 | 527 | delay(1000); 528 | } 529 | 530 | /* This is the sequence to program a byte on the memory * 531 | * 0x5555 0x2AAA is for AM29F010 532 | * 0x555 0x2AA is for AM29F040 A29F040 533 | ********************************************************/ 534 | 535 | void flash_erase_memory() 536 | { 537 | flash_ctrl_deselect(); 538 | delay(1000); 539 | 540 | //flash_change_pins_mode(0); 541 | 542 | flash_send_command(0x5555, 0xAA); 543 | flash_ctrl_deselect(); 544 | 545 | flash_send_command(0x2AAA, 0x55); 546 | flash_ctrl_deselect(); 547 | 548 | flash_send_command(0x5555, 0x80); 549 | flash_ctrl_deselect(); 550 | 551 | flash_send_command(0x5555, 0xAA); 552 | flash_ctrl_deselect(); 553 | 554 | flash_send_command(0x2AAA, 0x55); 555 | flash_ctrl_deselect(); 556 | 557 | flash_send_command(0x5555, 0x10); 558 | flash_ctrl_deselect(); 559 | 560 | _delay_ms(1000); 561 | //flash_DQ7_erase_poll(); 562 | flash_reset_chip(); 563 | Serial.print("Erasure Complete"); 564 | } 565 | 566 | /* To erase AM29F040 */ 567 | /*********************/ 568 | 569 | void flash_erase_memory2() 570 | { 571 | flash_ctrl_deselect(); 572 | delay(1000); 573 | 574 | //flash_change_pins_mode(0); 575 | 576 | flash_send_command(0x555, 0xAA); 577 | flash_ctrl_deselect(); 578 | 579 | flash_send_command(0x2AA, 0x55); 580 | flash_ctrl_deselect(); 581 | 582 | flash_send_command(0x555, 0x80); 583 | flash_ctrl_deselect(); 584 | 585 | flash_send_command(0x555, 0xAA); 586 | flash_ctrl_deselect(); 587 | 588 | flash_send_command(0x2AA, 0x55); 589 | flash_ctrl_deselect(); 590 | 591 | flash_send_command(0x555, 0x10); 592 | flash_ctrl_deselect(); 593 | 594 | _delay_ms(1000); 595 | //flash_DQ7_erase_poll(); 596 | //flash_reset_chip(); 597 | Serial.print("Erasure Complete"); 598 | } 599 | 600 | /* 601 | * Read data coming from the computer's USB port * 602 | *************************************************/ 603 | 604 | void receiveDataFromPC() 605 | { 606 | if (Serial.available()>0) 607 | { 608 | uint8_t data = Serial.read(); 609 | flash_program_byte(address++, data); 610 | } 611 | } 612 | 613 | /* Intiate the programing when the python GUI send a trigger */ 614 | /*************************************************************/ 615 | 616 | void startProgramming() 617 | { 618 | flash_change_pins_mode(0); 619 | 620 | Serial.print("+"); 621 | while (!Serial.available()); 622 | while (Serial.available() > 0) 623 | { 624 | char car = Serial.read(); 625 | delay(10); 626 | tab[index++]=car; 627 | 628 | } 629 | tab[index] = '\0'; 630 | 631 | Serial.print("+"); 632 | 633 | while(address <= atol(tab)) { 634 | receiveDataFromPC(); 635 | } 636 | } 637 | 638 | void setup() 639 | { 640 | Serial.begin(115200); 641 | //ANALOG_CONFIG; 642 | 643 | int c = 0; 644 | 645 | //Set the shift register pins 646 | 647 | pinMode(A5, OUTPUT); 648 | pinMode(A4, OUTPUT); 649 | pinMode(A3, OUTPUT); 650 | 651 | //set the highest address pins 652 | 653 | pinMode(A2, OUTPUT); 654 | pinMode(A1, OUTPUT); 655 | pinMode(A0, OUTPUT); 656 | 657 | //Set the chip controller 658 | 659 | pinMode(10, OUTPUT); 660 | pinMode(11, OUTPUT); 661 | pinMode(12, OUTPUT); 662 | 663 | //Set data pin mode 664 | pinMode(2, OUTPUT); 665 | pinMode(3, OUTPUT); 666 | pinMode(4, OUTPUT); 667 | pinMode(5, OUTPUT); 668 | pinMode(6, OUTPUT); 669 | pinMode(7, OUTPUT); 670 | pinMode(8, OUTPUT); 671 | pinMode(9, OUTPUT); 672 | 673 | delay(1000); 674 | 675 | address = 0; 676 | 677 | flash_ctrl_deselect(); 678 | } 679 | 680 | void loop() 681 | { 682 | while (!Serial.available()); 683 | cmd = Serial.read(); 684 | 685 | switch(cmd) 686 | { 687 | case 'R': 688 | flash_read_memory(0xFF); 689 | Serial.println(""); 690 | break; 691 | 692 | case 'E': 693 | flash_erase_memory(); 694 | Serial.println(""); 695 | break; 696 | 697 | case 'W': 698 | startProgramming(); 699 | Serial.println(""); 700 | break; 701 | 702 | case 'I': 703 | flash_get_id(); 704 | Serial.println(""); 705 | break; 706 | 707 | case 'D': 708 | flash_device_id(); 709 | Serial.println(""); 710 | break; 711 | 712 | default: 713 | cmd = 0; 714 | } 715 | cmd = 0; 716 | index = 0; 717 | memset(tab, '\0', sizeof(tab)); 718 | delay(10); 719 | } 720 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /FlashMemoryProgrammer_GUI.py.old: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | #@Author of this software: Radouane SAMIR. 4 | #@Date: 26/12/2014 5 | #@Version: 0.1 Beta 6 | #@Baud rate: Check the arduino Sketch 7 | 8 | #THIS NEEDS A WXPYTHON TO BE EXECUTED. 9 | 10 | import wx 11 | import os, sys 12 | import time 13 | import serial 14 | import struct 15 | import thread 16 | import threading 17 | 18 | from wx.lib.buttons import GenBitmapTextButton 19 | 20 | 21 | class programmer_gui(wx.Frame): 22 | def __init__(self, parent, id): 23 | 24 | wx.Frame.__init__(self, parent, id, 'FMPUNO (Flash Memory Programmer UNO) - By Warber0x (Radouane SAMIR)', size = (900, 380), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX ^ wx.MINIMIZE_BOX) 25 | panel = wx.Panel(self, pos = (0, 100), size = (700, 200)) 26 | self.percent = 0 27 | 28 | img = wx.Image('./avr.png') 29 | img.Rescale(170, 170) 30 | png = wx.BitmapFromImage(img) 31 | wx.StaticBitmap(panel, -1, png, (713, 130), (png.GetWidth(), png.GetHeight())) 32 | 33 | #Menu Gui 34 | status = self.CreateStatusBar() 35 | 36 | menubar = wx.MenuBar() 37 | filemenu = wx.Menu() 38 | editmenu = wx.Menu() 39 | aboutmenu = wx.Menu() 40 | 41 | 42 | exititem = filemenu.Append(wx.NewId(), "&Exit", "") 43 | aboutitem = aboutmenu.Append(wx.NewId(), "&About"," Information about this program") 44 | edititem1 = editmenu.Append(wx.NewId(), "&Read", "") 45 | edititem2 = editmenu.Append(wx.NewId(), "&Erase", "") 46 | edititem3 = editmenu.Append(wx.NewId(), "&Program", "") 47 | 48 | menubar.Append(filemenu, "File") 49 | menubar.Append(editmenu, "Edit") 50 | menubar.Append(aboutmenu, "?") 51 | 52 | self.SetMenuBar(menubar) 53 | self.Bind(wx.EVT_MENU, self.OnAbout, aboutitem) 54 | self.Bind(wx.EVT_MENU, self.OnExit, exititem) 55 | self.Bind(wx.EVT_MENU, self.OnRead, edititem1) 56 | self.Bind(wx.EVT_MENU, self.OnErase, edititem2) 57 | self.Bind(wx.EVT_MENU, self.OnProgram, edititem3) 58 | 59 | #End menubar 60 | 61 | #imageFile = "write.png" 62 | #imageFile2 = "read.png" 63 | #imageFile3 = "erase.png" 64 | #imageFile4 = "info.png" 65 | 66 | #imageWrite = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 67 | #imageRead = wx.Image(imageFile2, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 68 | #imageErase = wx.Image(imageFile3, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 69 | #imageInfo = wx.Image(imageFile4, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 70 | 71 | font3 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 72 | label6 = wx.StaticText(panel, -1, "Memory Operations", (30, 180)) 73 | label6.SetFont(font3) 74 | 75 | self.buttonProgram = wx.Button(panel, id=-1, label="Upload", pos = (50, 220), size = (65, 40)) 76 | self.buttonRead = wx.Button(panel, id=-1, label="Read", pos = (50+65, 220), size = (65, 40)) 77 | self.buttonErase = wx.Button(panel, id=-1, label="Erase",pos = (50, 260), size = (65, 40)) 78 | self.buttonInfo = wx.Button(panel, id=-1, label="Infos", pos = (50+65, 260), size = (65, 40)) 79 | 80 | self.textarea = wx.TextCtrl(panel, pos=(240, 10), style=wx.TE_MULTILINE | wx.TE_READONLY, size=(450,265)) 81 | 82 | 83 | font1 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 84 | label1 = wx.StaticText(panel, -1, "Programmer Setup", (30, 10)) 85 | label1.SetFont(font1) 86 | 87 | label2 = wx.StaticText(panel, -1, "Flash Ref.: ", (10, 47)) 88 | chip = ['AM29F010', 'AM29F040'] 89 | self.flashref = wx.TextCtrl(panel, -1, pos=(85, 40), size=(100, -1), style=wx.TE_READONLY) 90 | 91 | label3 = wx.StaticText(panel, -1, "Baude Rate: ", (10, 78)) 92 | baude = ['115200', '57600', '38400', '28800', '19200', '14400', '9600', '4800'] 93 | self.baudBox = wx.ComboBox(panel, -1, pos=(85, 73), size=(100, -1), choices=baude, style=wx.CB_READONLY) 94 | 95 | label4 = wx.StaticText(panel, -1, "Game File: ", (10, 110)) 96 | self.uploadText = wx.TextCtrl(panel, -1, pos=(85, 105), size=(100, -1), style = wx.TE_READONLY) 97 | buttonDlg = wx.Button(panel, id=-1, label='...', pos = (185, 105), size = (40,25)) 98 | 99 | label5 = wx.StaticText(panel, -1, "Serial port: ", (10, 140)) 100 | arduinoSerial = ['ttyACM0', 'ttyACM1', 'ttyACM2', 'ttyACM3','ttyACM4'] 101 | self.serialBox = wx.ComboBox(panel, -1, pos=(85, 135), size=(100, -1), choices=arduinoSerial, style=wx.CB_READONLY) 102 | 103 | self.ln = wx.StaticLine(panel, -1, pos=(20, 170), size=(200, -1), style=wx.LI_HORIZONTAL) 104 | 105 | gaugeText= wx.StaticText(panel, -1, "Transfer status: ", (240, 283)) 106 | self.gauge = wx.Gauge(panel, -1, 100, pos=(240, 300), size=(450, 25)) 107 | 108 | 109 | font6 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 110 | label6 = wx.StaticText(panel, -1, "Memory infos", (730, 10)) 111 | label6.SetFont(font6) 112 | 113 | label7 = wx.StaticText(panel, -1, "Man ID: ", (710, 45)) 114 | self.manid = wx.TextCtrl(panel, -1, pos=(770, 40), size=(120, -1), style = wx.TE_READONLY) 115 | 116 | label8 = wx.StaticText(panel, -1, "Dev ID: ", (710, 70)) 117 | self.devid = wx.TextCtrl(panel, -1, pos=(770, 70), size=(120, -1), style = wx.TE_READONLY) 118 | 119 | self.ln = wx.StaticLine(panel, -1, pos=(700, 110), size=(200, -1), style=wx.LI_HORIZONTAL) 120 | 121 | self.Bind(wx.EVT_BUTTON, self.OnProgram, self.buttonProgram) 122 | self.Bind(wx.EVT_BUTTON, self.OnDlg, buttonDlg) 123 | self.Bind(wx.EVT_BUTTON, self.OnRead, self.buttonRead) 124 | self.Bind(wx.EVT_BUTTON, self.OnErase, self.buttonErase) 125 | self.Bind(wx.EVT_BUTTON, self.OnInfos, self.buttonInfo) 126 | self.Bind(wx.EVT_CLOSE, self.OnExit) 127 | 128 | self.intro = 'ARDUINO AMD FLASH MEMORY PROGRAMMER - XXX29F0XX Series\n@Version: 1.0\n@Arduino ver: UNO\n@Author: Radouane SAMIR - SamCreation 2013\n\nPlease connect your programmer, select the serial port, choose the baud rate and press one of the operations\n\nThe programmed baudrate in this version is 115200\n\n' 129 | self.intro = self.intro.upper() 130 | self.textarea.SetValue(self.intro); 131 | 132 | self.count = 0 133 | 134 | def file_size_mb(filePath): 135 | return os.path.getsize(filePath) 136 | 137 | def setButtonDisable(self): 138 | self.buttonProgram.Disable() 139 | self.buttonRead.Disable() 140 | self.buttonInfo.Disable() 141 | self.buttonErase.Disable() 142 | 143 | def setButtonEnable(self): 144 | self.buttonProgram.Enable() 145 | self.buttonRead.Enable() 146 | self.buttonInfo.Enable() 147 | self.buttonErase.Enable() 148 | 149 | def setStatusText(self, string): 150 | self.SetStatusText(string) 151 | 152 | def OnDlg(self, event): 153 | dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.*", wx.OPEN) 154 | if dlg.ShowModal() == wx.ID_OK: 155 | path = dlg.GetPath() 156 | mypath = os.path.basename(path) 157 | self.uploadText.SetValue(path) 158 | self.SetStatusText("You selected: %s" % mypath) 159 | dlg.Destroy() 160 | 161 | def OnExit(self, event): 162 | self.Destroy() 163 | #self.count += 1 164 | #self.gauge.SetValue(self.count) 165 | #self.SetStatusText(str(self.count) + "% Done") 166 | 167 | def OnAbout(self,event): 168 | # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets. 169 | dlg = wx.MessageDialog( self, " AMD Flash Memory Programmer.\n Ver 0.1\n Copyright 2013 - Radouane SAMIR.", " AMD Flash Programmer", wx.OK) 170 | dlg.ShowModal() # Show it 171 | dlg.Destroy() # finally destroy it when finished. 172 | 173 | def OnRead(self, event): 174 | 175 | self.gauge.SetValue(0) 176 | 177 | self.percent = 0 178 | port = "/dev/" + str(self.serialBox.GetValue()) 179 | baudrate = str(self.baudBox.GetValue()) 180 | 181 | #serial = 0 182 | 183 | car = '' 184 | self.textarea.SetValue(self.intro) 185 | 186 | if (str(self.serialBox.GetValue()) != '' and baudrate != ''): 187 | line = 1 188 | car = self.textarea.GetValue() 189 | count = 0 190 | counter = 0 191 | val = '' 192 | total = 0x1FF / 100 #0x1FF in arduino code 193 | i = 0 194 | linecount = 0 195 | 196 | try: 197 | arduino = serial.Serial(port, int(float(baudrate)), timeout = 1) 198 | except: 199 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check serial ports !!!", "Communication Problem", wx.OK) 200 | dlg.ShowModal() 201 | dlg.Destroy() 202 | return 203 | 204 | time.sleep(2) 205 | 206 | self.SetStatusText("Please wait ...") 207 | 208 | car = car + str(struct.pack(">I", linecount).encode('hex')) + " " 209 | car = car.upper() 210 | 211 | arduino.write("R") 212 | while(1): 213 | val = arduino.read() 214 | car = car + val 215 | 216 | count += 1 217 | 218 | if (count==2): 219 | #self.textarea.SetValue(" "), 220 | car = car + " " 221 | count = 0 222 | 223 | if (line != 32): 224 | line += 1 225 | else: 226 | car = car + '\n' 227 | line = 1 228 | linecount += 1 229 | car = car + str(struct.pack(">I", linecount).encode('hex')) + " " 230 | car = car.upper() 231 | 232 | if (val == '\n'): 233 | break 234 | 235 | self.percent = round(i / total) 236 | i += 1 237 | 238 | arduino.close() 239 | 240 | while (counter <= 99): 241 | counter += 1 242 | self.gauge.SetValue(counter) 243 | self.SetStatusText(str(counter) + "% Done") 244 | 245 | self.textarea.SetValue(car) 246 | 247 | else: 248 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check the fileds", "Incorrect values", wx.OK) 249 | dlg.ShowModal() 250 | dlg.Destroy() 251 | #self.textarea.SetValue(car) 252 | 253 | def OnErase(self, event): 254 | counter = 0 255 | port = "/dev/" + str(self.serialBox.GetValue()) 256 | baudrate = str(self.baudBox.GetValue()) 257 | 258 | if (str(self.serialBox.GetValue()) != '' and baudrate != ''): 259 | #self.textarea.SetValue('') 260 | port = "/dev/" + str(self.serialBox.GetValue()) 261 | baudrate = str(self.baudBox.GetValue()) 262 | #serial = 0 263 | 264 | percent = 0 265 | 266 | try: 267 | arduino = serial.Serial(port, int(float(baudrate)), timeout = 1) 268 | except: 269 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check serial ports", "Communication Problem", wx.OK) 270 | dlg.ShowModal() 271 | dlg.Destroy() 272 | return 273 | 274 | time.sleep(2) 275 | 276 | self.SetStatusText("Please wait ...") 277 | 278 | 279 | arduino.write("E") 280 | response = '' 281 | while(1): 282 | car = arduino.read() 283 | response += car 284 | if (car == '\n'): 285 | break 286 | 287 | while (counter <= 99): 288 | counter += 1 289 | self.gauge.SetValue(counter) 290 | self.SetStatusText(str(counter) + "% Done") 291 | 292 | dlg = wx.MessageDialog(self, "Flash memory %s" %response, "Erasure Operation", wx.OK) 293 | dlg.ShowModal() 294 | dlg.Destroy() 295 | 296 | arduino.close() 297 | else: 298 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check the fields", "Incorrect values", wx.OK) 299 | dlg.ShowModal() 300 | dlg.Destroy() 301 | 302 | 303 | def OnProgram(self, event): 304 | ######################################################################## 305 | # The following functions are destined to program the memory chip 306 | # Should be included in function to be organizedreflexion 307 | # Mind the logic of the algorithm 308 | ######################################################################## 309 | 310 | gameSize = 0 311 | 312 | #Open Serial port and wait arduino to reset 313 | port = "/dev/" + str(self.serialBox.GetValue()) 314 | baudrate = str(self.baudBox.GetValue()) 315 | 316 | try: 317 | arduino = serial.Serial(port, int(float(baudrate)), timeout = 1) 318 | except: 319 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check serial ports", "Communication Problem", wx.OK) 320 | dlg.ShowModal() 321 | dlg.Destroy() 322 | return 323 | 324 | self.SetStatusText("Please wait ...") 325 | time.sleep(2) 326 | 327 | #Get Game size and send it to Arduino 328 | path = self.uploadText.GetValue() 329 | 330 | if (path != ''): 331 | 332 | gameSize = os.path.getsize(path) 333 | 334 | #Send begin command to Arduino and 335 | #Wait OK from Arduino to begin programming 336 | #Set Arduino in programming mode and wait for its response 337 | 338 | arduino.write('W') 339 | while (arduino.read() != '+'): 340 | pass 341 | 342 | arduino.write(str(gameSize)) 343 | 344 | while (arduino.read() != '+'): 345 | pass 346 | 347 | game = open(self.uploadText.GetValue(), 'r') 348 | 349 | total = gameSize / 100 350 | percent = 0 351 | 352 | #progressFrame = progressBar(parent = None, id = -1) 353 | #progressFrame.Show() 354 | #thread.start_new_thread(self.OnNewUpdate, (gameSize, game, total, arduino,self,)) 355 | self.OnNewUpdate(gameSize, game, total, arduino, self,) 356 | else: 357 | dlg = wx.MessageDialog(self, "Gameboy ROM file is missing", "ROM File", wx.OK) 358 | dlg.ShowModal() 359 | dlg.Destroy() 360 | 361 | def OnInfos(self, event): 362 | #Get Device ID - First 363 | #Get Manufacturer ID - Second 364 | 365 | #Start Device ID Operation 366 | self.gauge.SetValue(0) 367 | 368 | car = '' 369 | count = '' 370 | counter = 0 371 | baudrate = 0 372 | port = '' 373 | 374 | man = '' 375 | ref ='' 376 | 377 | self.gauge.SetValue(0) 378 | self.devid.SetValue("") 379 | self.manid.SetValue("") 380 | 381 | if (str(self.serialBox.GetValue()) != '' and baudrate != ''): 382 | self.SetStatusText("Please wait ...") 383 | 384 | self.percent = 0 385 | port = "/dev/" + str(self.serialBox.GetValue()) 386 | baudrate = str(self.baudBox.GetValue()) 387 | 388 | percent = 0 389 | 390 | try: 391 | arduino = serial.Serial(port, int(float(baudrate)), timeout = 1) 392 | except: 393 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check serial ports", "Communication Problem", wx.OK) 394 | dlg.ShowModal() 395 | dlg.Destroy() 396 | return 397 | 398 | time.sleep(2) 399 | 400 | response1 = '0x' 401 | response2 = '0x' 402 | 403 | arduino.write("D") 404 | while (1): 405 | car = arduino.read() 406 | 407 | if (car != '\n' and car != '\r'): 408 | response1 += car 409 | ref += car 410 | 411 | if (car == '\n' or car == '\r'): 412 | break 413 | 414 | #Just to complete the DevID field# 415 | if (ref == "0"): 416 | response1 += "0" 417 | 418 | self.devid.SetValue(response1) 419 | arduino.close() 420 | 421 | #Get Manufacturer - Start second operation 422 | car = '' 423 | count = '' 424 | counter = 0 425 | baudrate = 0 426 | port = '' 427 | 428 | 429 | if (str(self.serialBox.GetValue()) != '' and baudrate != ''): 430 | self.SetStatusText("Please wait ...") 431 | 432 | self.percent = 0 433 | port = "/dev/" + str(self.serialBox.GetValue()) 434 | baudrate = str(self.baudBox.GetValue()) 435 | 436 | percent = 0 437 | arduino = serial.Serial(port, int(float(baudrate)), timeout = 1) 438 | time.sleep(2) 439 | 440 | response2 = '0x' 441 | 442 | arduino.write("I") 443 | while (1): 444 | car = arduino.read() 445 | if (car == '\n' or car == '\r'): 446 | break 447 | 448 | if (car != '\n' and car != '\r'): 449 | response2 += car 450 | man += car 451 | 452 | 453 | 454 | while (counter <= 99): 455 | counter += 1 456 | self.gauge.SetValue(counter) 457 | self.SetStatusText(str(counter) + "% Done") 458 | 459 | self.manid.SetValue(response2) 460 | 461 | arduino.close() 462 | 463 | if (man == '01'): 464 | self.flashref.SetValue("AMD ") 465 | if (man == '37'): 466 | self.flashref.SetValue("AMIC ") 467 | if (man != '37' and man != '01'): 468 | self.flashref.SetValue("No chip found") 469 | 470 | if (ref == '20'): 471 | self.flashref.SetValue(self.flashref.GetValue() + "AM29F010B") 472 | if (ref == 'A4'): 473 | self.flashref.SetValue(self.flashref.GetValue() + "AM29F040B") 474 | if (ref == '86'): 475 | self.flashref.SetValue(self.flashref.GetValue() + "A29040B") 476 | 477 | 478 | else: 479 | dlg = wx.MessageDialog(self, "Please check the fields", "Incorrect values", wx.OK) 480 | dlg.ShowModal() 481 | dlg.Destroy() 482 | 483 | #Code recently added this code is for a new progress bar 484 | #The old one bugged sometimes, so I have to change its code 485 | 486 | def OnNewUpdate(self, gameSize, gamepath, total, arduinoport, mainFrame): 487 | pulse_dlg = wx.ProgressDialog(title="Upload Command", message="Uploading, Please wait ...", maximum=gameSize) 488 | 489 | ''' Old Code ''' 490 | #Some stuff happens 491 | #self.progressBar.SetRange(gameSize) 492 | ''' End Code ''' 493 | 494 | mainFrame.setButtonDisable() 495 | car = '' 496 | 497 | for x in range(0, gameSize): 498 | car = gamepath.read(1) 499 | arduinoport.write(car) 500 | 501 | ''' Some Old Code ''' 502 | #time.sleep(0.006) 503 | #self.progressBar.SetValue(x) 504 | #self.Refresh() 505 | #wx.MilliSleep(1) 506 | ''' End Code ''' 507 | 508 | pulse_dlg.Update(x) 509 | 510 | #self.SetStatusText("Uploading is almost finished ... ") 511 | #time.sleep(2) 512 | self.SetStatusText("Upload completed.") 513 | 514 | mainFrame.setButtonEnable() 515 | arduinoport.close() 516 | gamepath.close() 517 | pulse_dlg.Destroy() 518 | 519 | dlg = wx.MessageDialog(self, "Upload completed", "Information", wx.OK) 520 | dlg.ShowModal() 521 | dlg.Destroy() 522 | 523 | return 524 | 525 | class progressBar(wx.Frame): 526 | def __init__(self, parent, id): 527 | self.window = wx.Frame.__init__(self, parent, id,'ProgressBar', size=(360, 90), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX ^ wx.MINIMIZE_BOX) 528 | status = self.CreateStatusBar() 529 | panel = wx.Panel(self, pos = (0, 0), size = (100, 300)) 530 | self.progressBar = wx.Gauge(panel, -1, 0, pos=(30, 20), size=(300, 30)) 531 | self.SetStatusText("Uploading is in progress, Please wait ") 532 | self.Bind(wx.EVT_CLOSE, self.OnClose) 533 | 534 | def update(self, gameSize, gamepath, total, arduinoport, mainFrame): 535 | self.progressBar.SetRange(gameSize) 536 | mainFrame.setButtonDisable() 537 | car = '' 538 | 539 | for x in range(0, gameSize): 540 | car = gamepath.read(1) 541 | arduinoport.write(car) 542 | #time.sleep(0.006) 543 | 544 | self.progressBar.SetValue(x) 545 | self.Refresh() 546 | 547 | self.SetStatusText("Uploading is almost finished ... ") 548 | time.sleep(2) 549 | self.SetStatusText("Uploading complete.") 550 | 551 | mainFrame.setButtonEnable() 552 | arduinoport.close() 553 | gamepath.close() 554 | self.Destroy() 555 | return 556 | 557 | def OnClose(self, evt): 558 | return 559 | 560 | class starter(threading.Thread): 561 | def __init__(self, threadID, name, counter): 562 | threading.Thread.__init__(self) 563 | frame = programmer_gui(parent = None, id = -1) 564 | frame.Show() 565 | def run(self): 566 | pass 567 | 568 | if __name__ == '__main__': 569 | app = wx.PySimpleApp() 570 | # Create new threads 571 | thread1 = starter(1, "Thread-1", 1) 572 | 573 | # Start new Threads 574 | thread1.start() 575 | app.MainLoop() 576 | 577 | -------------------------------------------------------------------------------- /GUI_python3/FlashMemoryProgrammer_GUI.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # @Author of this software: Warber0x. 5 | # @Date: 26/12/2021 6 | # @Version: 1.0 Beta 7 | # @Baud rate: Check the arduino Sketch 8 | 9 | # THIS NEEDS A WXPYTHON TO BE EXECUTED. 10 | # Systel used Kali 2020 11 | # Python version 3 12 | 13 | # This is the latest version that's compatible with python 3 14 | 15 | import wx 16 | import os 17 | import sys 18 | import time 19 | import serial 20 | import struct 21 | import _thread 22 | import threading 23 | import binascii 24 | import ctypes 25 | import time 26 | 27 | from wx.lib.buttons import GenBitmapTextButton 28 | from pubsub import pub 29 | 30 | 31 | class programmer_gui(wx.Frame): 32 | gauge_counter = 0 33 | def __init__(self, parent, id): 34 | 35 | wx.Frame.__init__( 36 | self, 37 | parent, 38 | id, 39 | 'FMPUNO (Flash Memory Programmer UNO) - By Warber0x (github)' 40 | , 41 | size=(900, 450), 42 | style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER 43 | ^ wx.MAXIMIZE_BOX ^ wx.MINIMIZE_BOX, 44 | ) 45 | 46 | panel = wx.Panel(self, pos=(0, 100), size=(700, 200)) 47 | self.percent = 0 48 | 49 | img = wx.Image('./avr.png') 50 | img.Rescale(170, 170) 51 | png = wx.Bitmap(img) 52 | wx.StaticBitmap(panel, -1, png, (713, 170), (png.GetWidth(), 53 | png.GetHeight())) 54 | 55 | # Menu Gui 56 | 57 | status = self.CreateStatusBar() 58 | 59 | menubar = wx.MenuBar() 60 | filemenu = wx.Menu() 61 | editmenu = wx.Menu() 62 | aboutmenu = wx.Menu() 63 | 64 | exititem = filemenu.Append(wx.NewIdRef(), '&Exit', '') 65 | aboutitem = aboutmenu.Append(wx.NewIdRef(), '&About',' Information about this program') 66 | edititem1 = editmenu.Append(wx.NewIdRef(), '&Read', '') 67 | edititem2 = editmenu.Append(wx.NewIdRef(), '&Erase', '') 68 | edititem3 = editmenu.Append(wx.NewIdRef(), '&Program', '') 69 | 70 | menubar.Append(filemenu, 'File') 71 | menubar.Append(editmenu, 'Edit') 72 | menubar.Append(aboutmenu, '?') 73 | 74 | self.SetMenuBar(menubar) 75 | self.Bind(wx.EVT_MENU, self.OnAbout, aboutitem) 76 | self.Bind(wx.EVT_MENU, self.OnExit, exititem) 77 | self.Bind(wx.EVT_MENU, self.OnRead, edititem1) 78 | self.Bind(wx.EVT_MENU, self.OnErase, edititem2) 79 | self.Bind(wx.EVT_MENU, self.OnProgram, edititem3) 80 | 81 | # End menubar 82 | 83 | # imageFile = "write.png" 84 | # imageFile2 = "read.png" 85 | # imageFile3 = "erase.png" 86 | # imageFile4 = "info.png" 87 | 88 | # imageWrite = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 89 | # imageRead = wx.Image(imageFile2, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 90 | # imageErase = wx.Image(imageFile3, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 91 | # imageInfo = wx.Image(imageFile4, wx.BITMAP_TYPE_ANY).ConvertToBitmap() 92 | 93 | font3 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 94 | label6 = wx.StaticText(panel, -1, 'IC Operations:', (10, 200), size=(200, -1)) 95 | label6.SetFont(font3) 96 | 97 | self.buttonProgram = wx.Button(panel, id=-1, label='Upload', pos=(50, 240), size=(65, 40)) 98 | self.buttonRead = wx.Button(panel, id=-1, label='Read', pos=(50 + 65, 240), size=(65, 40)) 99 | self.buttonErase = wx.Button(panel, id=-1, label='Erase',pos=(50, 280), size=(65, 40)) 100 | self.buttonInfo = wx.Button(panel, id=-1, label='Infos', pos=(50 + 65, 280), size=(65, 40)) 101 | 102 | self.textarea = wx.TextCtrl(panel, pos=(240, 10), style=wx.TE_MULTILINE | wx.TE_READONLY, size=(450, 265)) 103 | 104 | font1 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 105 | label1 = wx.StaticText(panel, -1, 'File to Upload', (10, 10), size=(200, -1)) 106 | label1.SetFont(font1) 107 | 108 | label4 = wx.StaticText(panel, -1, 'Game File: ', (10, 40)) 109 | self.uploadText = wx.TextCtrl(panel, -1, pos=(85, 40), size=(100, -1), style=wx.TE_READONLY) 110 | buttonDlg = wx.Button(panel, id=-1, label='...', pos=(185,40), size=(40, 30)) 111 | 112 | self.ln = wx.StaticLine(panel, -1, pos=(20, 80), size=(200,-1), style=wx.LI_HORIZONTAL) 113 | 114 | font1 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 115 | label1 = wx.StaticText(panel, -1, 'Parameters:', (10, 90), size=(200, -1)) 116 | label1.SetFont(font1) 117 | 118 | label3 = wx.StaticText(panel, -1, 'Baude Rate: ', (10, 120), size=(200, -1)) 119 | baude = [ 120 | '115200', 121 | '57600', 122 | '38400', 123 | '28800', 124 | '19200', 125 | '14400', 126 | '9600', 127 | '4800', 128 | ] 129 | self.baudBox = wx.ComboBox(panel,-1,pos=(100, 120),size=(100, -1),choices=baude,style=wx.CB_READONLY,) 130 | 131 | label5 = wx.StaticText(panel, -1, 'Serial port: ', (10, 150), size=(200, -1)) 132 | arduinoSerial = ['ttyACM0', 'ttyACM1', 'ttyACM2', 'ttyACM3', 'ttyACM4'] 133 | self.serialBox = wx.ComboBox(panel,-1,pos=(100, 150),size=(100, -1),choices=arduinoSerial,style=wx.CB_READONLY,) 134 | 135 | self.ln = wx.StaticLine(panel, -1, pos=(20, 190), size=(200, 1), style=wx.LI_HORIZONTAL) 136 | 137 | gaugeText = wx.StaticText(panel, -1, 'Progress %: ', (240, 283)) 138 | self.gauge = wx.Gauge(panel, -1, 100, pos=(240, 300), size=(450, 25)) 139 | 140 | # create a pubsub listener 141 | pub.subscribe(self.updateProgress, "update") 142 | 143 | font6 = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD) 144 | label6 = wx.StaticText(panel, -1, 'IC Info', (710, 10), size=(200, -1)) 145 | label6.SetFont(font6) 146 | 147 | label7 = wx.StaticText(panel, -1, 'Man ID: ', (710, 45)) 148 | self.manid = wx.TextCtrl(panel, -1, pos=(770, 45), size=(120, 149 | -1), style=wx.TE_READONLY) 150 | 151 | label8 = wx.StaticText(panel, -1, 'Dev ID: ', (710, 80)) 152 | self.devid = wx.TextCtrl(panel, -1, pos=(770, 80), size=(120, 153 | -1), style=wx.TE_READONLY) 154 | 155 | label2 = wx.StaticText(panel, -1, 'Brand : ', (710, 115)) 156 | chip = ['AM29F010', 'AM29F040'] 157 | self.flashref = wx.TextCtrl(panel, -1, pos=(770, 115), size=(120, 158 | -1), style=wx.TE_READONLY) 159 | 160 | self.ln = wx.StaticLine(panel, -1, pos=(700, 150), size=(200, 161 | -1), style=wx.LI_HORIZONTAL) 162 | 163 | self.Bind(wx.EVT_BUTTON, self.OnProgram, self.buttonProgram) 164 | self.Bind(wx.EVT_BUTTON, self.OnDlg, buttonDlg) 165 | self.Bind(wx.EVT_BUTTON, self.OnRead, self.buttonRead) 166 | self.Bind(wx.EVT_BUTTON, self.OnErase, self.buttonErase) 167 | self.Bind(wx.EVT_BUTTON, self.OnInfos, self.buttonInfo) 168 | self.Bind(wx.EVT_CLOSE, self.OnExit) 169 | 170 | self.intro = \ 171 | '''ARDUINO AMD FLASH MEMORY PROGRAMMER - XXX29F0XX Series 172 | @Version: 1.0 173 | @Arduino ver: UNO 174 | @Python 3.9.1+ 175 | @Author: https://github.com/warber0x 176 | 177 | Please connect your programmer, select the serial port, choose the baud rate and press one of the operations 178 | 179 | The programmed baudrate in this version is 115200 (Recommended) 180 | 181 | ''' 182 | self.intro = self.intro.upper() 183 | self.textarea.SetValue(self.intro) 184 | 185 | self.count = 0 186 | 187 | # # # # # # # # # # # # # # # # # # # # # # # # 188 | 189 | def file_size_mb(filePath): 190 | return os.path.getsize(filePath) 191 | 192 | # # # # # # # # # # # # # # # # # # # # # # # # # 193 | 194 | def setButtonDisable(self): 195 | self.buttonProgram.Disable() 196 | self.buttonRead.Disable() 197 | self.buttonInfo.Disable() 198 | self.buttonErase.Disable() 199 | 200 | # # # # # # # # # # # # # # # # # # # # # # # # # 201 | 202 | def setButtonEnable(self): 203 | self.buttonProgram.Enable() 204 | self.buttonRead.Enable() 205 | self.buttonInfo.Enable() 206 | self.buttonErase.Enable() 207 | 208 | # # # # # # # # # # # # # # # # # # # # # # # # # 209 | 210 | def setStatusText(self, string): 211 | self.SetStatusText(string) 212 | 213 | # # # # # # # # # # # # # # # # # # # # # # # # # 214 | 215 | def OnDlg(self, event): 216 | dlg = wx.FileDialog( 217 | self, 218 | 'Choose a file', 219 | os.getcwd(), 220 | '', 221 | '*.*', 222 | wx.FD_OPEN, 223 | ) 224 | if dlg.ShowModal() == wx.ID_OK: 225 | path = dlg.GetPath() 226 | mypath = os.path.basename(path) 227 | self.uploadText.SetValue(path) 228 | self.SetStatusText('You selected: %s' % mypath) 229 | else: 230 | self.uploadText.SetValue("") 231 | self.SetStatusText("") 232 | 233 | dlg.Destroy() 234 | 235 | # # # # # # # # # # # # # # # # # # # # # # # # 236 | 237 | def OnExit(self, event): 238 | self.Destroy() 239 | 240 | # self.count += 1 241 | # self.gauge.SetValue(self.count) 242 | # self.SetStatusText(str(self.count) + "% Done") 243 | 244 | # # # # # # # # # # # # # # # # # # # # # # # # 245 | 246 | def OnAbout(self, event): 247 | 248 | # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets. 249 | 250 | dlg = wx.MessageDialog(self, 251 | ''' AMD Flash Memory Programmer. 252 | Ver 0.1 253 | Copyright 2013 - Warber0x (github).''', 254 | ' AMD Flash Programmer', wx.OK) 255 | dlg.ShowModal() # Show it 256 | dlg.Destroy() # finally destroy it when finished. 257 | 258 | # # # # # # # # # # # # # # # # # # # # # # # # 259 | 260 | def OnRead(self, event): 261 | 262 | self.gauge.SetValue(0) 263 | self.gauge_counter = 0 264 | t1 = GaugeThread() 265 | 266 | self.percent = 0 267 | port = '/dev/' + str(self.serialBox.GetValue()) 268 | baudrate = str(self.baudBox.GetValue()) 269 | 270 | # serial = 0 271 | 272 | car = '' 273 | self.textarea.SetValue(self.intro) 274 | 275 | if str(self.serialBox.GetValue()) != '' and baudrate != '': 276 | line = 1 277 | temp_intro = self.textarea.GetValue() 278 | count = 0 279 | counter = 0 280 | val = '' 281 | total = 0x1FF / 100 # 0x1FF in arduino code 282 | i = 0 283 | linecount = 0 284 | 285 | try: 286 | arduino = serial.Serial(port, int(float(baudrate)), 287 | timeout=1) 288 | except: 289 | dlg = wx.MessageDialog(self, 290 | "Can't communicate with Arduino, please check serial ports !!!" 291 | , 'Communication Problem', wx.OK) 292 | dlg.ShowModal() 293 | dlg.Destroy() 294 | return 295 | 296 | time.sleep(2) 297 | 298 | self.SetStatusText('Please wait ...') 299 | 300 | car = car + str("%02d" % linecount) + '\t\t' 301 | car = car.upper() 302 | 303 | command = 'R' 304 | arduino.write(command.encode()) 305 | 306 | time.sleep(.001) # delay of 1ms 307 | val = arduino.readline() # read complete line from serial output 308 | self.SetStatusText('Reading the memory chip ...') 309 | while not '\\n'in str(val): 310 | time.sleep(.001) # delay of 1ms 311 | temp = arduino.readline() # check for serial output. 312 | if not not temp.decode(): # if temp is not empty. 313 | val = (val.decode()+temp.decode()).encode() 314 | # requrired to decode, sum, then encode because 315 | # long values might require multiple passes 316 | val = val.decode() # decoding from bytes 317 | val = val.strip() # stripping leading and trailing spaces. 318 | 319 | 320 | for value in str(val): 321 | car = car + value 322 | count += 1 323 | if count == 2: 324 | car = car + ' ' 325 | count = 0 326 | 327 | if line != 32: 328 | line += 1 329 | else: 330 | car = car + '\n' 331 | line = 1 332 | linecount += 1 333 | car = car + str("%02d" % linecount) + '\t\t' 334 | car = car.upper() 335 | 336 | self.percent = round(i / total) 337 | i += 1 338 | 339 | car += '\n\n' + str(temp_intro) 340 | car = car.upper() 341 | 342 | '''while 1: 343 | # val = arduino.read() 344 | 345 | if str(val) in '\\n': 346 | break 347 | 348 | car = car + val 349 | 350 | count += 1 351 | 352 | if count == 2: 353 | 354 | # self.textarea.SetValue(" "), 355 | 356 | car = car + ' ' 357 | count = 0 358 | 359 | if line != 32: 360 | line += 1 361 | else: 362 | car = car + '\n' 363 | line = 1 364 | linecount += 1 365 | car = car + str(struct.pack('>I',linecount)) + ' ' 366 | car = car.upper() 367 | 368 | self.percent = round(i / total) 369 | i += 1''' 370 | 371 | 372 | self.textarea.SetValue(car) 373 | self.SetStatusText('Operation Completed Successfully.') 374 | dlg = wx.MessageDialog(self, 'Operation Completed', 'IC read', wx.OK) 375 | arduino.close() 376 | else: 377 | 378 | dlg = wx.MessageDialog(self, 379 | "Can't communicate with Arduino, please check the fileds" 380 | , 'Incorrect values', wx.OK) 381 | dlg.ShowModal() 382 | dlg.Destroy() 383 | 384 | # self.textarea.SetValue(car) 385 | t1.raise_exception() 386 | t1.join() 387 | 388 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 389 | 390 | def OnErase(self, event): 391 | counter = 0 392 | port = '/dev/' + str(self.serialBox.GetValue()) 393 | baudrate = str(self.baudBox.GetValue()) 394 | 395 | if str(self.serialBox.GetValue()) != '' and baudrate != '': 396 | 397 | # self.textarea.SetValue('') 398 | 399 | port = '/dev/' + str(self.serialBox.GetValue()) 400 | baudrate = str(self.baudBox.GetValue()) 401 | 402 | # serial = 0 403 | 404 | percent = 0 405 | 406 | try: 407 | arduino = serial.Serial(port, int(float(baudrate)), 408 | timeout=1) 409 | except: 410 | dlg = wx.MessageDialog(self, 411 | "Can't communicate with Arduino, please check serial ports" 412 | , 'Communication Problem', wx.OK) 413 | dlg.ShowModal() 414 | dlg.Destroy() 415 | return 416 | 417 | time.sleep(2) 418 | 419 | self.SetStatusText('Erasing, Please wait ...') 420 | 421 | command = "E" 422 | arduino.write(command.encode()) 423 | response = '' 424 | time.sleep(.001) # delay of 1ms 425 | val = arduino.readline() # read complete line from serial output 426 | 427 | while not '\\n'in str(val): 428 | time.sleep(.001) # delay of 1ms 429 | temp = arduino.readline() # check for serial output. 430 | if not not temp.decode(): # if temp is not empty. 431 | val = (val.decode()+temp.decode()).encode() 432 | # requrired to decode, sum, then encode because 433 | # long values might require multiple passes 434 | val = val.decode() # decoding from bytes 435 | val = val.strip() # stripping leading and trailing spaces. 436 | 437 | response = val 438 | self.SetStatusText('Operation Completed Successfully.') 439 | dlg = wx.MessageDialog(self, 'Flash memory %s' % response, 'IC Erase', wx.OK) 440 | dlg.ShowModal() 441 | dlg.Destroy() 442 | 443 | arduino.close() 444 | 445 | else: 446 | dlg = wx.MessageDialog(self, "Can't communicate with Arduino, please check the fields" , 'Incorrect values', wx.OK) 447 | dlg.ShowModal() 448 | dlg.Destroy() 449 | 450 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 451 | 452 | def OnProgram(self, event): 453 | 454 | # ####################################################################### 455 | # The following functions are destined to program the memory chip 456 | # Should be included in function to be organizedreflexion 457 | # Mind the logic of the algorithm 458 | # ####################################################################### 459 | 460 | gameSize = 0 461 | game = '' 462 | 463 | # Open Serial port and wait arduino to reset 464 | 465 | port = '/dev/' + str(self.serialBox.GetValue()) 466 | baudrate = str(self.baudBox.GetValue()) 467 | 468 | try: 469 | arduino = serial.Serial(port, int(float(baudrate)), 470 | timeout=1) 471 | except: 472 | dlg = wx.MessageDialog(self, 473 | "Can't communicate with Arduino, please check serial ports", 'Communication Problem', wx.OK) 474 | dlg.ShowModal() 475 | dlg.Destroy() 476 | return 477 | 478 | self.SetStatusText('Please wait ...') 479 | time.sleep(2) 480 | 481 | # Get Game size and send it to Arduino 482 | 483 | path = self.uploadText.GetValue() 484 | 485 | if path != '': 486 | self.SetStatusText('Getting file path ...') 487 | gameSize = os.path.getsize(path) 488 | 489 | # Send begin command to Arduino and 490 | # Wait OK from Arduino to begin programming 491 | # Set Arduino in programming mode and wait for its response 492 | 493 | command = 'W' 494 | arduino.write(command.encode()) 495 | 496 | val = arduino.read() # read complete line from serial output 497 | if '+' in str(val): 498 | self.SetStatusText('Uploading ... ') 499 | else: 500 | self.SetStatusText('Error Uploading ...') 501 | return 502 | 503 | arduino.write(str(gameSize).encode()) 504 | 505 | val = arduino.read() # read complete line from serial output 506 | if '+' in str(val): 507 | self.SetStatusText('Uploading ... Please wait') 508 | game = open(self.uploadText.GetValue(), 'rb') 509 | total = gameSize / 100 510 | percent = 0 511 | else: 512 | self.SetStatusText('Error Uploading ... Maybe the Arduino') 513 | return 514 | 515 | # progressFrame = progressBar(parent = None, id = -1) 516 | # progressFrame.Show() 517 | # thread.start_new_thread(self.OnNewUpdate, (gameSize, game, total, arduino,self,)) 518 | 519 | self.OnNewUpdate(gameSize, game, total, arduino, self) 520 | else: 521 | dlg = wx.MessageDialog(self, 'Gameboy ROM file is missing', 'ROM File', wx.OK) 522 | dlg.ShowModal() 523 | dlg.Destroy() 524 | 525 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 526 | 527 | def OnInfos(self, event): 528 | 529 | # Get Device ID - First 530 | # Get Manufacturer ID - Second 531 | 532 | # Start Device ID Operation 533 | # 534 | self.gauge_counter = 0 535 | t1 = GaugeThread() 536 | 537 | car = '' 538 | count = '' 539 | counter = 0 540 | baudrate = 0 541 | port = '' 542 | 543 | man = '' 544 | ref = '' 545 | 546 | self.gauge.SetValue(0) 547 | self.devid.SetValue('') 548 | self.manid.SetValue('') 549 | self.flashref.SetValue('') 550 | 551 | if str(self.serialBox.GetValue()) != '' and baudrate != '': 552 | self.SetStatusText('Please wait ... ') 553 | 554 | self.percent = 0 555 | port = '/dev/' + str(self.serialBox.GetValue()) 556 | baudrate = str(self.baudBox.GetValue()) 557 | 558 | percent = 0 559 | 560 | try: 561 | arduino = serial.Serial(port, int(float(baudrate)), 562 | timeout=1) 563 | except: 564 | dlg = wx.MessageDialog(self, 565 | "Can't communicate with Arduino, please check serial ports" 566 | , 'Communication Problem', wx.OK) 567 | dlg.ShowModal() 568 | dlg.Destroy() 569 | return 570 | 571 | time.sleep(2) 572 | 573 | response1 = '0x' 574 | response2 = '0x' 575 | 576 | command = "D" 577 | arduino.write(command.encode()) 578 | 579 | time.sleep(.001) # delay of 1ms 580 | val = arduino.readline() # read complete line from serial output 581 | self.SetStatusText('Getting Device ID ...') 582 | while not '\\n'in str(val): 583 | time.sleep(.001) # delay of 1ms 584 | temp = arduino.readline() # check for serial output. 585 | if not not temp.decode(): # if temp is not empty. 586 | val = (val.decode()+temp.decode()).encode() 587 | # requrired to decode, sum, then encode because 588 | # long values might require multiple passes 589 | val = val.decode() # decoding from bytes 590 | val = val.strip() # stripping leading and trailing spaces. 591 | response1 = response1 + val 592 | ref = ref + val 593 | 594 | # Just to complete the DevID field# 595 | 596 | if ref == '0': 597 | response1 += '0' 598 | 599 | # self.devid.SetValue(response1) 600 | arduino.close() 601 | 602 | # Get Manufacturer - Start second operation 603 | ## # # # # # # # # # # # # # # # # # # # # # # # 604 | car = '' 605 | count = '' 606 | counter = 0 607 | baudrate = 0 608 | port = '' 609 | 610 | if str(self.serialBox.GetValue()) != '' and baudrate != '': 611 | self.SetStatusText('Please wait ...') 612 | 613 | self.percent = 0 614 | port = '/dev/' + str(self.serialBox.GetValue()) 615 | baudrate = str(self.baudBox.GetValue()) 616 | 617 | percent = 0 618 | arduino = serial.Serial(port, int(float(baudrate)), 619 | timeout=1) 620 | time.sleep(2) 621 | 622 | response2 = '0x' 623 | 624 | command = "I" 625 | arduino.write(command.encode()) 626 | 627 | time.sleep(.001) # delay of 1ms 628 | val = arduino.readline() # read complete line from serial output 629 | self.SetStatusText('Getting Manufacturer ID...') 630 | while not '\\n' in str(val): 631 | time.sleep(.001) # delay of 1ms 632 | temp = arduino.readline() # check for serial output. 633 | if not not temp.decode(): # if temp is not empty. 634 | val = (val.decode()+temp.decode()).encode() 635 | # requrired to decode, sum, then encode because 636 | # long values might require multiple passes 637 | val = val.decode() # decoding from bytes 638 | val = val.strip() # stripping leading and trailing spaces. 639 | response2 = response2 + val 640 | man = man + val 641 | 642 | self.devid.SetValue(response1) 643 | self.manid.SetValue(response2) 644 | 645 | if man == '01': 646 | self.flashref.SetValue('AMD ') 647 | if man == '37': 648 | self.flashref.SetValue('AMIC ') 649 | if man != '37' and man != '01': 650 | self.flashref.SetValue('No chip found') 651 | 652 | if ref == '20': 653 | self.flashref.SetValue(self.flashref.GetValue() 654 | + 'AM29F010B') 655 | if ref == 'A4': 656 | self.flashref.SetValue(self.flashref.GetValue() 657 | + 'AM29F040B') 658 | if ref == '86': 659 | self.flashref.SetValue(self.flashref.GetValue() 660 | + 'A29040B') 661 | 662 | self.SetStatusText('Operation Completed Successfully.') 663 | arduino.close() 664 | else: 665 | 666 | dlg = wx.MessageDialog(self, 'Please check the fields', 'Incorrect values', wx.OK) 667 | dlg.ShowModal() 668 | dlg.Destroy() 669 | 670 | t1.raise_exception() 671 | t1.join() 672 | 673 | # Code recently added this code is for a new progress bar 674 | # The old one had bugs sometimes, so I have to change its code 675 | 676 | def OnNewUpdate( 677 | self, 678 | gameSize, 679 | gamepath, 680 | total, 681 | arduinoport, 682 | mainFrame, 683 | ): 684 | pulse_dlg = wx.ProgressDialog(title='Upload Command', message='Uploading, Keep arduino connected ...', maximum=gameSize) 685 | 686 | # Some stuff happens 687 | # self.progressBar.SetRange(gameSize) 688 | 689 | mainFrame.setButtonDisable() 690 | car = '' 691 | 692 | for x in range(0, gameSize): 693 | car = gamepath.read(1) 694 | arduinoport.write(car) 695 | 696 | # time.sleep(0.006) 697 | # self.progressBar.SetValue(x) 698 | # self.Refresh() 699 | # wx.MilliSleep(1) 700 | 701 | pulse_dlg.Update(x) 702 | 703 | # self.SetStatusText("Uploading is almost finished ... ") 704 | # time.sleep(2) 705 | 706 | self.SetStatusText('Upload completed.') 707 | 708 | mainFrame.setButtonEnable() 709 | arduinoport.close() 710 | gamepath.close() 711 | pulse_dlg.Destroy() 712 | 713 | dlg = wx.MessageDialog(self, 'Upload completed', 'IC writing', wx.OK) 714 | dlg.ShowModal() 715 | dlg.Destroy() 716 | 717 | return 718 | 719 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 720 | 721 | def updateProgress(self, msg): 722 | self.gauge_counter += 50 723 | 724 | self.gauge.SetValue(self.gauge_counter) 725 | self.gauge.Refresh() 726 | 727 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 728 | 729 | class progressBar(wx.Frame): 730 | 731 | def __init__(self, parent, id): 732 | self.window = wx.Frame.__init__( 733 | self, 734 | parent, 735 | id, 736 | 'ProgressBar', 737 | size=(360, 90), 738 | style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER 739 | ^ wx.MAXIMIZE_BOX ^ wx.MINIMIZE_BOX, 740 | ) 741 | status = self.CreateStatusBar() 742 | panel = wx.Panel(self, pos=(0, 0), size=(100, 300)) 743 | self.progressBar = wx.Gauge(panel, -1, 0, pos=(30, 20), 744 | size=(300, 30)) 745 | self.SetStatusText('Uploading is in progress, Please wait ') 746 | self.Bind(wx.EVT_CLOSE, self.OnClose) 747 | 748 | def update( 749 | self, 750 | gameSize, 751 | gamepath, 752 | total, 753 | arduinoport, 754 | mainFrame, 755 | ): 756 | self.progressBar.SetRange(gameSize) 757 | mainFrame.setButtonDisable() 758 | car = '' 759 | 760 | for x in range(0, gameSize): 761 | car = gamepath.read(1) 762 | arduinoport.write(car) 763 | 764 | # time.sleep(0.006) 765 | 766 | self.progressBar.SetValue(x) 767 | self.Refresh() 768 | 769 | self.SetStatusText('Uploading is almost finished ... ') 770 | time.sleep(2) 771 | self.SetStatusText('Uploading complete.') 772 | 773 | mainFrame.setButtonEnable() 774 | arduinoport.close() 775 | gamepath.close() 776 | self.Destroy() 777 | return 778 | 779 | def OnClose(self, evt): 780 | return 781 | 782 | # # # # # # # # # # # # # # # # # # # # # # # # # # 783 | 784 | class GaugeThread(threading.Thread): 785 | """Test Worker Thread Class.""" 786 | 787 | #---------------------------------------------------------------------- 788 | def __init__(self): 789 | """Init Worker Thread Class.""" 790 | threading.Thread.__init__(self) 791 | self.start() # start the thread 792 | 793 | #---------------------------------------------------------------------- 794 | def run(self): 795 | """Run Worker Thread.""" 796 | # This is the code executing in the new thread. 797 | for i in range(2): 798 | wx.CallAfter(pub.sendMessage, "update", msg="update") 799 | 800 | 801 | def get_id(self): 802 | 803 | # returns id of the respective thread 804 | if hasattr(self, '_thread_id'): 805 | return self._thread_id 806 | for id, thread in threading._active.items(): 807 | if thread is self: 808 | return id 809 | 810 | def raise_exception(self): 811 | thread_id = self.get_id() 812 | res = ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 813 | ctypes.py_object(SystemExit)) 814 | if res > 1: 815 | ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0) 816 | print('Exception raise failure') 817 | 818 | # # # # # # # # # # # # # # # # # # # # # # # # # # 819 | 820 | class OperationsThread(threading.Thread): 821 | 822 | def __init__(self, target, *args): 823 | self._target = target 824 | threading.Thread.__init__(self) 825 | 826 | def run(self): 827 | self._target() 828 | 829 | # # # # # # # # # # # # # # # # # # # # # # # # # # 830 | 831 | class starter(threading.Thread): 832 | 833 | def __init__( 834 | self, 835 | threadID, 836 | name, 837 | counter, 838 | ): 839 | threading.Thread.__init__(self) 840 | frame = programmer_gui(parent=None, id=-1) 841 | frame.Show() 842 | 843 | def run(self): 844 | pass 845 | 846 | 847 | if __name__ == '__main__': 848 | app = wx.App(False) 849 | 850 | # Create new threads 851 | 852 | thread1 = starter(1, 'Thread-1', 1) 853 | # Start new Threads 854 | 855 | thread1.start() 856 | app.MainLoop() 857 | --------------------------------------------------------------------------------