wokwi / rp2040js

A Raspberry Pi Pico Emulator in JavaScript
MIT License
400 stars 44 forks source link

test(PIO):improving `SET PINS` test to be unaffected by other pins #65

Closed Turro75 closed 3 years ago

Turro75 commented 3 years ago

the set pins requires the result and-ed to avoid the other pins status

Turro75 commented 3 years ago

as alternative the DBG_PADOUT can be reset by writing 0 to PINS with a MOV instruction, I don't know if DBG_PADOUT is affected by GPIO status, anyway for testing purpose seems not important.

 async function resetStateMachines() {

    await cpu.writeUint32(CTRL, 0xf0);
    await cpu.writeUint32(SM0_INSTR, pioJMP(PIO_COND_ALWAYS, 0)); // Jump machine 0 to address 0

    // Clear FIFOs
    await cpu.writeUint32(SM0_SHIFTCTRL, FJOIN_RX);  
    await cpu.writeUint32(SM0_SHIFTCTRL, 0);

    //reset Pins/DBG_PADOUT
    await cpu.writeUint32(SM0_INSTR, pioSET(PIO_DEST_X, 0));
    await cpu.writeUint32(SM0_INSTR, pioMOV(PIO_DEST_PINS, PIO_OP_NONE, PIO_SRC_X)); 
  }
urish commented 3 years ago

Thank you Valerio!

I don't know if DBG_PADOUT is affected by GPIO status, anyway for testing purpose seems not important.

The datasheet says: "Read to sample the pad output values PIO is currently driving to the GPIOs.", so as I understand it it's only affected by PIO and not by any external peripherals.

In any case, both methods are fine, I don't have any strong preference for one over the other.

Turro75 commented 3 years ago

In any case, both methods are fine, I don't have any strong preference for one over the other.

me neither, both work. a little bit better the reworked test as it's more generic and allows the testing of any combination of SET PINS while the other way uses instructions to test instructions, but who cares it's a test and now it passes.

urish commented 3 years ago

Thanks!