Post Go back to editing

Read from SPI flash through memory mapped mode

Category: Software
Product Number: ADSP-SC593

Hi,

Based on BSP downloaded from here:

download.analog.com/.../ADI_EV-SC59x_EZ-KIT-Rel4.0.0.exe

and examples from

[Installation path]\Analog Devices\EV-SC59x_EZ-KIT-Rel4.0.0\EV-SC59x_EZ-KIT\Examples\drivers\ospi\ospi_flashdirectaccess

I tried the code snippet mentioned. Further modified a few things of the ADI_OSPI_DAC_CMD DAC_Read_Command2 and tried.

The aim is to Read from Flash using memory mapped IO from address specified like 0x60005800.

I am trying only Read from Flash via Direct Access Control. Non-DMA mode is intended.

However, no data is being read. All values are zeros.

However, the result of driver function calls are all ADI_OSPI_SUCCESS.

Attached herewith in the .txt file are the various code snippet modifications done. They mainly differ in the parameters assigned to DAC_Read_Command2.

Can you please let me know what is likely to have been missed and why only zeros are obtained in the ReadBuffer?

 Thanks,

===========================
Modification Case 1:
===========================
ADI_OSPI_DAC_CMD DAC_Read_Command2;
#if 1
        /* Buffer into which the data from Flash is read in to */
        #define READBUFFSIZE 0x128
        uint8_t ReadBuff[READBUFFSIZE];

        ADI_OSPI_RESULT eResult = ADI_OSPI_SUCCESS;

        uint8_t nDriver_Memory[ADI_OSPI_MEMORY_SIZE + ADI_SPU_MEMORY_SIZE];
        #define MDMA_CHANNEL_USED 	ADI_DMA_MEMDMA_S0
        /* Initialize OSPI controller */
        //if(Ospi_initialize() != 0U)
        //    return 0;        

            /* Handle for OSPI driver */
        uint32_t HandleMem = 0;
        ADI_OSPI_HANDLE *phDevice = (ADI_OSPI_HANDLE*)&HandleMem;
        
        DAC_Read_Command2.CmdOpcode         = 0x03; // /*(0x0B)Fast Read mode */   /*(0x03)Normal Read mode */
        DAC_Read_Command2.CmdOpcode2        = 0;
        DAC_Read_Command2.eBusMode          = ADI_OSPI_SINGLE;
        DAC_Read_Command2.eTransferMode     = ADI_OSPI_TRANSFERMODE_STR;
        DAC_Read_Command2.eOperatingMode    = OSPI_ADI_COREMODE;
        DAC_Read_Command2.eAddrSize         = ADI_OSPI_CMD_ADDR_SIZE_3;
        DAC_Read_Command2.NumOfDummyCycles  = 8;
        DAC_Read_Command2.ModeDataEnable    = 1;  // check for 0
        DAC_Read_Command2.ModeData          = 0;
        DAC_Read_Command2.pSource           = (uint8_t *)0x60000000;
        DAC_Read_Command2.pDestination      = (uint8_t *)ReadBuff;
        DAC_Read_Command2.nCount            = READBUFFSIZE; // tried 16 earlier

        eResult = adi_ospi_Open((uint8_t *)nDriver_Memory + ADI_SPU_MEMORY_SIZE,
        ADI_OSPI_MEMORY_SIZE,
        OSPI_ADI_MDMAUSED,
        MDMA_CHANNEL_USED,
        phDevice
        );

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Open OSPI driver. Error code returned %d \n", eResult);
            return -1;
        }
  
        eResult = adi_ospi_ConfigBaud(*phDevice, ADI_OSPI_BAUD_DIV_BY_32);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Baud rate. Error code returned %d \n", eResult);
            return -1;
        }
    
        eResult = adi_ospi_UpdateReadDelay(*phDevice, 8);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Read delay capture value. Error code returned %d \n", eResult);
            return -1;
        }

        /* Perform the read operation in the configured mode of OSPI and flash */
        eResult = adi_ospi_DirectRead( *phDevice, &DAC_Read_Command2);

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Error occurred in OSPI Direct Read. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }

        /* Close the OPSI driver */
        eResult = adi_ospi_Close(*phDevice);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Close OSPI driver. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }
#else
==================================================================================
Modification #2:  Changed the source address to 0x5800
ADI_OSPI_DAC_CMD DAC_Read_Command2;
#if 1
        /* Buffer into which the data from Flash is read in to */
        #define READBUFFSIZE 128U
        uint8_t ReadBuff[READBUFFSIZE];

        ADI_OSPI_RESULT eResult = ADI_OSPI_SUCCESS;

        uint8_t nDriver_Memory[ADI_OSPI_MEMORY_SIZE + ADI_SPU_MEMORY_SIZE];
        #define MDMA_CHANNEL_USED 	ADI_DMA_MEMDMA_S0
        /* Initialize OSPI controller */
        //if(Ospi_initialize() != 0U)
        //    return 0;        

            /* Handle for OSPI driver */
        uint32_t HandleMem = 0;
        ADI_OSPI_HANDLE *phDevice = (ADI_OSPI_HANDLE*)&HandleMem;
        
        DAC_Read_Command2.CmdOpcode         = 0x03; // /*(0x0B)Fast Read mode */   /*(0x03)Normal Read mode */
        DAC_Read_Command2.CmdOpcode2        = 0;
        DAC_Read_Command2.eBusMode          = ADI_OSPI_SINGLE;
        DAC_Read_Command2.eTransferMode     = ADI_OSPI_TRANSFERMODE_STR;
        DAC_Read_Command2.eOperatingMode    = OSPI_ADI_COREMODE;
        DAC_Read_Command2.eAddrSize         = ADI_OSPI_CMD_ADDR_SIZE_3;
        DAC_Read_Command2.NumOfDummyCycles  = 8;
        DAC_Read_Command2.ModeDataEnable    = 1;  // check for 0
        DAC_Read_Command2.ModeData          = 0;
        DAC_Read_Command2.pSource           = (uint8_t *)0x00005800; // Tried this also (uint8_t *)0x60000000;
        DAC_Read_Command2.pDestination      = (uint8_t *)ReadBuff;
        DAC_Read_Command2.nCount            = READBUFFSIZE; // tried 16 earlier

        eResult = adi_ospi_Open((uint8_t *)nDriver_Memory + ADI_SPU_MEMORY_SIZE,
        ADI_OSPI_MEMORY_SIZE,
        OSPI_ADI_MDMAUSED,
        MDMA_CHANNEL_USED,
        phDevice
        );

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Open OSPI driver. Error code returned %d \n", eResult);
            return -1;
        }
  
        eResult = adi_ospi_ConfigBaud(*phDevice, ADI_OSPI_BAUD_DIV_BY_32);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Baud rate. Error code returned %d \n", eResult);
            return -1;
        }
    
        eResult = adi_ospi_UpdateReadDelay(*phDevice, 8);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Read delay capture value. Error code returned %d \n", eResult);
            return -1;
        }

        /* Perform the read operation in the configured mode of OSPI and flash */
        eResult = adi_ospi_DirectRead( *phDevice, &DAC_Read_Command2);

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Error occurred in OSPI Direct Read. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }

        /* Close the OPSI driver */
        eResult = adi_ospi_Close(*phDevice);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Close OSPI driver. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }
#else
============================================================================
Modification #3: Made NumOfDummyCycles, ModeDataEnable and ModeData all 0.
ADI_OSPI_DAC_CMD DAC_Read_Command2;
#if 1
        /* Buffer into which the data from Flash is read in to */
        #define READBUFFSIZE 128U
        uint8_t ReadBuff[READBUFFSIZE];

        ADI_OSPI_RESULT eResult = ADI_OSPI_SUCCESS;

        uint8_t nDriver_Memory[ADI_OSPI_MEMORY_SIZE + ADI_SPU_MEMORY_SIZE];
        #define MDMA_CHANNEL_USED 	ADI_DMA_MEMDMA_S0
        /* Initialize OSPI controller */
        //if(Ospi_initialize() != 0U)
        //    return 0;        

            /* Handle for OSPI driver */
        uint32_t HandleMem = 0;
        ADI_OSPI_HANDLE *phDevice = (ADI_OSPI_HANDLE*)&HandleMem;
        
        DAC_Read_Command2.CmdOpcode         = 0x03; // /*(0x0B)Fast Read mode */   /*(0x03)Normal Read mode */
        DAC_Read_Command2.CmdOpcode2        = 0;
        DAC_Read_Command2.eBusMode          = ADI_OSPI_SINGLE;
        DAC_Read_Command2.eTransferMode     = ADI_OSPI_TRANSFERMODE_STR;
        DAC_Read_Command2.eOperatingMode    = OSPI_ADI_COREMODE;
        DAC_Read_Command2.eAddrSize         = ADI_OSPI_CMD_ADDR_SIZE_3;
        DAC_Read_Command2.NumOfDummyCycles  = 0;
        DAC_Read_Command2.ModeDataEnable    = 0;  // check for 0
        DAC_Read_Command2.ModeData          = 0;
        DAC_Read_Command2.pSource           = (uint8_t *)0x00005800; // Tried this also (uint8_t *)0x60000000;
        DAC_Read_Command2.pDestination      = (uint8_t *)ReadBuff;
        DAC_Read_Command2.nCount            = READBUFFSIZE; // tried 16 earlier

        eResult = adi_ospi_Open((uint8_t *)nDriver_Memory + ADI_SPU_MEMORY_SIZE,
        ADI_OSPI_MEMORY_SIZE,
        OSPI_ADI_MDMAUSED,
        MDMA_CHANNEL_USED,
        phDevice
        );

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Open OSPI driver. Error code returned %d \n", eResult);
            return -1;
        }
  
        eResult = adi_ospi_ConfigBaud(*phDevice, ADI_OSPI_BAUD_DIV_BY_32);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Baud rate. Error code returned %d \n", eResult);
            return -1;
        }
    
        eResult = adi_ospi_UpdateReadDelay(*phDevice, 8);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to update the Read delay capture value. Error code returned %d \n", eResult);
            return -1;
        }

        /* Perform the read operation in the configured mode of OSPI and flash */
        eResult = adi_ospi_DirectRead( *phDevice, &DAC_Read_Command2);

        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Error occurred in OSPI Direct Read. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }

        /* Close the OPSI driver */
        eResult = adi_ospi_Close(*phDevice);
        if(eResult != ADI_OSPI_SUCCESS)
        {
            printf("Failed to Close OSPI driver. Error code returned %d \n", eResult);
            printf("Fail \n");
            return 0;
        }
#else

  • Hi,

    We have tested the ospi_flashdirectaccess example in core mode with the configuration you provided, and it works as expected on the ADSP-21593 SOM.

    We understand that you are using a custom board, so to assist you more effectively, could you please provide the following information:

    1.Could you please share the exact part numbers for the processor and flash memory you are using?
    2.Please try running the example in the BSP without any modifications and share the results with us.
    3.We noticed that the ModeDataEnable bit is enabled in your commands. Are you attempting to use XIP (Execute in Place) mode?
    4.Is any data written to the flash memory address 0x5800 before performing the read operation?
    5.According to the datasheet, OSPI memory-mapped address access starts from 0x60000000. Could you please change the DAC_Read_Command2.pSource to (uint8_t *)0x60005800 in modification case 3 and share the results with us?

    This will help us to assist you further.

    Regards,
    Nandini C

  • Hi,

    It is found that the main cause for the Flash read to not occur was the missing call to Init_pinmux() function. Once this is done read is being done fine. 

    Yes, the address to be read is from 0x60000000 onwards. Hence 0x5800 will not work. 

    Winbond flash is used.

    Hence this ticket can be closed. 

    Thanks Nandini C for taking time for your reply. 

  • Hi,

    Thanks for the update and glad to know your issue got resolved.

    Regards,
    Nandini C