ADSP-21569
Recommended for New Designs
Reaching speeds of up to 1 GHz, the ADSP-2156x processors are members of the SHARC® family of products. The ADSP-2156x processor is based on the SHARC...
Datasheet
ADSP-21569 on Analog.com
/*********************************************************************************
Copyright(c) 2020 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.
*********************************************************************************/
/*****************************************************************************
* SPI_MemoryMappedMode.c
*****************************************************************************/
#include <stdio.h>
#include <sys/platform.h>
#include <drivers/spi/adi_spi.h>
#include "adi_initialize.h"
#include "SPI_MemoryMappedMode.h"
ADI_SPI_HANDLE hSpi;
uint8_t SpiMemory[ADI_SPI_BIDIR_MEMORY_SIZE];
uint8_t ReadBuffer[BUFFER_SIZE]={0};
/* prototype */
void ConfigSoftSwitches_EV_21569_SOM(void);
void ConfigSoftSwitches_EV_SOMCRR_EZKIT(void);
static void CheckResult(ADI_SPI_RESULT Result) {
if (Result != ADI_SPI_SUCCESS) {
printf("Failed with error code 0x%08X\n", Result);
}
}
int main()
{
uint32_t Result,gpioMaxCallbacks;
ADI_SPI_RESULT eResult;
ADI_SPI_MMRDH_PARAM Mmrdh;
uint32_t *pSPI_MEM ;
adi_initComponents();
ConfigSoftSwitches_EV_21569_SOM();
ConfigSoftSwitches_EV_SOMCRR_EZKIT();
/* open SPI */
eResult = adi_spi_Open(SPI_DEVICE_NUM, ADI_SPI_DIR_BIDIRECTION, SpiMemory, ADI_SPI_BIDIR_MEMORY_SIZE, &hSpi);
CheckResult(eResult);
/* Set the MMRDH parameters
* struct ADI_SPI_MMRDH_PARAM available in adi_spi_2156x.h has detailed description of
* the below mentioned fields */
Mmrdh.bCmdSkip = false;
Mmrdh.bCmdPins = false;
Mmrdh.bAddrPin = false;
Mmrdh.bMergeEnable = false;
Mmrdh.bWrapEnable = false;
Mmrdh.nOpcode = CMD_SINGLE_MODE_READ;
Mmrdh.nModeField = 0x00u;
// Mmrdh.nAddrSize = ADI_SPI_MMRDH_ADRSIZE_3BYTE;
Mmrdh.nAddrSize = ADI_SPI_MMRDH_ADRSIZE_4BYTE;
Mmrdh.nDummybytes = ADI_SPI_MMRDH_0_DUMMY_BYTE;
Mmrdh.nTristateTiming = ADI_SPI_MMRDH_NEVER_TRISTATE;
eResult = adi_spi_SetSlaveSelectDelay(hSpi,true,true,3ul);
CheckResult(eResult);
eResult = adi_spi_SetWordSize(hSpi,ADI_SPI_WORDSIZE_32BIT);
CheckResult(eResult);
eResult = adi_spi_SetHWSlaveSelect(hSpi,true);
CheckResult(eResult);
eResult = adi_spi_SetSlaveSelect(hSpi,ADI_SPI_SSEL_ENABLE1);
CheckResult(eResult);
eResult = adi_spi_Enable_MemMappedMode(hSpi,Mmrdh,NULL);
CheckResult(eResult);
/* Read the contents of the SPI Flash memory which should be verified with
* the data written into by the flash programmer */
uint32_t sectorAddress = SECTOR_OFFSET;
pSPI_MEM = (uint32_t *)0x60000000;
int32_t pIntBuffer[COUNT];
int32_t *tmp;
uint32_t currentAddress;
for(uint32_t i=0; i<COUNT; i++)
{
// ReadBuffer[LoopVar]= *pSPI_MEM++;
//currentAddress = (uint32_t)(pSPI_MEM + sectorAddress + (i * sizeof(int32_t)));
currentAddress = (uint32_t)(pSPI_MEM + SECTOR_OFFSET + i );
// printf("Reading from address: 0x%08X\n", currentAddress);
pIntBuffer[i] = *(int32_t *)currentAddress;
}
printf("Reading from address: 0x%08X\n", currentAddress);
eResult = adi_spi_Disable_MemMappedMode(hSpi);
CheckResult(eResult);
/* Close the SPI driver */
eResult = adi_spi_Close(hSpi);
CheckResult(eResult);
/*************************************************************************************************************/
/* open SPI */
eResult = adi_spi_Open(SPI_DEVICE_NUM, ADI_SPI_DIR_BIDIRECTION, SpiMemory, ADI_SPI_BIDIR_MEMORY_SIZE, &hSpi);
CheckResult(eResult);
eResult = adi_spi_SetSlaveSelect(hSpi, SPI_SELECT_NUM);
CheckResult(eResult);
eResult = adi_spi_SetWordSize(hSpi, ADI_SPI_WORDSIZE_32BIT);
CheckResult(eResult);
/* Read the contents of the SPI Flash memory */
int32_t intBuffer[COUNT];
int32_t pReadData[COUNT];
ADI_SPI_TRANSCEIVER_PARAM transceiver;
sectorAddress = SECTOR_OFFSET;
/* Read the contents of the SPI Flash memory */
for (uint32_t i = 0; i < COUNT; i++) {
//currentAddress = (uint32_t)(pSPI_MEM + SECTOR_OFFSET + i );
currentAddress = (uint32_t)( pSPI_MEM+SECTOR_OFFSET + i);
// Setup the transceiver for read operation
uint8_t command[4] = {0x03, (currentAddress >> 16) & 0xFF, (currentAddress >> 8) & 0xFF, (currentAddress >> 0) & 0xFF};
// uint8_t command[5] = {0x13,(currentAddress >> 24) & 0xFF, (currentAddress >> 16) & 0xFF, (currentAddress >> 8) & 0xFF, currentAddress & 0xFF}; // 0x0B is the opcode for 32-bit address read
transceiver.pTransmitter = command; //
transceiver.pReceiver = & intBuffer[i];
transceiver.TxBytes = sizeof(command);
transceiver.RxBytes = sizeof(command); // Size of data to read
eResult = adi_spi_CoreTransceiver(hSpi, &transceiver);
CheckResult(eResult);
/* Read the contents of the SPI Flash memory */
uint8_t seqReadWrite[4];
seqReadWrite[0] = 0x03;
seqReadWrite[1] = (currentAddress >> 16) & 0xFF;
seqReadWrite[2] = (currentAddress >> 8) & 0xFF;
seqReadWrite[3] = (currentAddress >> 0) & 0xFF;
eResult = adi_spi_CoreWrite(hSpi,seqReadWrite,4);
eResult = adi_spi_CoreRead(hSpi,&pReadData,COUNT,ADI_OSAL_TIMEOUT_FOREVER);
uint8_t seqReadWrite2[5];
seqReadWrite2[0] = 0x13;
seqReadWrite2[1] = (currentAddress >> 24) & 0xFF;
seqReadWrite2[2] = (currentAddress >> 16) & 0xFF;
seqReadWrite2[3] = (currentAddress >> 8) & 0xFF;
seqReadWrite2[4] = (currentAddress >> 0) & 0xFF;
eResult = adi_spi_CoreWrite(hSpi,seqReadWrite2,5);
eResult = adi_spi_CoreRead(hSpi,&pReadData,COUNT,ADI_OSAL_TIMEOUT_FOREVER);
}
printf("Reading from address: 0x%08X\n", currentAddress);
/* Close the SPI driver */
eResult = adi_spi_Close(hSpi);
CheckResult(eResult);
/*************************************************************************************************************/
return 0;
}
I am using an adsp-21569 development board with an IS25LP512M on the SOM. I plan to read data through the SPI interface, starting from the address 0x60000000. The reference routine reads data using the memory-map method without any issues. However, I have not been successful using either adi_spi_CoreRead or adi_spi_CoreTransceiver. Could you please help me troubleshoot the problem?