cswtag into stash

This commit is contained in:
R
2024-04-14 07:55:58 +01:00
parent 673d6b6eab
commit b1e2e79d5d
2 changed files with 11 additions and 4 deletions
+9 -4
View File
@@ -21,7 +21,7 @@ typedef struct USBD_descriptor {
// EP 1 IN (64 bytes) // EP 1 IN (64 bytes)
// +0x140 // +0x140
// <unused> // <unused>
// +0x1d4 // +0x1cc
// ram for stashing data // ram for stashing data
// +0x200 // +0x200
// <256-byte flash page buffer> // <256-byte flash page buffer>
@@ -160,7 +160,8 @@ extern volatile uint32_t USB_EP1_OUT[32];
extern volatile uint32_t USB_EP1_IN[32]; extern volatile uint32_t USB_EP1_IN[32];
#define USB_EP1_IN_OLDOLD(offs) (*(volatile uint32_t *)(0x400060C0 + 2 * (offs))) #define USB_EP1_IN_OLDOLD(offs) (*(volatile uint32_t *)(0x400060C0 + 2 * (offs)))
#define USB_UF2_FIELDS_STASH(offs) (*(uint32_t *)(0x400061d4 + 2 * (offs))) extern uint32_t CSWTAG_LO;
extern uint32_t CSWTAG_HI;
extern uint32_t BLOCKNUM_LO; extern uint32_t BLOCKNUM_LO;
extern uint32_t BLOCKNUM_HI; extern uint32_t BLOCKNUM_HI;
extern uint32_t TOTBLOCKS_LO; extern uint32_t TOTBLOCKS_LO;
@@ -372,7 +373,6 @@ __attribute__((naked)) int main(void) {
// bits [23:20] = sense key // bits [23:20] = sense key
// bits [7:0] = state // bits [7:0] = state
uint32_t msc_state = STATE_WANT_CBW; uint32_t msc_state = STATE_WANT_CBW;
uint32_t dCSWTag = 0;
// when reading: // when reading:
// [31:16] = current lba // [31:16] = current lba
// [15:0] = blocks left // [15:0] = blocks left
@@ -418,6 +418,7 @@ __attribute__((naked)) int main(void) {
// XXX how is this supposed to work? // XXX how is this supposed to work?
uint32_t wIndex = USB_EP0_OUT[2]; uint32_t wIndex = USB_EP0_OUT[2];
if (wIndex == 0x81) { if (wIndex == 0x81) {
uint32_t dCSWTag = CSWTAG_LO | (CSWTAG_HI << 16);
make_msc_csw(dCSWTag, 1); make_msc_csw(dCSWTag, 1);
msc_state = (msc_state & 0xffffff00) | STATE_SENT_CSW; msc_state = (msc_state & 0xffffff00) | STATE_SENT_CSW;
set_ep_mode(0, 0, USB_EPTYPE_CONTROL, USB_STAT_STALL, USB_STAT_ACK, 0, 0); set_ep_mode(0, 0, USB_EPTYPE_CONTROL, USB_STAT_STALL, USB_STAT_ACK, 0, 0);
@@ -600,7 +601,9 @@ __attribute__((naked)) int main(void) {
if ((USB_DESCS[1].count_rx & 0x3f) != 0x1f || USB_EP1_OUT[0] != 0x5355 || USB_EP1_OUT[1] != 0x4342) { if ((USB_DESCS[1].count_rx & 0x3f) != 0x1f || USB_EP1_OUT[0] != 0x5355 || USB_EP1_OUT[1] != 0x4342) {
set_ep_mode(1, 1, USB_EPTYPE_BULK, USB_STAT_ACK, USB_STAT_STALL, 0, 0); set_ep_mode(1, 1, USB_EPTYPE_BULK, USB_STAT_ACK, USB_STAT_STALL, 0, 0);
} else { } else {
dCSWTag = USB_EP1_OUT[2] | (USB_EP1_OUT[3] << 16); CSWTAG_LO = USB_EP1_OUT[2];
CSWTAG_HI = USB_EP1_OUT[3];
uint32_t dCSWTag = CSWTAG_LO | (CSWTAG_HI << 16);
uint32_t dCBWDataTransferLength = USB_EP1_OUT[4] | (USB_EP1_OUT[5] << 16); uint32_t dCBWDataTransferLength = USB_EP1_OUT[4] | (USB_EP1_OUT[5] << 16);
uint32_t bmCBWFlags = USB_EP1_OUT[6] & 0xff; uint32_t bmCBWFlags = USB_EP1_OUT[6] & 0xff;
uint32_t operation_code = USB_EP1_OUT[7] >> 8; uint32_t operation_code = USB_EP1_OUT[7] >> 8;
@@ -803,6 +806,7 @@ __attribute__((naked)) int main(void) {
uint32_t blocks_left = scsi_xfer_lba_blocks & 0xffff; uint32_t blocks_left = scsi_xfer_lba_blocks & 0xffff;
blocks_left--; blocks_left--;
if (blocks_left == 0) { if (blocks_left == 0) {
uint32_t dCSWTag = CSWTAG_LO | (CSWTAG_HI << 16);
make_msc_csw(dCSWTag, 0); make_msc_csw(dCSWTag, 0);
if (UF2_BLOCKS_LEFT == 0x8000) if (UF2_BLOCKS_LEFT == 0x8000)
msc_state = STATE_SENT_CSW_REBOOT; msc_state = STATE_SENT_CSW_REBOOT;
@@ -818,6 +822,7 @@ __attribute__((naked)) int main(void) {
} }
} else if ((ep_status & (1 << 7)) && (epidx == 1)) { } else if ((ep_status & (1 << 7)) && (epidx == 1)) {
// ep 1 in // ep 1 in
uint32_t dCSWTag = CSWTAG_LO | (CSWTAG_HI << 16);
switch (msc_state & 0xff) { switch (msc_state & 0xff) {
case STATE_SENT_CSW: case STATE_SENT_CSW:
set_ep_mode(1, 1, USB_EPTYPE_BULK, USB_STAT_ACK, USB_STAT_STALL, 0, 0); set_ep_mode(1, 1, USB_EPTYPE_BULK, USB_STAT_ACK, USB_STAT_STALL, 0, 0);
+2
View File
@@ -42,6 +42,8 @@ SECTIONS
PROVIDE( USB_EP0_IN = 0x40006030 ); PROVIDE( USB_EP0_IN = 0x40006030 );
PROVIDE( USB_EP1_OUT = 0x40006040 ); PROVIDE( USB_EP1_OUT = 0x40006040 );
PROVIDE( USB_EP1_IN = 0x400060c0 ); PROVIDE( USB_EP1_IN = 0x400060c0 );
PROVIDE( CSWTAG_LO = 0x400061cc );
PROVIDE( CSWTAG_HI = 0x400061d0 );
PROVIDE( BLOCKNUM_LO = 0x400061d4 ); PROVIDE( BLOCKNUM_LO = 0x400061d4 );
PROVIDE( BLOCKNUM_HI = 0x400061d8 ); PROVIDE( BLOCKNUM_HI = 0x400061d8 );
PROVIDE( TOTBLOCKS_LO = 0x400061dc ); PROVIDE( TOTBLOCKS_LO = 0x400061dc );