Cortex M3 (ATSAM3N4B) Peripheral DMA read from SRAM ok, FLASH fails

atmelccortex-m3uart

I've stumbled across a peculiar problem with my PDC (Peripheral DMA Controller) where using the PDC to transfer a constant string from flash over UART 0 seems to produce an unexpected result. The correct number of bytes is sent but they are all zero.

The string is defined in the global namespace as follows

char* str = "Hello world!";

I only send it once at the start of main like this:

UART0->UART_TPR = str;               // PDC transfer pointer
UART0->UART_TCR = strlen(str);       // PDC counter
UART0->UART_PTCR = UART_PTCR_TXTEN;  // PDC enable for UART 0

which sends me 12 zeroes over UART on startup.

Now, if I copy the string into an array that is in function scope:

int main()
{
    // ... some initialization stuff ...
    char buffer[100];
    int i;

    for (i = 0; i < 100 && str[i] != '\0'; ++i)
    {
        buffer[i] = str[i];
    }
    buffer[i] = '\0';

    UART0->UART_TPR = buffer;               // PDC transfer pointer
    UART0->UART_TCR = strlen(buffer);       // PDC counter
    UART0->UART_PTCR = UART_PTCR_TXTEN;     // PDC enable for UART 0

    // ... other code here ...
}

This one sends me the string "Hello world!" over UART + one random character which is easy enough to fix.

My question is, why did the first method not work?

The datasheet states that the PDC can access any of the on-chip memories, so what is going on with Flash?

Using SAM-ICE I've confirmed the obvious:

  1. The global variable's address starts with 0x004…, meaning that it resides in Flash

  2. The local buffer address starts with 0x200…, menaning that it resides in SRAM.

This problem is happening on a commercial prototype board. I do have a SAM3N4C evaluation kit board that I can rewrite the code for if you require it in order to help me but I would like to avoid that if possible.

The datasheet sections that are of interest are the following:

Section 10.5 : ARM Cortex M3 -> Memory model (10.5.2 and 10.5.3 in particular)

Section 22 : Peripheral DMA Controller

Section 29 : UART (if it is not enough information look at 30, USART, it might give some clues).

I'm not sure what to think since I'm only accessing bytes so endian-ness and alignment shouldn't be a problem. Also, the flash section in the datasheet also says that the Flash can be read in bytes so I don't see a problem. Hence, I'm turning to the community for help. Thanks in advance.

Best Answer

It seems that I did not read the section 22.2.3 of the datasheet indicating that the PDC is not connected to the Internal Flash.

My apologies for wasting the communities time.