{"id":26483345,"url":"https://github.com/julianvilas/hackpyratebus","last_synced_at":"2025-03-20T04:54:45.925Z","repository":{"id":241400234,"uuid":"806749439","full_name":"julianvilas/hackPyrateBus","owner":"julianvilas","description":"Python library that provides high-level functions to interact with specific integrated circuits using the Bus Pirate","archived":false,"fork":false,"pushed_at":"2024-07-12T10:26:55.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-02T17:18:21.318Z","etag":null,"topics":["buspirate","hardware-hacking"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/julianvilas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-27T20:26:32.000Z","updated_at":"2024-07-30T14:05:38.000Z","dependencies_parsed_at":"2024-07-10T17:54:09.146Z","dependency_job_id":null,"html_url":"https://github.com/julianvilas/hackPyrateBus","commit_stats":null,"previous_names":["julianvilas/bphelpers","julianvilas/hackpyratebus"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julianvilas%2FhackPyrateBus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julianvilas%2FhackPyrateBus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julianvilas%2FhackPyrateBus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julianvilas%2FhackPyrateBus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/julianvilas","download_url":"https://codeload.github.com/julianvilas/hackPyrateBus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554070,"owners_count":20471173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buspirate","hardware-hacking"],"created_at":"2025-03-20T04:54:45.376Z","updated_at":"2025-03-20T04:54:45.912Z","avatar_url":"https://github.com/julianvilas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hackPyrateBus\n\n`hackPyrateBus` is a Python library that provides high-level functions to interact with specific integrated circuits using the [Bus Pirate](http://dangerousprototypes.com/docs/Bus_Pirate).\nThis library takes into account the particularities of the integrated circuits it interacts with.\n\nThis project is built on top of [pyBusPirateLite](https://github.com/juhasch/pyBusPirateLite), and we would like to give credit to the original authors and contributors of pyBusPirateLite and pyBusPirate.\n\n_NOTE: the pyBusPirateLite dependency is vendored from https://github.com/julianvilas/pyBusPirateLite/tree/new for convenience, as the original project does not seem to be maintained and it is not available in PyPI neither._\n_The `new` branch in that fork contains commits not available in the original upstream, while `master` matches exactly the upstream (as of today)._\n_[How to use the module directly](#pybuspiratelite-users)._\n\n## Installation\n\nFrom PyPI:\n\n```bash\nvirtualenv venv\nsource venv/bin/activate\n\npip install hackPyrateBus\n```\n\nFrom the root of the cloned repo you can install `hackPyrateBus` running:\n\n```bash\n# from the root of the cloned repo\nvirtualenv venv\nsource venv/bin/activate\n\npip install .\n```\n\nDirectly From GitHub Releases:\n\n```bash\n# from anywhere\nvirtualenv venv\nsource venv/bin/activate\n\n# latest release\nurl=$(curl --silent \"https://api.github.com/repos/julianvilas/hackPyrateBus/releases/latest\" | jq -r .assets[0].browser_download_url)\npip install --upgrade $url\n```\n\n## Usage\n\n### AT24C128/256 EEPROM\n\n[Datasheet](https://ww1.microchip.com/downloads/en/devicedoc/doc0670.pdf)\n\nDevice particularities:\n\n* 16,384/32,768 bytes capacity (`AT24C128`/`AT24C256` respectively) organized as 256/512 64-bytes pages\n* Device address range [`0x50`:`0x54`] (default `0x50`), plus a LSB R/W bit (0 write, 1 read)\n* Page write mode rolls over when more than 64 bytes are written\n* Sequential read with data address auto-increment\n* Reading from a concrete data address requires a previous dummy-write\n\n#### Initialize with default values\n\n```python\nfrom hackPyrateBus.AT24CXXX import AT24CXXX\nat24c = AT24CXXX()\nat24c.speed = '50kHz'\nat24c.configure(power=True, pullup=True) # do not enable pullup when using external pullup resistors\n```\n\nDefault values:\n* Auto-detect and auto-connect to Bus Pirate port\n* 115200 bps serial communication speed with Bus Pirate\n* 1s timeout to ensure full EEPROM can be read/written in a single call\n* `256` model\n* `0x50` device address\n\n#### Read the first 15 bytes from the EEPROM\n\n```python\nat24c.load(0x0000, 15)\n```\n\n* Performs dummy-write + sequential read using [Bus Pirate Write then read I2C method](http://dangerousprototypes.com/docs/I2C_(binary)#0x08_-_Write_then_read)\n* Auto-handles reads of more than 4096 bytes (Bus Pirate buffer size)\n\n#### Store data from the 100 position of the EEPROM\n\n```python\nat24c.store(100, b'\\x00Hello, world!\\xff')\n```\n\n* Performs page write using [Bus Pirate Write then read I2C method](http://dangerousprototypes.com/docs/I2C_(binary)#0x08_-_Write_then_read)\n* Auto-handles writes of more than 64 bytes (page size) to avoid roll-over\n\n#### Reset Bus Pirate\n\n```python\nat24c.hw_reset()\n```\n\n### Winbond W25Q64FV Flash Memory\n\n[Datasheet](https://www.winbond.com/resource-files/w25q64fv%20revq%2006142016.pdf)\n\nDevice particularities:\n* Operates from 2.7V to 3.6V\n* 32,768 programmable pages of 256-bytes each\n* Up to 256 bytes can be programmed at a time. If the amount of data exceeds the size of the page it rolls over and overwrites the page from the beginning.\n* Pages can be erased in groups of 16 (4KB sector erase), groups of 128 (32KB block erase), groups of 256 (64KB block erase) or the entire chip (chip erase)\n* Supports SPI, Dual/Quad SPI and QPI\n* SPI bus operation Mode 0 (0,0) and 3 (1,1) are supported\n* Up to `104MHz` speed supported in Standard SPI for all instructions except `Read data` (`03h`) when operating at 3.0-3.6V\n* `50Mhz` Clock frequency for `Read data` when operating at 3.0-3.6V (Bus Pirate maximum SPI speed is `8Mhz`)\n\n_NOTE: the Bus Pirate SPI `write_then_read`'s read operation is slower than_\n_expected because for every call it has to return all the data to the UART. As_\n_the buffer of the Bus Pirate it is 4096 bytes there is a huge penalty when_\n_reading big amounts of the flash, as the Bus Pirate's UART works at 115200 bps._\n\n#### Initialize with default values\n\n```python\nfrom hackPyrateBus.W25Q64FV import W25Q64FV\nwinbond = W25Q64FV()\nwinbond.pins = W25Q64FV.PIN_POWER | W25Q64FV.PIN_CS\nwinbond.config = W25Q64FV.CFG_PUSH_PULL | W25Q64FV.CFG_CLK_EDGE\nwinbond.speed = '1MHz'\n```\n\nDefault values:\n* Auto-detect and auto-connect to Bus Pirate port\n* 115200 bps serial communication speed with Bus Pirate\n* 0.5 timeout to ensure full memory can be read/written in a single call\n* The Bus Pirate is using the [buzzpirat](https://buzzpirat.com/) compatible firmware. Otherwise set this param as `False`.\n\n#### Get memory info\n\n```python\nwinbond.info()\n```\n\nReturns a dictionary containing the following keys:\n\n- `manufacturer`: str\n- `device_id`: str\n- `unique_id`: str\n- `memory_type`: str\n- `capacity`: int (in bytes)\n\n#### Read the whole flash memory\n\n```python\nimg = winbond.read(0x000000, winbond.MAX_WORDS)\nwith open('flash.img', 'wb') as f:\n    f.write(img)\n\n```\n\n* Performs the sequential read using [Bus Pirate Write then read SPI method](http://dangerousprototypes.com/docs/SPI_(binary)#00000100_-_Write_then_read)\n* Auto-handles reads of more than 4096 bytes (Bus Pirate buffer size)\n\n#### Overwrite the whole flash memory\n\n```python\nwith open('flash.img', 'rb') as f:\n    winbond.store(0x000000, file.read())\n\n```\n\n* In order to write the the flash, the pages should be previously erased.\nThe `erase` method is used for that purpose\n* Automatically checks if the memory is busy and sets the Write Enable bit\n\n#### Erasing the flash memory:\n\n```python\n# erase the whole flash\nwinbond.erase(winbond.COMMAND_ERASE_CHIP, 0x000000)\n\n# erase a sector (4096 bytes)\nwinbond.erase(winbond.COMMAND_ERASE_SECTOR, 0x000000)\n\n# erase a 32KB block\nwinbond.erase(winbond.COMMAND_ERASE_ERASE_32KB, 0x000000)\n\n# erase a 64KB block\nwinbond.erase(winbond.COMMAND_ERASE_ERASE_64KB, 0x000000)\n```\n\n* To calculate the minimum pages required to be erased for writing a content use the `calculate_pages` method\n\n```python\npages = winbond.calculate_pages(0x000000, b'\\x00Hello, world!\\xff')\n```\n\n### pyBusPirateLite users\n\nAs previously mentioned `pyBusPirateLite` is vendored in this repo. To directly use that module, just import `vendor.pyBusPirateLite`.\n\nUsage example:\n\n```python\nfrom vendor.pyBusPirateLite.I2C import I2C\n```\n\n## Dependencies\n\nThis project uses the following open source packages:\n\n- [pyBusPirateLite](https://github.com/juhasch/pyBusPirateLite) (GPLv3)\n\n## License\n\n`hackPyrateBus` is licensed under the GNU General Public License v3 (GPLv3). The full text of the license can be found in the [LICENSE](LICENSE) file.\n\nThe pyBusPirateLite project, from which this project is derived, is also licensed under the GPLv3. We would like to thank the authors and contributors of pyBusPirateLite for their work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianvilas%2Fhackpyratebus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulianvilas%2Fhackpyratebus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulianvilas%2Fhackpyratebus/lists"}