Hi,
I am trying to get this part working and I am coming to the same type of conclusion. It looks like there is something fishy about argument passing to functions. pass by value (e.g. in registers) looks like mostly working but when working with pointers things start to behave strangely after 4 bytes(e.g. one word).
It is also possible that something goes wrong in cache/memory handling.
I did a few experiments and would like to repeat the same experiments on a normal UART but just disabling the USB UART did gave some errors. I have a few variants but for now this examples shows the strange behavior.
The following program reliably display the following(funny enough the compiler flags use -OS but stlll do some inlining.
_;_9_a_b_c_d_e_f________
0123456789ab
fedcba9;
Here is the basic code. e.g. replacing the 3 loops with a single loop things to wrong.(I also tries some changes like setting -O0 for the compiler.
int main() {
UART_BAUD = FREQ / BAUD_RATE;
LEDS = 0xAA;
char *second="0123456789abcdef";
for (;;) {
int f=0;
for (int x =0 ; x < 16;x++) {
uart_putc('_');
uart_putc(second[f + x]);
}
uart_putc('\r');
uart_putc('\n');
for (int x =0 ; x < 4;x++) {
uart_putc(second[x]);
}
for (int x =4 ; x < 8;x++) {
uart_putc(second[x]);
}
for (int x =8 ; x < 12;x++) {
uart_putc(second[x]);
}
uart_putc('\r');
uart_putc('\n');
for (int x =11 ; x >= 0;x--) {
uart_putc(second[x]);
}
uart_putc('\r');
uart_putc('\n');
uint32_t start = rdcycle();
while ((rdcycle() - start) <= FREQ);
}
}