AVR32 SPI clock frequency bug?

65 views
Skip to first unread message

Martin Guy

unread,
Oct 14, 2011, 7:14:06 AM10/14/11
to eLua Users and Development List (www.eluaproject.net), miz...@googlegroups.com
I think I've spotted a bug in the calculation of the SPI clock
frequency on AVR32:

diff --git a/src/platform/avr32/platform.c b/src/platform/avr32/platform.c
index 75a2d65..899a19a 100644
--- a/src/platform/avr32/platform.c
+++ b/src/platform/avr32/platform.c
@@ -213,10 +213,10 @@ int platform_init()
spiopt.modfdis = TRUE;
spiopt.pcs_decode = FALSE;
spiopt.delay = 0;
- spi_initMaster(&AVR32_SPI0, &spiopt, REQ_CPU_FREQ);
+ spi_initMaster(&AVR32_SPI0, &spiopt, REQ_PBA_FREQ);

#if NUM_SPI > 4
- spi_initMaster(&AVR32_SPI1, &spiopt, REQ_CPU_FREQ);
+ spi_initMaster(&AVR32_SPI1, &spiopt, REQ_PBA_FREQ);
#endif

#endif

where
int spi_initMaster(volatile avr32_spi_t *spi, const
spi_master_options_t *opt, U32 pba_hz)
{
...

which I expect would really set a frequency of one quarter of that
which was asked for (and reported) since CPU=60000000 and PBA=15000000

but I don't have any SPI hardware to test this, so before I make this
fairly obvious change, which affects all AVR32 boards, has anyone
tried SPI on any of these boards? It seems a fairly obvious error but
I wouldn't want to break something that was working... if it was
working...

M

Bogdan Marinescu

unread,
Oct 14, 2011, 7:19:25 AM10/14/11
to miz...@googlegroups.com, eLua Users and Development List (www.eluaproject.net)
Hi,
I didn't try SPI on AVR32, but your fix is obviously right because of the AVR32 system architecture (as described in the datasheet) and because of this line from spi.c:


int spi_initMaster(volatile avr32_spi_t *spi, const spi_master_options_t *opt, U32 pba_hz)

I'd go ahead with it.

Best,
Bogdan

>
>    M
>

Marcus

unread,
Oct 15, 2011, 5:11:48 AM10/15/11
to miz...@googlegroups.com
Yes, the SPI should be based on the PBA clock. It is better to correct this even if it breaks something else that work with wrong frequency.

Regards,
Marcus
Reply all
Reply to author
Forward
0 new messages