SPI driver for KINETIS K20.

ChibiOS public support forum for topics related to the Freescale Kinetis family of micro-controllers.

Moderator: utzig

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SPI driver for KINETIS K20.

Postby Giovanni » Sat Aug 23, 2014 5:23 pm

You are going really fast :)

I recommend organizing things in order to share the code among the various subfamilies or you have a lot of rework ahead, talking because experience...

Giovanni

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: SPI driver for KINETIS K20.

Postby utzig » Sat Aug 23, 2014 5:31 pm

My plan was to finish I2C and then write SPI drivers but since Derek wrote it already, my next step will be to cleanup and merge families. I think that after cleaning up it will also be quite easier to add new sub-families. And after that "harder" drivers can be written like ethernet K6x, K7x and USB (which most have).

Cheers,
Fabio Utzig

SpaceCoaster
Posts: 49
Joined: Mon Aug 11, 2014 6:40 am

Re: SPI driver for KINETIS K20.

Postby SpaceCoaster » Sat Aug 23, 2014 6:57 pm

The EXT driver should be cross compatible between KINETIS series chips but not the SPI driver judging by the register changes required.

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: SPI driver for KINETIS K20.

Postby utzig » Sat Aug 23, 2014 7:04 pm

Yep, the SPI on KL2x is very different (and it's called DSPI on the K2x...). Don't know about other families. Btw, I applied all patches (all looked very good). Only did little changes to the header file (mk20d5.h). Please check that I didn't break anything.

Fabio Utzig

SpaceCoaster
Posts: 49
Joined: Mon Aug 11, 2014 6:40 am

Re: SPI driver for KINETIS K20.

Postby SpaceCoaster » Sat Aug 23, 2014 7:14 pm

A couple of issues

When I build RT-MCHCK-K20-SPI I get

Code: Select all

main.c: In function 'main':
main.c:103:3: warning: implicit declaration of function '_pal_lld_setpadmode' [-Wimplicit-function-declaration]
   palSetPadMode(GPIOC, 5, PAL_MODE_ALTERNATIVE_2);  /* SCK  */


I think it needs an extern in pal_lld.h for _pal_lld_setpadmode.

Also the ch.bin doesn't have the KINETIS flash protection bits at 0x400. It just has random data!

I think this is because I set USE_LTO to yes. Too much optimization. With it set to no I get the protection bits and it works.

Cheers,
Derek

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SPI driver for KINETIS K20.

Postby Giovanni » Sat Aug 23, 2014 7:33 pm

Look for a missing KEEP in the scatter file.

Giovanni

colin
Posts: 149
Joined: Thu Dec 22, 2011 7:44 pm

Re: SPI driver for KINETIS K20.

Postby colin » Wed Aug 27, 2014 10:12 pm

Yeah the DSPI peripheral is an odd beast. It is on the Freescale ColdFire MCUs and also Kinetis K series but not Kinetis L. It is the DMA SPI device, which most importantly takes data 16-bits at a time. MSB is the control byte, like start or end transfer, which slave to select, etc., and LSB is the data.

It is powerful because you can queue up multiple transfers to multiple slaves etc. using just DMA with no core intervention between transfers.

It is clumsy because you can't just point the DMA at a buffer of data and send it ... you need to copy/expand it in a buffer to 16-bits wide.

The Kinetis L's SPI peripheral is perhaps less powerful in a way, but I think would ironically be more convenient for DMA implementation?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SPI driver for KINETIS K20.

Postby Giovanni » Wed Aug 27, 2014 10:46 pm

You may look at the DSPI driver in the SPC5 port, it supports both IRQ and DMA modes, not sure if it is exactly the same version of DSPI but it is the same peripheral from Freescale.

Anyway, it is really an odd beast...

fpga_comp
Posts: 16
Joined: Thu Aug 28, 2014 2:00 pm

Re: SPI driver for KINETIS K20.

Postby fpga_comp » Thu Aug 28, 2014 2:35 pm

There is a DMA SPI library for the Teensy 3.X (K20) here: https://github.com/crteensy/DmaSpi (actual code is in the DmaSpi.h header file!)
Hope that would be useful here.

As far as I can remember from the forum discussion that started that, they basically use 8-bit DMA write to the TXDATA FIFO.
http://forum.pjrc.com/threads/23253-tee ... A-nice-try

The upper control words are defaulted to all 0's. None of the fancy hardware SPI chip select stuff can be used. Those are handled in software for asserting/deasserting GPIO pins. You wouldn't care too much about that if you are doing big block of SPI transfer to a single device. You only need to toggle the chip select before and after the DMA.

SpaceCoaster
Posts: 49
Joined: Mon Aug 11, 2014 6:40 am

Re: SPI driver for KINETIS K20.

Postby SpaceCoaster » Tue Sep 02, 2014 1:52 pm

Earlier in this thread I noticed that

SpaceCoaster wrote:OK, everything looks better if the lines.

Code: Select all

__main_stack_size__     = 0x0400;
__process_stack_size__  = 0x0400;

are taken out of KL25Z128.ld and MK20DX128.ld


The attached patch removes the stack size definitions from the *.ld files and allows the rules.mk feature to work as intended.
Attachments
0001-KINETIS-Remove-stack-size-definitions.patch.gz
(524 Bytes) Downloaded 268 times


Return to “Kinetis Support”

Who is online

Users browsing this forum: No registered users and 19 guests