User avatar
Arjan
Posts: 265
Joined: Sat Sep 08, 2012 1:59 pm

Setting UART clock is not reliable with latest firmware

Mon Nov 28, 2016 5:34 pm

Hi,

After updating the firmware for working with the Raspberry Pi 2 V1.2 (a.k.a. 2B+), the PL011 FIQ is mostly unreliable.
It applies for all models. The issue seems to be with the firmware upgrade to support the Raspberry Pi 2 V1.2 and changing the default UART CLOCK speed.

The good scenario :
I set the UART clock to 3MHz using the Set Clock Rate mailbox tag.
Then set the IBRD/FBRD with the correct values to support 31250 baud.

The bad scenario :
I set the UART clock to 4MHz using the Set Clock Rate mailbox tag.
Then set the IBRD=1/FBRD=0 to support 250000 baud.
=> Mostly it does not work. I get it working by switching off/on the Raspberry Pi multiple times.

I am pretty lost here. What could have been changed in the firmware which makes the 4Mhz setting unreliable?

Many thanks in advance,
Arjan
Last edited by Arjan on Thu Dec 01, 2016 5:53 pm, edited 2 times in total.
http://www.raspberrypi-dmx.org/
Open Source DMX/RDM/MIDI/OSC/Art-Net/sACN solutions

User avatar
Ultibo
Posts: 160
Joined: Wed Sep 30, 2015 10:29 am
Location: Australia
Contact: Website

Re: PL011 UART0 FIQ not reliable with latest firmware

Thu Dec 01, 2016 12:38 am

Hi Arjan,
Arjan wrote:I set the UART clock to 4MHz using the Set Clock Rate mailbox tag.
I'm wondering if there is a reason you set the UART clock to 4MHz rather than just using the Get Clock Rate mailbox tag to ask for the current value and then calculate the divisor based on that? By default the PL011 UART clock rate now seems to be 48MHz so you should be able to set any baud rate you need from that.

Are you able to confirm that the call to Set Clock Rate is actually successful?

I have support for handling FIQ in the Ultibo project but I've never tried it with the UART, it would be quite easy to test so if you don't get any answers to your question let me know.
Ultibo.org | Make something amazing
https://ultibo.org

Threads, multi-core, OpenGL, Camera, FAT, NTFS, TCP/IP, USB and more in 3MB with 2 second boot!

User avatar
Arjan
Posts: 265
Joined: Sat Sep 08, 2012 1:59 pm

Re: PL011 UART0 FIQ not reliable with latest firmware

Thu Dec 01, 2016 5:50 pm

Hi Ultibo, thanks for your reply. Much appreciated.
I'm wondering if there is a reason you set the UART clock to 4MHz rather than just using the Get Clock Rate mailbox tag to ask for the current value and then calculate the divisor based on that?
At any time, a 4MHz clock is perfect and I can just set the IBRD=1/FBRD=0 to support the 250000 baud.
By default the PL011 UART clock rate now seems to be 48MHz so you should be able to set any baud rate you need from that.
The 48Mhz is a new default for the latest firmware. All firmware releases prior the Raspberry Pi 2 V1.2 support do set the UART clock to 3MHz.
Are you able to confirm that the call to Set Clock Rate is actually successful?
When I read the UART clock back after setting to 4Mhz, then is returns the 4MHz as expected. So from the ARM point of view it is all OK. However, it seems that on the other side, the setting is not honored. As I believe this is a bug in the firmware, I have opened an issue accordingly (https://github.com/raspberrypi/firmware/issues/689). I need to update the issue with my findings.

I have coded a quick workaround for the firmware bug. With the assumption that the default is always a 48Mhz clock :

Code: Select all

	uint32_t ibrd = 12;
	if (bcm2835_vc_get_clock_rate(BCM2835_VC_CLOCK_ID_UART) == 3000000) {
		(void) bcm2835_vc_set_clock_rate(BCM2835_VC_CLOCK_ID_UART, 4000000);// Set UART clock rate to 4000000 (4MHz)
		ibrd = 1;
   }
The full code is here : https://github.com/vanvught/rpidmx512/b ... dmx.c#L715

Thanks, Arjan
http://www.raspberrypi-dmx.org/
Open Source DMX/RDM/MIDI/OSC/Art-Net/sACN solutions

Return to “Bare metal, Assembly language”