0
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ It's sufficiently common for all memory and I/O devices in a system to share a bus, that situations where some devices can't communicate with others can be confusing. Other people with similar problems may be helped if they encounter your question and answer. \$\endgroup\$
    – supercat
    May 17, 2013 at 20:42
  • \$\begingroup\$ Thanks, in that case I will leave it up and mark as solved. \$\endgroup\$ May 19, 2013 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.