Post Go back to editing

Example code to setup SPI2 in memory map mode on ADSP-SC589 SAM

Category: Hardware

Is there any example code on how to map the flash device on the SAM board in memory mapped mode ? 

I'm trying to read a section of flash, and I had it working the other day, but now I can't get it to work without generating a data abort exception. 

This is what I have so far, following the guide in the HWR and using same polarity & speed that I have working in another application on the same HW. 

What I find is that the ARM core freezes on the *pREG_SPI2_CTL |=BITM_SPI_CTL_MMSE; line and doesn't continue. No SPI error bits are set. 

// Enable SPI2 memory map mode
*pREG_SPI2_CTL &= ~BITM_SPI_CTL_EN;
*pREG_SPI2_RXCTL = BITM_SPI_RXCTL_REN;
*pREG_SPI2_TXCTL = BITM_SPI_TXCTL_TEN | BITM_SPI_TXCTL_TTI;
*pREG_SPI2_DLY = BITM_SPI_DLY_LAGX | BITM_SPI_DLY_LEADX | (3 << BITP_SPI_DLY_STOP);
// Anomaly 20000062 - Writes to the SPI_SLVSEL Register Do Not Take Effect: Write twice
*pREG_SPI2_SLVSEL |= ENUM_SPI_SLVSEL_SSEL1_EN;
*pREG_SPI2_SLVSEL |= ENUM_SPI_SLVSEL_SSEL1_EN;
*pREG_SPI2_MMRDH = ( 3 << BITP_SPI_MMRDH_ADRSIZE) | ( 0x03u << BITP_SPI_MMRDH_OPCODE);
*pREG_SPI2_MMTOP = 0x04000000;
*pREG_SPI2_CLK = 0x50;
*pREG_SPI2_CTL = ENUM_SPI_CTL_MASTER | BITM_SPI_CTL_EMISO | ENUM_SPI_CTL_SIZE32 | ENUM_SPI_CTL_ASSRT_SSEL | BITM_SPI_CTL_SELST | ENUM_SPI_CTL_FAST_EN;
*pREG_SPI2_CTL |=BITM_SPI_CTL_MMSE;
*pREG_SPI2_CTL |= BITM_SPI_CTL_EN;

  • Hi,

    Please find the attached project for ADSP-SC584. Please take this as reference and modify it as per your requirement.

    Attached code writes known data into flash via configured Quad mode SPI and switches SPI to Memory mapped mode to read data. Now written data gets reflected in DSP SPI mapped memory (0x60000000u), so we can read the data from there. Again SPI switched back to normal mode for further process. Now we can do quad write/read transfers as we required. For example, using quad read you can read the data already written in flash after you had completed memory mapped mode read.

    Quad and memmode.zip

    Regards,
    Anand Selvaraj.

  • Thanks for that. Is there anything special I need to do to be able to use memory mapped mode on the ARM core ? When I try to read from the memory mapped SPI flash, I get a Data Fault Exception.. 

    Description: Data Fault Exception - caused by attempting to access invalid data memory.
    General Type: RunTimeError
    Specific Type: ExceptAbrtData
    Error Message: If this is a synchronous fault, address 0x00600008 held in Data Fault Address Register (DFAR) is the problem address.
    Error PC: 0x200b0fca

    Thanks

    Rob

  • Hi,

    Please refer the attached project which works fine in ARM core of ADSP-SC584. Please take this as reference.

    TEST_MEMMODE_Core0.zip

    Regards,
    Anand Selvaraj.