Skip to main content
Topic: BusPirate hangs in SPI sniffer mode. (Read 21928 times) previous topic - next topic

Re: BusPirate hangs in SPI sniffer mode.

Reply #30
Quote
but I believe the Baud rate only really affects comms at the far end - i.e. the BP processor <--> FTDI.

Sleepwalker3, it sounds right...

Re: BusPirate hangs in SPI sniffer mode.

Reply #31
I have done a very simple test to reproduce the problem: I have programmed an arduino as SPI source and I have done a few tests with different bytes per seccond. The arduino code is:

Code: [Select]
/*Simple SPI test 
  Pinout:
  GND  to ground
  CS  to digital pin 10
  MOSI  to digital pin 11
  CLK  to digital pin 13
*/

#include <SPI.h>

const int CSPin = 10;

void setup() {
  // set the CSPin as an output:
  pinMode (CSPin, OUTPUT);
  // configure SPI:
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE3);
  SPI.begin();
  digitalWrite(CSPin,LOW);
}

void loop() {
  SPI.transfer(0xFF);
  delayMicroseconds(200);
}

I have seen that with 400us in the delayMicroseconds function the BP works fine, but with 200 us the BP hangs the same way it does with the circuit im trying to sniff.

Re: BusPirate hangs in SPI sniffer mode.

Reply #32
OK, managed to dive into the source (never had to deal with SPI sniffer before) and have some insight on the problem, here it goes:
- Dived into the source code for actual sniffer. If you suspect that BP cannot keep up, try using the sniffer from the terminal. It gives out a warning, "Couldn't keep up", if there is an overflow.
- In binary mode (and terminal mode) the mode led turning off means there is a buffer overflow aka sniffed signal too fast.
- There is a circular buffer inside BP for things like this but it can overflow too.
- BPv3 uses the FTDI IC so there is a bottleneck between uC and FTDI interface which is UART at 115200 bps. I'm thinking the calculations are about right, but you cannot be precise.

In conclusion the reason for the hangs seems to be the buffer overflow. The reason for that is you SPI traffic picks up and we cannot send it fast enough through the FTDI and to the PC. And you mentioned that you cannot change the speed of the traffic and there is no faster baudrate (115200) on the menu. However, it may be possible to have a faster baudrate set up in the code (sorry you have to deal with that) that can fix your problem.

Or you have to have a specific hardware for transferring SPI to your PC. BP is like a Swiss Army Knife, you can use the screwdriver on it but using a real screwdriver is faster. :)

Re: BusPirate hangs in SPI sniffer mode.

Reply #33
That's awesome work Tayken, thanks for the great insight, very informative. Obviously I was wrong (and kind of a little right) about the bottleneck being between the BP PIC and the FTDI. Not sure about the FTDI on the BP, but I think most of them are capable of going up to around 1M Baud rate and I think many have small buffers which perhaps haven't been pressed into service. If the PIC is capable of the throughput, then as you suggest, there may be a way of increasing the throughput by increasing the baud rate.

I imagine the BP V4 would be better in this respect, as far as throughput goes, so that might be an option for Juanma too.

Re: BusPirate hangs in SPI sniffer mode.

Reply #34
SOLVED!! Thanks tayken and SleepWalker3!

Actually the limitation was in the UART speed between PIC and FTDI, that is by default 115200bps. I dont know why is 115200 the default speed in code and not higher speed while both pic and ftdi supports higher baudrate.

Anyway, what I have done is modify the baudrate manually through terminal menu option 'b' to 'BRG raw value' (I didnt know it could be done) with a value of 8, what means a baudrate around 460800bps. Then I have run my python script and the BP doesnt hang.

After that I have rewritten the script to modify the baudrate automatically at the beginning.

By other hand, I have take a look inside the firmware source and I have seen that the different baudrates are set in baseIO.c:

Code: [Select]
static unsigned int UARTspeed[] = {13332, 3332, 1666, 832, 416, 207, 103, 68, 34,}; //BRG:300,1200,2400,4800,9600,19200,38400,57600,115200

and the default index is set to 8 in main.c what means a baudrate of 115200bps:

Code: [Select]
   bpConfig.termSpeed = 8; //default PC side port speed, startup in 115200, or saved state (later)....

I havent read all the source code and I dont have any ideahow to compilethe firmware, but It seemsto be very easy to modify the baudrate to higher values even its possible to set BRG to 0 what means highest baudrate. Maybe If people finds it useful it could be changed in future firmware versions.

Thanks to every body!

Re: BusPirate hangs in SPI sniffer mode.

Reply #35
[quote author="juanma"]Actually the limitation was in the UART speed between PIC and FTDI, that is by default 115200bps. I dont know why is 115200 the default speed in code and not higher speed while both pic and ftdi supports higher baudrate. [/quote]
Well, BP was developed as a device that is controlled by a user. 115200 was enough at the time and it is pretty standard with similar devices. Binary mode and scripting works fairly well with the same baudrate so there was no need to change it.

[quote author="juanma"]Anyway, what I have done is modify the baudrate manually through terminal menu option 'b' to 'BRG raw value' (I didnt know it could be done) with a value of 8, what means a baudrate around 460800bps. Then I have run my python script and the BP doesnt hang.[/quote]
Yes, there is a raw value entry but I wasn't sure if it supported higher baudrate. Sometimes you have to edit a prescaler and from time to time that is not implemented in the code. :)

[quote author="juanma"]I havent read all the source code and I dont have any ideahow to compilethe firmware, but It seemsto be very easy to modify the baudrate to higher values even its possible to set BRG to 0 what means highest baudrate. Maybe If people finds it useful it could be changed in future firmware versions.[/quote]
Baudrate entry from the terminal is possible, so it is not really best to change the source. But not sure if implemented in binary mode. BRG = 0 means something like 4Mbps which may not be possible for FTDI to handle.

Re: BusPirate hangs in SPI sniffer mode.

Reply #36
[quote author="tayken"]Baudrate entry from the terminal is possible, so it is not really best to change the source. But not sure if implemented in binary mode.[/quote]

No, it is not possible to change baudrate from binary mode. What my script does is:

- Change BP baudrate in terminal mode through the 'b' option in the main menu.
- Reconfigure the baudrate of the com port used by the script to match the new BP speed.
- Enter the binary mode.
- Enter SPI function, configure SPI and sniff.

Re: BusPirate hangs in SPI sniffer mode.

Reply #37
That's what I guessed. I think we can use one of the unused binary mode keys for configuring it. You'll have to send the key first, then BRG. I'll start working on that and let's see if others like it.

Re: BusPirate hangs in SPI sniffer mode.

Reply #38
Thanks tayken.

Re: BusPirate hangs in SPI sniffer mode.

Reply #39
@juanma, @tayken
 
Thank you both, you saved my day!
I have learned something new I don't knew before.
 
@tayken
 
Kinda OT.
I know this isn't the right place, but I understand you want do changes in the firmware.
So I have noted another trunk message while performing b command:
 
Bus Pirate v3.5
Firmware v6.3-beta1 r2151 Bootloader v4.4
DEVID:0x0447 REVID:0x3046 (24FJ64GA002 B8)
http://dangerousprototypes.com
HiZ>
 
Enter raw value for BRG
 
(34)>8
Adjust your terminal
Space to conti
 
so pressing spacebar I get:
 
(34)>8
Adjust your terminal
Space to contiHiZ>
 
I guess "Space to conti" of course it mean "Space to continue".
Apologizing me for the OT, thanks in advance.
 
Kindest regards,
sre71

Re: BusPirate hangs in SPI sniffer mode.

Reply #40
Hi guys,

I have just bought a BP to snif a SPI connection with the target chip allowing a maximum SPI frequency of 10 MHz. So from the description the BP should work perfectly fine in sniffer mode.
Anyways, when I use the binary sniffing tool it just stops working after a couple of bytes (around 20). The mode led turns off in that case. If I try it manually using a serial terminal, I get around 6-7 bytes followed by continuous lines "Couldn't keep up", mode LED staying on.

I have been reading this forum and trying everything I could find including increasing the baud rate to 960... baud (register value 3). The beaviour stays the same, though, and I just cannot get it to work.

Something I notived using my oscilloscope was, that on the board they are trying to "obscure" the data by inserting invalid clock pulses etc while the CS line is inactive. Maybe that has something to to with it..

Would be cool if anybode here could give me some hints to try :)

Thanks for your kind help,
Tobi

Re: BusPirate hangs in SPI sniffer mode.

Reply #41
If it is giving you some invalid clocks, you may try to use some logic IC for getting clock and data when CS line is active. If it's active high, an AND gate will work. Just a though.