Problem using UART within bootloader code.
Hi all. I have a weird problem that has me baffled. I am migrating a project that uses a pair of PIC32MX695s to a new hardware version using a single PIC32MZ2048EFM144. I have a non-harmony stack (Oryx) running on the new hardware, along with most of my application. I'm using MPLAB v5.05 and XC32 v2.10.
The last major step I have is to get the bootloader working. I actually have most of it going, with the bootloader in boot flash and the application in program memory, but flash programming is not there yet. In an effort to debug, I want to send text to a UART (UART4 in this case) from within the bootloader. I am already using UART4 all over the application for that purpose. Using exactly the same code in the bootloader, I can't get squat. As soon as the bootloader jumps to the application it's fine.
System setup, clocks, port init, remap pins and UART setup are exactly the same as the application. Here's the serial code:
void serial_init(uint32_t brate)
//Configure UART4 (8 bits, no parity, 1 stop bit)
U4STA = 0;
//Enable high-speed mode
U4MODE = _U4MODE_BRGH_MASK;
U4BRG = ((40000000 / 4) / brate) - 1;
U4MODESET = _U4MODE_ON_MASK;
//Enable transmitter and receiver
U4STASET = _U4STA_UTXEN_MASK | _U4STA_URXEN_MASK;
void putb(unsigned char dat)
unsigned int maxwt;
//Wait for the transmitter to be ready but don't hang
maxwt = 10000;
while (!(U4STA & _U4STA_TRMT_MASK) && maxwt--);
U4TXREG = dat;
// Wait for the transfer to complete
maxwt = 10000;
while(!(U4STA & _U4STA_TRMT_MASK) && maxwt--);
Is there something else required to access peripherals from code in the bootloader area? I did run into a similar problem trying to set up SPI4 for the spi flash but I just bit banged that instead (which worked).