Skip to content

daplink_flash: Add DAPLink Flash driver for I2C bridge to W25Q64JV.#164

Merged
nedseb merged 10 commits intomainfrom
feat/daplink-flash-driver
Mar 16, 2026
Merged

daplink_flash: Add DAPLink Flash driver for I2C bridge to W25Q64JV.#164
nedseb merged 10 commits intomainfrom
feat/daplink-flash-driver

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 16, 2026

Summary

  • Rename lib/w2564jv/ to lib/daplink_flash/ (the flash is accessed via I2C bridge, not SPI directly)
  • Implement DaplinkFlash MicroPython driver for the STM32F103 DAPLink flash bridge
  • Support write (append to file) and read (sector-based) operations
  • Add 13 mock tests + 5 hardware test scenarios
  • Add 4 usage examples, all validated on hardware
  • Update README with correct API documentation

Architecture

The STM32WB55 (MicroPython) communicates with the STM32F103 (DAPLink) at I2C address 0x3B (7-bit). The F103 bridges to the W25Q64JV SPI flash (64 Mbit).

STM32WB55 --I2C--> STM32F103 (DAPLink) --SPI--> W25Q64JV
  (MicroPython)       (0x3B)                     (64 Mbit flash)

I2C Protocol

Command Code Description
WHO_AM_I 0x01 Device ID -> 0x4C
SET_FILENAME 0x03 Set 8.3 filename (11 bytes)
GET_FILENAME 0x04 Read current filename
CLEAR_FLASH 0x10 Erase entire flash
WRITE_DATA 0x11 Append data (30-byte chunks)
READ_SECTOR 0x20 Read 256-byte sector (requires firmware fix, see #165)
STATUS_REG 0x80 Busy flag (bit 7)
ERROR_REG 0x81 Error flags

API

from daplink_flash import DaplinkFlash

i2c = machine.I2C(1)
flash = DaplinkFlash(i2c)

flash.device_id()                    # -> 0x4C
flash.set_filename("DATA", "CSV")
flash.write_line("temperature;humidity")
flash.write_line("25.3;48.2")
flash.clear_flash()

# Read (requires DAPLink firmware fix #165)
data = flash.read_sector(0)          # 256 bytes
content = flash.read()               # full file as bytes

Examples

Example Description
flash_info.py Display bridge status, error register, current filename
write_csv.py Write CSV data and read it back
read_file.py Read and display current file on flash
sensor_log.py Write 200 rows of sensor data, read back, compute min/avg/max

Hardware test results

WHO_AM_I: 0x4C
set_filename / get_filename round-trip OK
write_line -> file visible on USB mass storage OK
read_sector -> content matches written data OK
sensor_log: 200 rows written (4 KB), 170 parsed back with statistics OK

DAPLink firmware dependency

The READ_SECTOR command has two bugs in the upstream DAPLink firmware (argument length mismatch + hardcoded read address). A fix is submitted in steamicc/DAPLink#1, tracked in #165.

Write operations work without any firmware modification.

Test plan

  • ruff check passes
  • 13 mock tests pass (no regression on other drivers)
  • Hardware: device_id() returns 0x4C
  • Hardware: set_filename() / get_filename() round-trip
  • Hardware: Write file, verify via USB mass storage
  • Hardware: Read back file content matches written data
  • Hardware: 200-row sensor log write + read + statistics

Closes #5
Closes #38

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01482f9dd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4266e042a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2466e6381e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d71cc0e784

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e722f69c51

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b44452f49a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/daplink_flash/daplink_flash/device.py
@nedseb nedseb merged commit 43f0a58 into main Mar 16, 2026
3 checks passed
nedseb added a commit that referenced this pull request Mar 16, 2026
@nedseb nedseb deleted the feat/daplink-flash-driver branch March 16, 2026 14:49
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: Add test scenario for DAPLink Flash driver. daplink_flash: Add DAPLink Flash driver (I2C bridge to W25Q64JV).

1 participant