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?