Draft
fix: correct CH32X035 RX_RES bit positions and shared control register handling#1
Conversation
- ch32_usbfs_reg.h: Fix USBFS_EP_R_RES_* values from (x<<0) to (x<<2) to match USBFS_EP_R_RES_MASK at bits [3:2] for CH32X035 - dcd_ch32_usbfs.c: Add #if defined(CH32X035) guards throughout driver to handle the shared TX/RX control register in CH32X035: - dcd_init: combine TX+RX writes for EP0 and EP1-7 initialization - update_in: preserve RX bits when updating TX for EP0 - update_out: preserve TX bits when setting RX=ACK for EP0 - dcd_int_handler: fix SETUP and BUS_RST EP0 register writes - dcd_edpt0_status_complete: combine TX+RX writes - dcd_edpt_open: use read-modify-write to preserve other direction - dcd_edpt_stall/clear_stall: use read-modify-write for EP0 Agent-Logs-Url: https://github.com/21km43/Adafruit_TinyUSB_Arduino/sessions/5141344a-6785-407d-8fca-757e32bbc9c4 Co-authored-by: 21km43 <48169975+21km43@users.noreply.github.com>
…omment - Extract repeated read-modify-write patterns into CH32X035_PRESERVE_TX_BITS and CH32X035_PRESERVE_RX_BITS helper macros - Use EP_RX_CTRL in PRESERVE_RX_BITS for semantic clarity - Clarify AUTO_TOG comment in ch32_usbfs_reg.h to document shared-bit behavior Agent-Logs-Url: https://github.com/21km43/Adafruit_TinyUSB_Arduino/sessions/5141344a-6785-407d-8fca-757e32bbc9c4 Co-authored-by: 21km43 <48169975+21km43@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
PR adafruit#486 (adafruit/Adafruit_TinyUSB_Arduino) のコードレビューで特定されたバグを修正します。
修正内容
Bug 1:
USBFS_EP_R_RES_*のビット位置不整合 (ch32_usbfs_reg.h)CH32X035 向けの RX 応答値が
(x << 0)で定義されていたが、マスクUSBFS_EP_R_RES_MASKは(3 << 2)(ビット [3:2])を使用しており不整合。Bug 2: EP_TX_CTRL / EP_RX_CTRL が同一アドレスを指す (
dcd_ch32_usbfs.c)CH32X035 では TX と RX が同一の 8 ビットレジスタを共有する:
従来コードは
EP_TX_CTRL(ep) = valの後にEP_RX_CTRL(ep) = valを書くと前の値が上書きされるため、初期化で TX 設定が失われていた。修正方法:
CH32X035_PRESERVE_TX_BITS(ep)/CH32X035_PRESERVE_RX_BITS(ep)を追加#if defined(CH32X035)ガードを追加し、read-modify-write または結合書き込みを使用影響箇所:
dcd_init: EP0・EP1-7 の初期化update_in,update_out: EP0 制御中の CTRL 書き込みdcd_int_handler: SETUP/BUS_RST 割り込みハンドラdcd_edpt0_status_complete,dcd_edpt_open,dcd_edpt_stall,dcd_edpt_clear_stall関連