FPC: got RX working, got client over usart somehow working..., see detailed commit msg

* using WITH_FPC:
  * activate basic usart
  * no double buffer for now, no interrupt
  * usart_dataavailable/usart_readbuffer/usart_writebuffer, to demo it:
    * pm3 client over USB, minicom over usart
    * analyse a d 414243
* using WITH_FPC_HOST:
  * it implies WITH_FPC as it's based on it
  * control pm3 with client over usart
  * EXPERIMENTAL! still some frame desync issues
  * you can connect both from usart & USB with two pm3 clients
    * actually you *have* to connect USB for the moment because
      it's used to send debug messages about buggy usart... See Dbprintf_usb below
  * "sessions": msgs are directed to the latest client to have sent a cmd
  * Dbprintf_usb macro to send msgs to USB client to help debugging usart...
  * We now have an option to run client at different speed as usart is 115200:
    client/proxmark3 /dev/ttyUSB0 -b 115200
  * Consequently, argc,argv handling is a bit revamped, it was so messy...
  * USB and flashing are still at 460800, don't try flashing over usart yet ^^
This commit is contained in:
Philippe Teuwen 2019-04-02 22:06:10 +02:00
commit 21be6d4400
15 changed files with 174 additions and 84 deletions

View file

@ -31,6 +31,17 @@
*/
#include "cmd.h"
#ifdef WITH_FPC_HOST
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
bool reply_via_fpc = 0;
extern void Dbprintf(const char *fmt, ...);
#define Dbprintf_usb(...) {\
reply_via_fpc = 0;\
Dbprintf(__VA_ARGS__);\
reply_via_fpc = 1;}
#endif
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
UsbCommand txcmd;
@ -53,11 +64,16 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
uint32_t sendlen = 0;
// Send frame and make sure all bytes are transmitted
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand));
#ifdef WITH_FPC
// usart_init();
// usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) );
#ifdef WITH_FPC_HOST
if (reply_via_fpc) {
sendlen = usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) );
Dbprintf_usb("Sent %i bytes over usart", len);
} else {
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand));
}
#else
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand));
#endif
return sendlen;