cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
436 stars 43 forks source link

Download Error using minichlink <-> CH32V003 B/D #20

Closed arondr70 closed 11 months ago

arondr70 commented 1 year ago

I've been struggling for a week. It's a very basic question, but help me~~ It's blocked here, so it's not moving any further.

*Question : The rv003usb bootloader has been saved to CH32V003 using WCH-LinkE/minichlink. But the below error occurs when the CH32V003(WCH Evolution Board) is then plugged into USB and downloaded using minichlink. What's the problem?

../../ch32v003fun/../minichlink/minichlink -w blink.bin flash -b Found B003Fun Bootloader Halting Boot Countdown Error: Timed out waiting for stub to complete Could not setup interface.

*Note: Downloading using busbflash in testblink example is normal.

HD: 0x55c1acc1a2a0 Read 40 bytes Send feature report: 128 Read: 129 Readback Confirm

[Test environment]

cnlohr commented 1 year ago

Wow... I don't know what the problem is. I wonder if there's some pending update to minichlink that was not pushed. I can investigate more tonight.

arondr70 commented 1 year ago

Thank you very much for your reply. If you upload a prebuilt image (bootloader, minichlink) to git to validate the error, I think it will help a lot for a beginner who approaches for the first time like me. Thank you in advance^^

arondr70 commented 1 year ago
arondr70 commented 1 year ago

I tested it using two CH32V003 boards, two WCH Links, two computers, and many USB cables, but all of them get the same error. Therefore, it is not a hardware issue.

../../minichlink/minichlink -w blink.bin flash -b Found B003Fun Bootloader Halting Boot Countdown Error: Timed out waiting for stub to complete Could not setup interface. make: *** [../../ch32v003fun/ch32v003fun.mk:66: cv_flash] 오류 223

arondr70 commented 1 year ago

After looking at the pgm-b003fun.c source file in the minichlink folder, it is an error message caused by the timeout of the "CommitOp" function during the setup process of the function below. As a result of solving and executing a well-made debugging comment (#define DEBUG_B003), it was confirmed that both the data sent and received were normal.

The normal transmission and reception is also understood as the normal operation of the existing busbflash.c and testtop.c examples.

static int B003FunSetupInterface( void dev ) { struct B003FunProgrammerStruct eps = (struct B003FunProgrammerStruct*) dev; printf( "Halting Boot Countdown\n" ); ResetOp( eps ); WriteOpArb( eps, halt_wait_blob, sizeof(halt_wait_blob) ); if( CommitOp( eps ) ) return -5; // <----------- timeout error point return 0; }

../../minichlink/minichlink -w blink.bin flash -b Found B003Fun Bootloader Halting Boot Countdown Commit TX: 128 bytes aa 00 00 00 81 46 94 c1 fd 56 14 c1 82 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cd ab 34 12

hid_send_feature_report = 128 Commit RX: 128 bytes aa 00 00 00 81 46 94 c1 fd 56 14 c1 82 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 cd ab 34 12

arondr70 commented 1 year ago

It is normal only when the if statement in the "CommitOp" function is satisfied and broken, but it seems that the error occurs because it is timed out.

If the assembly command in the "halt_wait_blob" array is executed, the if statement should be satisfied, but after debugging by adding the GPIO code to the bootloader, the if statement below has not entered. I don't understand the whole thing, but the e->count++ above the if statement looks weird. I only ++ once outside for loop, is this normal? If you enter here, the runwordpad changes in the main function, so the code "halt_wait_blob" will be executed, but this seems to be a problem.

// minichlink/pgm-b003fun.c source static int CommitOp( struct B003FunProgrammerStruct * eps ) { ..... if( eps->respbuffer[1] == 0xff ) break; .... }

// li a3, 0; sw a3, 0(a1); li a3, -1; sw a3, 0(a0); ret; static const unsigned char halt_wait_blob[] = { 0x81, 0x46, 0x94, 0xc1, 0xfd, 0x56, 0x14, 0xc1, 0x82, 0x80 };

// bootloader.c source for( i = 0; i < l; i++ ) start[i] = data[i];//((intptr_t)data)>>(i*8); e->count ++; // <---- I doubt it's an error

if( e->count >= SCRATCHPAD_SIZE ) { // <----- Failed to enter

arondr70 commented 11 months ago

I solved it. I modified one line of the source code below to confirm that it works normally with minichlink, downloaded to flash and run.

[bootloader.c -- line 264] if( e->count >= SCRATCHPAD_SIZE ) ==> if( e->count >= (SCRATCHPAD_SIZE>>3) )