mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
CHG: FPC connector tests. Device -> Client communications works.
Adjust armsrc/Makefile and client/Makefile to include the -DWITH_FPC flag to compile with FPC enabled.
This commit is contained in:
parent
aa3b322d0f
commit
f8c33af1da
7 changed files with 123 additions and 119 deletions
|
@ -56,8 +56,8 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
|
|||
sendlen = usb_write( (uint8_t*)&txcmd, sizeof(UsbCommand) );
|
||||
|
||||
#ifdef WITH_FPC
|
||||
usart_init();
|
||||
usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) );
|
||||
// usart_init();
|
||||
// usart_writebuffer( (uint8_t*)&txcmd, sizeof(UsbCommand) );
|
||||
#endif
|
||||
|
||||
return sendlen;
|
||||
|
|
114
common/usart.c
114
common/usart.c
|
@ -1,6 +1,6 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Iceman, July 2018
|
||||
// edists by - Anticat, August 2018
|
||||
// edits by - Anticat, August 2018
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
|
@ -14,7 +14,7 @@
|
|||
#define AT91_BAUD_RATE 115200
|
||||
|
||||
volatile AT91PS_USART pUS1 = AT91C_BASE_US1;
|
||||
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
|
||||
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
|
||||
volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_US1;
|
||||
|
||||
/*
|
||||
|
@ -39,90 +39,53 @@ void usart_close(void) {
|
|||
}
|
||||
*/
|
||||
|
||||
static uint8_t outbuf[sizeof(UsbCommand)];
|
||||
//static uint8_t inbuf[sizeof(UsbCommand)];
|
||||
|
||||
static uint8_t us_outbuf[sizeof(UsbCommand)];
|
||||
|
||||
/// Reads data from an USART peripheral
|
||||
/// \param data Pointer to the buffer where the received data will be stored.
|
||||
/// \param len Size of the data buffer (in bytes).
|
||||
inline int usart_readbuffer(uint8_t *data, size_t len) {
|
||||
inline int16_t usart_readbuffer(uint8_t *data, size_t len) {
|
||||
|
||||
pUS1->US_PTSR = AT91C_PDC_TXTEN;
|
||||
pUS1->US_PTCR = AT91C_PDC_TXTEN;
|
||||
|
||||
// Check if the first PDC bank is free
|
||||
if (!(pUS1->US_RCR)) {
|
||||
pUS1->US_RPR = (uint32_t)data;
|
||||
pUS1->US_RCR = len;
|
||||
|
||||
pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTDIS;
|
||||
return 2;
|
||||
}
|
||||
// Check if the second PDC bank is free
|
||||
else if (!(pUS1->US_RNCR)) {
|
||||
pUS1->US_RNPR = (uint32_t)data;
|
||||
pUS1->US_RNCR = len;
|
||||
|
||||
pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTDIS;
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
pPDC->PDC_PTSR = AT91C_PDC_RXTEN;
|
||||
pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
|
||||
|
||||
//check if data is available
|
||||
if (pPDC->PDC_RCR != 0) return -1;
|
||||
|
||||
memcpy(data, inbuf, len);
|
||||
|
||||
//start next transfer
|
||||
pPDC->PDC_RNPR = (uint32_t)inbuf;
|
||||
pPDC->PDC_RNCR = sizeof(inbuf);
|
||||
|
||||
return sizeof(inbuf);
|
||||
*/
|
||||
}
|
||||
/*
|
||||
int16_t usart_writebuffer(uint8_t *data, size_t len) {
|
||||
|
||||
// pUS1->US_PTSR = AT91C_PDC_TXTEN;
|
||||
pUS1->US_PTCR = AT91C_PDC_TXTEN;
|
||||
|
||||
// if buffer is sent
|
||||
if (pUS1->US_TCR != 0) return -1;
|
||||
|
||||
memcpy(outbuf, data, len);
|
||||
|
||||
//start next transfer
|
||||
pUS1->US_TNPR = (uint32_t)outbuf;
|
||||
pUS1->US_TNCR = sizeof(outbuf);
|
||||
|
||||
return sizeof(outbuf);
|
||||
}
|
||||
*/
|
||||
|
||||
// works.
|
||||
// transfer to client
|
||||
// transfer from device to client
|
||||
inline int16_t usart_writebuffer(uint8_t *data, size_t len) {
|
||||
|
||||
pUS1->US_PTSR = AT91C_PDC_TXTEN;
|
||||
pUS1->US_PTCR = AT91C_PDC_TXTEN;
|
||||
|
||||
// Check if the first PDC bank is free
|
||||
if (!(pUS1->US_TCR)) {
|
||||
|
||||
memcpy(outbuf, data, len);
|
||||
|
||||
pUS1->US_TPR = (uint32_t)outbuf;
|
||||
pUS1->US_TCR = sizeof(outbuf);
|
||||
memcpy(us_outbuf, data, len);
|
||||
pUS1->US_TPR = (uint32_t)us_outbuf;
|
||||
pUS1->US_TCR = sizeof(us_outbuf);
|
||||
|
||||
pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTDIS;
|
||||
return 2;
|
||||
}
|
||||
// Check if the second PDC bank is free
|
||||
else if (!(pUS1->US_TNCR)) {
|
||||
memcpy(outbuf, data, len);
|
||||
|
||||
pUS1->US_TNPR = (uint32_t)outbuf;
|
||||
pUS1->US_TNCR = sizeof(outbuf);
|
||||
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;
|
||||
|
@ -132,19 +95,20 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) {
|
|||
void usart_init(void) {
|
||||
|
||||
// disable & reset receiver / transmitter for configuration
|
||||
pUS1->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX);
|
||||
pUS1->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS);
|
||||
|
||||
//enable the USART1 Peripheral clock
|
||||
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_US1);
|
||||
|
||||
// disable PIO control of receive / transmit pins
|
||||
pPIOA->PIO_PDR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
pPIO->PIO_PDR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
|
||||
// enable peripheral mode A on receive / transmit pins
|
||||
pPIOA->PIO_ASR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
pPIO->PIO_ASR |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
pPIO->PIO_BSR = 0;
|
||||
|
||||
// enable pull-up on receive / transmit pins (see 31.5.1 I/O Lines)
|
||||
pPIOA->PIO_PPUER |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
pPIO->PIO_PPUER |= (AT91C_PA21_RXD1 | AT91C_PA22_TXD1);
|
||||
|
||||
// set mode
|
||||
pUS1->US_MR = AT91C_US_USMODE_NORMAL | // normal mode
|
||||
|
@ -154,8 +118,19 @@ void usart_init(void) {
|
|||
AT91C_US_NBSTOP_1_BIT | // 1 stop bit
|
||||
AT91C_US_CHMODE_NORMAL; // channel mode: normal
|
||||
|
||||
// all interrupts disabled
|
||||
pUS1->US_IDR = 0xFFFF;
|
||||
|
||||
// iceman, setting 115200 doesn't work. Only speed I got to work is 9600.
|
||||
// something fishy with the AT91SAM7S512 USART.. Or I missed something
|
||||
// For a nice detailed sample, interrupt driven but still relevant.
|
||||
// See https://www.sparkfun.com/datasheets/DevTools/SAM7/at91sam7%20serial%20communications.pdf
|
||||
|
||||
// set baudrate to 115200
|
||||
pUS1->US_BRGR = (48UL*1000*1000) / (115200*16);
|
||||
// 115200 * 16 == 1843200
|
||||
//
|
||||
//pUS1->US_BRGR = (48UL*1000*1000) / (9600*16);
|
||||
pUS1->US_BRGR = 48054841 / (9600 << 4);
|
||||
|
||||
// Write the Timeguard Register
|
||||
pUS1->US_TTGR = 0;
|
||||
|
@ -163,23 +138,6 @@ void usart_init(void) {
|
|||
pUS1->US_FIDI = 0;
|
||||
pUS1->US_IF = 0;
|
||||
|
||||
/*
|
||||
//Empty PDC
|
||||
pUS1->US_RNPR = (uint32_t)(char *)0;
|
||||
pUS1->US_RNCR = 0;
|
||||
pUS1->US_RPR = (uint32_t)(char *)0;
|
||||
pUS1->US_RCR = 0;
|
||||
|
||||
pUS1->US_TNPR = (uint32_t)(char *)0;
|
||||
pUS1->US_TNCR = 0;
|
||||
pUS1->US_TPR = (uint32_t)(char *)0;
|
||||
pUS1->US_TCR = 0;
|
||||
*/
|
||||
|
||||
//pUS1->US_PTCR = (AT91C_PDC_RXTEN | AT91C_PDC_TXTEN);
|
||||
//pUS1->US_PTSR = (AT91C_PDC_RXTEN | AT91C_PDC_TXTEN);
|
||||
|
||||
// re-enable receiver / transmitter
|
||||
pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN);
|
||||
|
||||
}
|
|
@ -7,6 +7,6 @@
|
|||
void usart_init(void);
|
||||
void usart_close(void);
|
||||
|
||||
int usart_readbuffer(uint8_t *data, size_t len);
|
||||
int16_t usart_readbuffer(uint8_t *data, size_t len);
|
||||
int16_t usart_writebuffer(uint8_t *data, size_t len);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue