diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 9236df6ff..2ab2c4c0e 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1105,30 +1105,32 @@ void UsbPacketReceived(uint8_t *packet, int len) { */ - char dest[USB_CMD_DATA_SIZE] = { '\0' }; - static const char *welcome = "Proxmark3 Serial interface via FPC ready\n"; - strncat(dest, welcome, sizeof(dest) - strlen(dest) - 1); - sprintf(dest + strlen(dest) - 1, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x \n" + char dest[USB_CMD_DATA_SIZE]={'\0'}; + sprintf(dest, usart_dataavailable() ? "DATA!\r\n" : "no data\r\n"); + cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); + + static const char *welcome = "Proxmark3 Serial interface via FPC ready\r\n"; + usart_writebuffer((uint8_t *)welcome, strlen(welcome)); + + sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n" , c->d.asBytes[0] , c->d.asBytes[1] , c->d.asBytes[2] , c->d.asBytes[3] ); + usart_writebuffer((uint8_t *)dest, strlen(dest)); - UsbCommand txcmd = { CMD_DEBUG_PRINT_STRING, { strlen(dest), 0, 0 } }; - memcpy(txcmd.d.asBytes, dest, sizeof(dest)); LED_A_ON(); - usart_init(); - usart_writebuffer((uint8_t *)&txcmd, sizeof(UsbCommand)); //usb cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); + + sprintf(dest, usart_dataavailable() ? "DATA!\r\n" : "no data\r\n"); + cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); LED_A_OFF(); - - - /* +/* uint8_t my_rx[sizeof(UsbCommand)]; while (!BUTTON_PRESS() && !usb_poll_validate_length()) { LED_B_INV(); @@ -1136,13 +1138,12 @@ void UsbPacketReceived(uint8_t *packet, int len) { //UsbPacketReceived(my_rx, sizeof(my_rx)); UsbCommand *my = (UsbCommand *)my_rx; - if (mc->cmd > 0 ) { + if (my->cmd > 0 ) { Dbprintf("received command: 0x%04x and args: %d %d %d", my->cmd, my->arg[0], my->arg[1], my->arg[2]); } } } - */ - +*/ //cmd_send(CMD_DEBUG_PRINT_STRING, strlen(dest), 0, 0, dest, strlen(dest)); cmd_send(CMD_ACK, 0, 0, 0, 0, 0); diff --git a/common/Makefile.hal b/common/Makefile.hal index e34095f2d..0e109340e 100644 --- a/common/Makefile.hal +++ b/common/Makefile.hal @@ -5,6 +5,8 @@ define KNOWN_PLATFORMS +--------------------------------------------------------+ | PM3RDV4 (def) | Proxmark3 rdv4 with AT91SAM7S512 | +--------------------------------------------------------+ +| PM3RDV4FPC | Proxmark3 rdv4+FPC (experimental) | ++--------------------------------------------------------+ | PM3EVO | Proxmark3 EVO with AT91SAM7S512 | +--------------------------------------------------------+ | PM3EASY | Proxmark3 rdv3 Easy with AT91SAM7S256 | @@ -31,6 +33,10 @@ ifeq ($(PLATFORM),PM3RDV4) MCU = AT91SAM7S512 PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH PLTNAME = Proxmark3 rdv4 +else ifeq ($(PLATFORM),PM3RDV4FPC) + MCU = AT91SAM7S512 + PLATFORM_DEFS = -DWITH_SMARTCARD -DWITH_FLASH -DWITH_FPC + PLTNAME = Proxmark3 rdv4 else ifeq ($(PLATFORM),PM3EVO) MCU = AT91SAM7S512 PLTNAME = Proxmark3 EVO diff --git a/common/usart.c b/common/usart.c index 869179091..e82d343ec 100644 --- a/common/usart.c +++ b/common/usart.c @@ -66,27 +66,20 @@ inline int16_t usart_readbuffer(uint8_t *data, size_t len) { } } +inline bool usart_dataavailable(void) { + return (pUS1->US_CSR & AT91C_US_RXRDY) != 0; +} // transfer from device to client inline int16_t usart_writebuffer(uint8_t *data, size_t len) { - - // Check if the first PDC bank is free - if (!(pUS1->US_TCR)) { + if (pUS1->US_TCR == 0) { memcpy(us_outbuf, data, len); pUS1->US_TPR = (uint32_t)us_outbuf; - pUS1->US_TCR = sizeof(us_outbuf); + pUS1->US_TCR = len; pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTDIS; + while((pUS1->US_CSR & AT91C_US_TXEMPTY) ==0) {}; return 2; - } - // Check if the second PDC bank is free - else if (!(pUS1->US_TNCR)) { - memcpy(us_outbuf, data, len); - pUS1->US_TNPR = (uint32_t)us_outbuf; - pUS1->US_TNCR = sizeof(us_outbuf); - - pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTDIS; - return 1; } else { return 0; } @@ -130,7 +123,7 @@ void usart_init(void) { // 115200 * 16 == 1843200 // //pUS1->US_BRGR = (48UL*1000*1000) / (9600*16); - pUS1->US_BRGR = 48054841 / (9600 << 4); + pUS1->US_BRGR = 48054841 / (115200 << 4); // Write the Timeguard Register pUS1->US_TTGR = 0; diff --git a/common/usart.h b/common/usart.h index 7e8d3eb7b..c49b0a8fd 100644 --- a/common/usart.h +++ b/common/usart.h @@ -9,4 +9,5 @@ void usart_close(void); int16_t usart_readbuffer(uint8_t *data, size_t len); int16_t usart_writebuffer(uint8_t *data, size_t len); +bool usart_dataavailable(void); #endif diff --git a/uart/uart_posix.c b/uart/uart_posix.c index 95e9ce070..0b12cd76b 100644 --- a/uart/uart_posix.c +++ b/uart/uart_posix.c @@ -194,14 +194,6 @@ serial_port uart_open(const char *pcPortName) { // Flush all lingering data that may exist tcflush(sp->fd, TCIOFLUSH); -#ifdef WITH_FPC - if (uart_set_speed(sp, 115200)) { - printf("[=] UART Setting serial baudrate 115200 [FPC enabled]\n"); - } else { - uart_set_speed(sp, 9600); - printf("[=] UART Setting serial baudrate 9600 [FPC enabled]\n"); - } -#else // set speed, works for UBUNTU 14.04 bool success = uart_set_speed(sp, 460800); if (success) { @@ -210,7 +202,6 @@ serial_port uart_open(const char *pcPortName) { uart_set_speed(sp, 115200); printf("[=] UART Setting serial baudrate 115200\n"); } -#endif return sp; }