I'm writing some custom firmware for a 25 year old system based on the MCF5206.
I find myself completely unable to transmit any data from UART1, using polling of the USR register, rather than interrupts.
My UART initialisation code looks like this:
volatile SIM_UART* u = &_sim_base->UART1;
u->UCR = UART_UCR_RESET_RECEIVER;
u->UCR = UART_UCR_RESET_TRANSMITTER;
u->UCR = UART_UCR_RESET_MODE;
u->UCR = UART_UCR_RESET_ERROR;
u->UCR = UART_UCR_RESET_BREAK;
u->UIPCR_UACR = 0; // IEC = 0
u->UISR_UIMR = 0; // no interrupts
u->USR_UCSR = 0xdd; // use timer for rx/tx clock
// set clock for 31250 baud
const uint16_t ubg = 33000000 / (32 * 31250);
u->UBG1 = (ubg >> & 0xff;
u->UBG2 = (ubg >> 0) & 0xff;
u->UMR = 0x13; // UMR1: 8 bits, no parity
u->UMR = 0x07; // UMR2: 1 stop bit
u->UCR = UART_UCR_TX_ENABLE;
and my transmit code like this:
volatile SIM_UART* u = &_sim_base->UART1;
uint32_t count = 0;
uint8_t led = 0x40;
*io_u35 = 0x20;
while ((u->USR_UCSR & UART_USR_TX_READY) == 0) {
*io_u35 = led;
if (++count == 50000) {
count = 0;
led = 0x40 - led;
}
}
u->URB_UTB = n;
The code inside the UART write loop is just there to flash a front panel LED every 50k times around the loop. The loop never exits, so it seems TxRdy is never getting asserted.
I found a post relating to the 5213 saying that the UARTs don't work right after a power-on-reset, but the proposed fix (writing to the Reset Control Register) doesn't exist on the 5206.
Am I missing something fundamental about how to use the transmit interface?
I've tracked down the problem - it appear to be related to my definition of `_sim_base` with its address specified in my linker script:
_sim_base = 0x20000000;
and imported in C code with:
extern volatile SIM* _sim_base;
It works if I use this instead:
static volatile SIM* _sim_base = (void*)0x20000000;
I can't be sure yet, but it appeared that with my original code the system was trying to read the contents of 0x20000000 to find `_sim_base`, rather than treating that as an absolute address in its own right.
I'm working from the 5206 User Manual and the original firmware for the unit.
My code looks *very* similar to that from AN2168, albeit some of the writes done in a different order. I'll try new code based on AN2168 shortly.