KL25Z and Sensor Fusion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL25Z and Sensor Fusion

Jump to solution
4,750 Views
andrewhartnett
Contributor II

Hi Mike,

 

I'm relatively new to Freescale and Sensor Fusion. I have a project working on a custom board with a KL25Z128VFM4. It's driving a string of LEDS, reading some switches, and monitoring a battery voltage with an ADC. The board also includes an FXOS8700CQ accelerometer and magnetometer, and an FXAS21002 gyroscope. I built the initial software using SDK1 and processor expert, and can configure and read the sensors (I2C) and manage all the other components, but now I want to integrate the Sensor Fusion Software. I thought an approach would be to build a bare metal version using the V7 Sensor Fusion on the FRDMKL25Z with the AGM01 board and get that working with the Sensor Fusion toolbox, then port it to my board. But I'm struggling to work out where to begin. I built a SDK2.0 package for the KL25Z128, and downloaded it, and can create a new project using it with the 2.0 wizard. I've read the print of the pages from the Rev 2 of the User Guide, but am still unclear how to proceed. Is there a document I'm missing somewhere that will provide some direction? Do I just have to import all appropriate source and headers into the project, modify the main with main_baremetal.c, configure the build.h, and go from there?

 

Thanks for any help!

Labels (1)
1 Solution
4,245 Views
michaelestanley
NXP Employee
NXP Employee

Andrew,

I appreciate the status update.  It makes my day when I know someone has successfully included the library into their design.

Regards,

Mike

View solution in original post

0 Kudos
Reply
22 Replies
3,927 Views
michaelestanley
NXP Employee
NXP Employee

Remember the Borg in Star Trek the Next Generation?  Well, we (as in the Sensor Fusion project) have been assimilated by KSDK.  Along with the many benefits, it also places some limitations on us as to how we field example applications.  The initial 7.00 release within KEx only supports K22F and K64F out of the box.  BUT, if you build your K25Z KSDK based on the FRDM-KL25Z-A8471 kit pulldown, and check the ISSDK option, you will get the sensor fusion code included (I just checked).  But it does not have a reference design.  Let me see if I can pull one together for you.  Do you prefer IAR or KDS?

Mike

3,927 Views
andrewhartnett
Contributor II

Thanks Mike - a reference design would be great - KDS please.

I realized that the V7 was (so far!) for the K22 and K64, but did build and download for the K25 and selected the ISSDK option and got the Sensor Fusion code - and then stalled! I think I can work it out but the work involved looks fairly daunting! Any help is much appreciated,

Andy

3,927 Views
michaelestanley
NXP Employee
NXP Employee

Andy,

I am working on an example for you, but it's taking a bit longer than I expected because I had forgotten that the KL25Z UART0 uses a different driver.  I've got to roll a slightly different version of the control subsystem to adapt for that.  So please give me another day.

To address your earlier question about the process:

  1. Always start with a known working example.  I'm using the K64F with MULT2B shield as my reference.
  2. Copy an existing driver example within the KSDK as a starting point.
  3. I use a 2 screen environment on my PC.  One of the screens for the reference, the other for the new project.  It helps tremendously.
  4. Add <baseboard>.h, <shield>.h and issdk_hall.h to match your hardware.  Use the working example as a reference.
  5. Start pulling in files from your reference, and discarding files used by the old driver.
  6. Check all include paths in the project Options dialog.
  7. MCU dependencies are all at the subsystem level as described in the user guide.  The sensor fusion SPI/I2C drivers use CMSIS level drivers that are currently available for only a few MCUs.  This is one place the porting gets difficult today.  Eventually, the CMSIS drivers should be available across most of the KEx environment.  The UART interface is the one that caught me on this project.  UART0 is "special".

The fusion code is basically hardware agnostic.  All hardware dependencies are contained within the headers in (4) above, plus subsystems and sensor drivers.  There's quite a bit of discussion on that in the sensor fusion user guide.

Regards,

Mike

3,927 Views
michaelestanley
NXP Employee
NXP Employee

Andrew, I uploaded a bare metal IAR project in a separate posting.  The FreeRTOS version isn't ready for prime time yet, as I need to bring RAM requirements down.

FYI, I also found that when using the "all algorithms" build at 40Hz fusion rate, I encountered problems in the dynamic behavior in the 9-axis build.  So the version I posted is ONLY 9-axis at 25Hz.  That seems to be better behaved.

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

Thanks Mike - but I'm hoping that IAR is a typo - did you mean KDS?

0 Kudos
Reply
3,927 Views
michaelestanley
NXP Employee
NXP Employee

No, I meant IAR.  Since you didn't specify, I went with my default tool.  I'll try to pull together a KDS version for you. 

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

Thanks - I did specify - I guess you missed it - first line of my reply on the 24th!

I really appreciate all the work so far - I've been working along attempting to make progress myself! Quite a steep learning curve though.

0 Kudos
Reply
3,927 Views
michaelestanley
NXP Employee
NXP Employee

You did.  I must have read it half a dozen times.  Sorry.

I'm working on it now.  Unfortunately KDS and I do not get along well, so although I now know exactly what file changes need to be brought in place, getting the configuration in the tool correct is taking some time.

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

No worries! I know how that happens.

0 Kudos
Reply
3,927 Views
michaelestanley
NXP Employee
NXP Employee

Andrew,

Check out the latest posting.  I hope it gets you moving forward.

To get this working on KL25Z, I had to create new versions of:

  • control.c
  • driver_KDSK_NVM.c
  • driver_pit.c

All dealt with differences in the KSDK between flavors of Kinetis.

As noted earlier, I built for a 25Hz fusion rate, 9-axis only.  Otherwise, everything will match what you see in the user manual.

Regards,

Mike

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

Mike  - thought you might like to know, - I got the bare metal version running on our board today, using the FRDMKL25Z opensda to program it and to communicate to the pc. I had to switch to uart0, as the uart1 pins on our board are used for other functions. Had some challenges getting the uart running correctly, but eventually worked out that set status wasn't configured in sfg - so changed the order of the initialization in main, and it worked fine. Then had to run uart connections from our board to the FRDM board. Also had to reroute the i2C pins, but then all works and talks to the Sensor fusion tool box! Thanks again for your help.

0 Kudos
Reply
4,246 Views
michaelestanley
NXP Employee
NXP Employee

Andrew,

I appreciate the status update.  It makes my day when I know someone has successfully included the library into their design.

Regards,

Mike

0 Kudos
Reply
3,927 Views
dinofarina
Contributor II

Hi Mike,

I'm in sort of the same boat as Andrew but can't seem to find the code you posted for the project.  Could you let me know where I might find it?

Many thanks,

-Dino

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

Dino - I think it's attached to the posting from Mike a month ago labeled 'Bare Metal KL25Z KDS Sensor Fusion 7.00'.

Regards, Andy

0 Kudos
Reply
3,927 Views
michaelestanley
NXP Employee
NXP Employee

Correct.

0 Kudos
Reply
3,927 Views
dinofarina
Contributor II

Great, thanks Andrew and Mike!

-Dino

0 Kudos
Reply
3,927 Views
dinofarina
Contributor II

Hi Mike,

Anything in particular (besides what is in the SensorFusion Guide) I should consider in migrating your code over to run on FreeRTOS for the FRDM-KL25Z or for the FRDM-KL27Z as we're looking at possibly using a KL17Z for production?

Thanks,

-Dino

0 Kudos
Reply
3,927 Views
michaelestanley
NXP Employee
NXP Employee

Dino,

Make sure you pick a KL17Z variant with sufficient RAM/Flash.  Pay attention to which UART variant (standard or low power) is used for the OpenSDA port (which affects the control subsystem implementation), and especially pay attention to physical alignment of the sensors on the PCB.  There are a couple of existing NXP applications notes on the topic of PCB layout considerations for accel and mag.  Make sure whoever does the layout is familiar with them.

Mike

0 Kudos
Reply
3,927 Views
dinofarina
Contributor II

Thx Mike, will do!

-Dino

0 Kudos
Reply
3,927 Views
andrewhartnett
Contributor II

Got it running Mike - many thanks for all your help!

0 Kudos
Reply