The AN12218SW uses the following code to change the baudrate:
/* Calculate baud settings u32Baud = 19200*/
pUART->BAUD |= LPUART_BAUD_OSR(15);
u16Sbr = (u32SysClk/u32Baud)/16;
pUART->BAUD |= LPUART_BAUD_SBR(u16Sbr);
This works for the default bootloader values as the calculated OSR/SBR value overlaps with the non-zero reset value. It is however not universal (at all!).
It would have been better if the AN12218SW would have used:
/* Calculate baud settings*/
pUART->BAUD = (pUART->BAUD & ~LPUART_BAUD_OSR_MASK) | LPUART_BAUD_OSR(15);
u16Sbr = (u32SysClk/u32Baud)/16;
pUART->BAUD = (pUART->BAUD & ~LPUART_BAUD_SBR_MASK) | LPUART_BAUD_SBR(u16Sbr);
It took me way to long to figure out the registers were non-zero. Especially OSR is very very wrong as it will always be 15 with the supplied code.
Solved! Go to Solution.
Thanks for sharing this, I will report it as well.
Thanks,
Lukas