Dear responsible,
We are trying to develop an industrial software on IDKAM437x board. One part of this software is SPI communication where SPI0 on AM437x is configured as master. Our main problem is that we cannot swap the D0 and D1. Default master configuration on sitara configures D1-SPI0_DOUT and D0-SPI0_DIN which we would like to configure as D1-SPI0-DIN and D0-SPI0_DOUT.
For the purpose we are using the following code parts.
am43xx_idkevm_pinmux_data.c
static pinmuxPerCfg_t gMcspi0PinCfg[] =
{
{
/* SPI0 -> spi0_sclk -> P23 */
PIN_SPI0_SCLK, 0, \
( \
PIN_MODE(0) | \
((PIN_PULL_UD_DIS | PIN_PULL_UP_EN | PIN_RX_ACTIVE | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \
(~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN))
) \
},
{
/* SPI0 -> spi0_d0 -> T22 */
PIN_SPI0_D0, 0, \
( \
PIN_MODE(0) | \
((PIN_PULL_UD_DIS | PIN_PULL_UP_EN | PIN_RX_ACTIVE | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \
(~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN))
) \
},
{
/* SPI0 -> spi0_d1 -> T21 */
PIN_SPI0_D1, 0, \
( \
PIN_MODE(0) | \
((PIN_PULL_UP_EN | PIN_RX_ACTIVE | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \
(~PIN_PULL_UD_DIS & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN))
) \
},
{
/* SPI0 -> spi0_cs0 -> T20 */
PIN_SPI0_CS0, 0, \
( \
PIN_MODE(0) | \
((PIN_PULL_UP_EN | PIN_RX_ACTIVE | PIN_DS_VALUE_OVERRIDE_EN | PIN_DS_OP_DIS | PIN_DS_PULL_UP_EN) & \
(~PIN_PULL_UD_DIS & ~PIN_DS_OP_VAL_1 & ~PIN_DS_PULL_UD_EN & ~PIN_WAKE_UP_EN))
) \
},
{PINMUX_INVALID_PIN}
};
main.c
static bool spi_open(uint32_t bitRate)
{
/* Configure SPI as master */
//SPI_init();
SPI_Params_init(&spiParams);
spiParams.bitRate = bitRate;
spiParams.mode = SPI_MASTER;
spiParams.transferMode = SPI_MODE_BLOCKING;
// spiParams.frameFormat = SPI_POL0_PHA0;
/* Attempt to open SPI. */
uint32_t u32_temp_x = 0U;
u32_temp_x = HW_RD_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D0);
// HW_WR_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D0,0x13070000); // D0 input
HW_WR_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D0,0x13020000); // D0 output
u32_temp_x = 0U;
u32_temp_x = HW_RD_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D1);
// HW_WR_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D1,0x13060000); // D1 output
HW_WR_REG32(SOC_CONTROL_MODULE_REG + CTRL_CONF_SPI0_D1,0x13060000); // D1 input
spiHandle = SPI_open(SPI_INSTANCE, &spiParams);
return spiHandle != NULL;
}
static bool spi_write(const uint8_t *buf, size_t len)
{
SPI_Transaction masterTransaction;
masterTransaction.count = len;
masterTransaction.txBuf = (void*)buf;
masterTransaction.arg = NULL;
masterTransaction.rxBuf = NULL;
return SPI_transfer(spiHandle, &masterTransaction) ? 1 : 0;
}
static bool spi_read(uint8_t *buf, size_t len)
{
SPI_Transaction masterTransaction;
masterTransaction.count = len;
masterTransaction.rxBuf = buf;
masterTransaction.txBuf = NULL;
masterTransaction.arg = NULL;
return SPI_transfer(spiHandle, &masterTransaction) ? 1 : 0;
}
#define PICCOLO_WRITE 0x55
static bool spi_write_test(void) {
bool flag;
const uint8_t comadd[] = {PICCOLO_WRITE};
//flashSelect(); // acaba burasi SPI in CS pini mi ?
flag = spi_write(comadd,sizeof(comadd));
//flashDeSelect(); // acaba burasi SPI in CS pini mi ?
return flag;
}
#define PICCOLO_READ 0xAA
static uint8_t devInfoBuf[3];
static bool spi_read_test(void) {
bool flag;
const uint8_t comadd[] = {PICCOLO_READ, 0x00, 0x00, 0x00};//
//flashSelect();//
flag = spi_write(comadd, sizeof(comadd));//
if(!flag) {
//flashDeSelect();
return false;
}
flag = spi_read(devInfoBuf, sizeof(devInfoBuf));//
//flashDeSelect();//
return flag;
}
When we debug the code and trace the related memory adress for D0 and D1 we can see the register values as they are at the main code (HW_WR_REG32...) but at the end we are always getting the data out from D1 which we would like to shift to D0.
Thank you,
Sunay.