From eb6b66af0f6da50c8f6b1626e560f478e9b38d56 Mon Sep 17 00:00:00 2001 From: sys64738 Date: Wed, 23 Jun 2021 17:51:56 +0000 Subject: [PATCH] Update 'USB protocol' --- USB-protocol.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/USB-protocol.md b/USB-protocol.md index 82d164e..404ecb4 100644 --- a/USB-protocol.md +++ b/USB-protocol.md @@ -73,7 +73,7 @@ The device operates in two (or three, depending on how you count) operting modes In bootloader mode, you first have to send a magic number for the device (stored in the FT240X' EEPROM) to enable some functionality: when authenticated, in bootloader mode, you can access the Spartan-3AN's internal SPI flash, as well as maybe a few extra bits. -You can switch to application mode (and back to bootloader mode) at any time, however, allegedly (this is the behavior of the [ScanaPLUS](https://sigrok.org/wiki/IKALOGIC_ScanaPLUS) device, which has a similar setup) capturing samples (in application mode) will not work when not authenticated in bootloader mode. (TODO: does switching to bootloader mode from application mode bring you into authenticated mode when already authenticated before switching to application mode?) +You can switch to application mode (and back to bootloader mode) at any time, however, allegedly (this is the behavior of the [ScanaPLUS](https://sigrok.org/wiki/IKALOGIC_ScanaPLUS) device, which has a similar setup) capturing samples (in application mode) will not work when not authenticated in bootloader mode. A log of libftd2xx function calls from ScanaStudio, in various scenarios, is available [here](https://cloud.lain.faith/s/RpcBp89MA2LDqqY). @@ -157,6 +157,8 @@ This blob is 24 bytes in size. * **`0x16`**: Capture mode flag. `0x01` in capture and mixed mode, `0x00` in generate mode. * **`0x17`**: Generate mode flag. `0x01` in generate and mixed mode, `0x00` in capture mode. +"Passive settings" (used in the "Example transfers" section) means settings that retain frequency, voltage, ..., settings, but disable triggers and reset capture/generate bytes. + __**Memory settings**__: These three fields are each 3-byte little-endian values: 1. `MS1` denotes the memory size used for storing captured signal data. @@ -222,7 +224,93 @@ field: |LVL|0 | pw_max ' |OVRL|0 | ' pw_min |IGN ### Example transfers -#### Spartan-3AN internal SPI flash read ID and status +Below is what the ScanaStudio software does. + +Abbreviations/terms used: +* `APP`: application mode variant of a command +* `BL` bootloader mode variant of a command +* `passive`: see "Settings blob". +* `SC/WFT`: signal capture/wait-for-trigger +* While a status response is technically the same byte repeated 4 byte, the byte is only listed once below. + +#### Device init/reset + +1. Send settings (`0xf1` APP) (passive) (probably spurious) +1. Cancel ongoing SC/WFT (`0xf0 0x00`) +1. Get status (`0xfd 0x00 0x01 0x02 0xfe`) + * Should return either `0x09` (device just started up) or `0x22` (already inited). +1. Switch to bootloader mode (`0x94`) +1. Read 3 magic auth bytes from FT240X EEPROM at (little-endian) word addresses 0x12 and 0x13. +1. Send the above magic auth bytes (`0xf1` BL) +1. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x01`. +1. Switch to application mode (`0x93`) +1. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +1. Send settings (`0xf1` APP) (passive) + +#### Capture a signal + +1. Cancel ongoing SC/WFT (`0xf0 0x00`) +2. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +3. Send settings (`0xf1`) (passive) (spurious?) +4. Send settings (`0xf1') +5. Send trigger steps (`0xf4`) (optional) +6. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +7. Cancel ongoing SC/WFT (`0xf0 0x00`) +8. Start SC/WFT (`0xf0 0x01`) +9. Read 4-byte response (trigger position, result) +10. Cancel ongoing SC/WFT (`0xf0 0x00`) +11. Start capture data download (`0xf0 0x06`) +12. Read capture data bytes (`MS1*2` bytes) +13. Cancel ongoing SC/WFT (`0xf0 0x00`) +14. Send settings (`0xf1`) (passive) +15. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. + +#### Generate a signal + +1. Cancel ongoing SC/WFT (`0xf0 0x00`) +2. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +3. Send settings (`0xf1`) (passive, but generator mode enabled) +4. Start generator upload pattern (`0xf0 0x05 0xf3`) +5. Send generator pattern bytes (`MS2*2` bytes) +6. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +7. Cancel ongoing SC/WFT (`0xf0 0x00`) +8. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +9. Start pattern generation, indefinitely (`0xf0 0x02`) or once (`0xf0 0x07`) +10. Send settings (`0xf1`) +11. (wait...) +12. Stop pattern generation: Cancel ongoing SC/WFT (`0xf0 0x00`) +13. Send settings (`0xf1`) (passive, but generator mode enabled) +14. Send settings (`0xf1`) (passive) +15. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. + +#### Perform a mixed-mode transaction + +1. Cancel ongoing SC/WFT (`0xf0 0x00`) +2. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +3. Send settings (`0xf1`) (passive, but capture and generator modes enabled) +4. Start generator upload pattern (`0xf0 0x05 0xf3`) +5. Send generator pattern bytes (`(MS2-MS1)*2` bytes) +6. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +7. Cancel ongoing SC/WFT (`0xf0 0x00`) +8. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +9. Send settings (`0xf1`) +10. Send trigger steps (`0xf4`) (optional) (?) +11. Cancel ongoing SC/WFT (`0xf0 0x00`) +12. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +13. Send settings (`0xf1`) +14. Send settings (`0xf1`) (spurious?) +15. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. +16. Cancel ongoing SC/WFT (`0xf0 0x00`) +17. Start mixed-mode action (`0xf0 0x03`) +18. Read 4-byte response (trigger position, result) +19. Cancel ongoing SC/WFT (`0xf0 0x00`) +20. Start capture data download (`0xf0 0x06`) +21. Read capture data bytes (`MS1*2` bytes) +22. Cancel ongoing SC/WFT (`0xf0 0x00`) +23. Send settings (`0xf1`) (passive) +24. Get status (`0xfd 0x00 0x01 0x02 0xfe`), should return `0x22`. + +#### Spartan-3AN internal SPI flash: read ID and status ``` Flash ID: @@ -238,7 +326,7 @@ Status: Send 0x91,0x00, no read data ``` -#### Spartan-3AN internal SPI flash dump +#### Spartan-3AN internal SPI flash: dump ``` Send 0x90,0x00, no read data