Migrate Demo from TWR-K21F120M to MK22FX512VLH12

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

Migrate Demo from TWR-K21F120M to MK22FX512VLH12

Jump to solution
2,816 Views
stevenlutz
Contributor II

The TWR-K21F120M is a board listed as the dev tool for the K22FX512VLH12 chip which I have on my custom board. 

I have successfully compiled a few TWR-K21 demos and flashed the unmodified demos to the K22 chip, and to my surprise, it worked. [FlexCAN Loopback, Blinky LED, USB Host keyboard and mouse Demos]

However, when trying to use the demos as a starting point for my application and switching the MCU in the project settings, and updating the pins and clocks (either manually or importing a mex file) the demos just simply fall apart with too many errors to to correct. 

What is the proper migration method for getting the demos ported over to the chip that I'm using?

I have also started a new project based on my chips specific SDK, and ported over some basic LED functions in the board files, went through the SDK Wizard to create an SDK package specific for my board but the board files are not imported when crating a project based off of my custom SDK. 

Also, When trying to duplicate the USB demos from a fresh project, the osa folder is missing compared to the K21 SDK Demos as well as other files. Adding additional components also doesn't solve the issue. I have no idea where those files that support USB functionality are obtainable. 

Ultimately I just need a USB Host with keyboard support, and Canbus working. 
Any advice getting USB and flexcan working on my chip would greatly appreciated. 


Tags (1)
0 Kudos
1 Solution
2,693 Views
ErichStyger
Senior Contributor V

Hi @stevenlutz ,

Just for clarification / understanding. Under the projects Component Manager, Under the Operating System Tab, FreeRTOS is available for slection but... the project seems to already have FreeRTOS in it.
Where is the diconnect in McuXpresso not knowing about freertos? and will this become an issue?

The project manager reads the SDK manifest XML files, and shows what is available, and uses that information to copy the files into the project. The FreeRTOS in that project and in the McuLib is not the 'stock' FreeRTOS: the McuLib one is more advanced (like having shell support, reentrant heap and memory allocation, support for LTO, support for other architectures as RISC-V, etc). That's why it is not showing up. And it won't be an issue for your application at all.

It looks like this is all setup to be a USB Device, Rather than a Host.

Correct, it uses only the USB CDC device class. I have not used it with host device class (all our robots are devices, not host). But you certainly could port or use the K22FN512 host class files.

I hope that makes sense.

Erich

View solution in original post

0 Kudos
13 Replies
2,776 Views
ErichStyger
Senior Contributor V

We are using the K22FX512 for our robot projects (see https://mcuoneclipse.com/2014/10/30/new-sumo-robot-assembled-and-looking-good/ ), and I shared projects for it including FreeRTOS and USB here: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/MCUXpresso/K22FX512

It uses the McuLib plus the SDK, and it includes FreeRTOS. But it does not use CAN, but that should be easy to add.

 

I hope this helps,

Erich

0 Kudos
2,745 Views
stevenlutz
Contributor II

I have downloaded and imported the project you linked to and re-linked the McuLib Dir. I tried to build it and am getting the following error:

Description Resource Path Location Type
fatal error: McuLibConfig.h: No such file or directory lfs_config.h /K22FX512xxx12_McuLib/McuLib/littleFS line 10 C/C++ Problem

I haven't made any changes to your project, I'm just looking to get a successful build of your code. 
I'm using McuXpresso 11.6

Please advise.

0 Kudos
2,739 Views
ErichStyger
Senior Contributor V

I believe you somehow did not link the McuLib correctly? Did you update the Build Variable in the project?

 

Just in case: attached a zip file with the McuLib inside the project and the MCULIB variable pointing to it.

 

Erich

0 Kudos
2,722 Views
stevenlutz
Contributor II

Thank you for responding so quickly. 
But I'm still getting the same errors. I can verify that the new version has the McuLib folder locally rather than linked. I'm not sure what the issue is. 


Description Resource Path Location Type
fatal error: FreeRTOS.h: No such file or directory Application.c /K22FX512xxx12_McuLib/source line 9 C/C++ Problem
fatal error: McuLibconfig.h: No such file or directory FreeRTOShooks.c /K22FX512xxx12_McuLib/source line 8 C/C++ Problem
fatal error: McuShell.h: No such file or directory virtual_com.h /K22FX512xxx12_McuLib/usb/cdc line 57 C/C++ Problem

 

 

0 Kudos
2,721 Views
stevenlutz
Contributor II

I just updated the Build Variable for McuLib with your project that include the McuLib folder (not linked). It's now building. 

Thanks a TON! I'll start building from here... hopefully all goes well. 
How did you assemble this sample project and where did McuLib come from?
Where sis the USB support files come from as well?


0 Kudos
2,714 Views
ErichStyger
Senior Contributor V

Thanks a TON! I'll start building from here... hopefully all goes well.

You are welcome! Keeping fingers crossed.

How did you assemble this sample project and where did McuLib come from?

The project on GitHub is basically a stripped down project for the robotics projects we use at the university for partner projects and as well for education. The 'McuLib' is a long term research project and collection of files and drivers, for a plethora of of MCUs and devices, including for NXP ones. The library is available on GitHub (https://github.com/ErichStyger/McuOnEclipseLibrary ) and you can find references and examples of it in my blog (https://mcuoneclipse.com/tag/mculib/). The origin started with NXP/Freescale decision to drop Processor Expert support (https://mcuoneclipse.com/2012/07/26/there-is-a-time-and-date-for-both-worlds/ ).

Where sis the USB support files come from as well?

They are taken from the SDK for the K22FN512 (which we use as well). The USB peripheral is the same for the FX and FN part, but we have fixed a few issues in the stack and made it fully reentrant, as well usable to be used with an RTOS.

I hope this helps?

Erich

0 Kudos
2,712 Views
stevenlutz
Contributor II

This is all making a lot more sense. You work is much appreciated, I just wish that this kind of work would have been available from the top (NXP) so people like you don't have to create it and people like me don't have to go looking for it. 

Just for clarification / understanding. Under the projects Component Manager, Under the Operating System Tab, FreeRTOS is available for slection but... the project seems to already have FreeRTOS in it. 
Where is the diconnect in McuXpresso not knowing about freertos? and will this become an issue?

I've never used freertos but I'm taking this as an opportunity to dive in. I just wish I had a bit more streamline way to learn about it. I am feeling pretty lost right now and I'm not sure where to start. 


It looks like this is all setup to be a USB Device, Rather than a Host. 
Is there a built in way to make the switch or am I going to need to start over with the USB implementation?


Ultimately I need the USB in Host mode for a Keyboard input/ I don't know what is all included in this project so I'm not sure aht I'm looking for to edit. 

Getting this off the ground is proving to be quite the hurdle... but I know I'm not the best at this. However I'm determined to get this figured out. 
Any references or further info to help would be greatly appreciated. 


0 Kudos
2,694 Views
ErichStyger
Senior Contributor V

Hi @stevenlutz ,

Just for clarification / understanding. Under the projects Component Manager, Under the Operating System Tab, FreeRTOS is available for slection but... the project seems to already have FreeRTOS in it.
Where is the diconnect in McuXpresso not knowing about freertos? and will this become an issue?

The project manager reads the SDK manifest XML files, and shows what is available, and uses that information to copy the files into the project. The FreeRTOS in that project and in the McuLib is not the 'stock' FreeRTOS: the McuLib one is more advanced (like having shell support, reentrant heap and memory allocation, support for LTO, support for other architectures as RISC-V, etc). That's why it is not showing up. And it won't be an issue for your application at all.

It looks like this is all setup to be a USB Device, Rather than a Host.

Correct, it uses only the USB CDC device class. I have not used it with host device class (all our robots are devices, not host). But you certainly could port or use the K22FN512 host class files.

I hope that makes sense.

Erich

0 Kudos
2,752 Views
stevenlutz
Contributor II

Thank you for posting this as it should help although I was hoping to build my solution on bare metal without freertos. 

All in all, I'm really frustrated with the unbelievable amount of compatibility inconsistencies among the great collection of tools that nxp has, as well as improper documentation regarding proper development boards and migration processes to the intended production chips. 

I have invested a lot of time, effort and money in the nxp ecosystem over the last handful of years and having a smooth end to end development process is extremely rare and often frustrating. 




0 Kudos
2,715 Views
ErichStyger
Senior Contributor V

Thank you for posting this as it should help although I was hoping to build my solution on bare metal without freertos.

You are welcome. Just to be clear: while the McuLib includes the FreeRTOS sources, you can use it perfectly without it. There is even a setting for it:

#define McuLib_CONFIG_SDK_USE_FREERTOS              (0)

Just set it to zero, and then the drivers are not using it.

As for USB: there are certainly advantages using it *with* an RTOS, as it makes running the USB stack with the application running in parallel much easier and simpler. Keep in mind that you need to keep the USB 'system' polled/called on a periodic base, and having a dedicated task for it makes that a piece of cake.

Erich

2,711 Views
stevenlutz
Contributor II

After thinking about my application a bit more, it does make sense to keep it, I was just trying to avoid it trying to skirt around the hurdle of learning it. But in the long run I think this will be best. 
*sigh*
I'll keep it and figure it out. Thank you

0 Kudos
2,779 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello,

 

Could you please help me check the following post ? I believe that it can help you creating the base of the project you need so you will only need to adapt less elements into your application . Please let me know if that helps

 

Regards

0 Kudos
2,743 Views
stevenlutz
Contributor II

I have taken the steps for both suggested solutions. 

Erichs example doesn't work as it's having issue with this McuLib dependencies even after re-linking the dir. 

Starting a new project is an issue as it's missing the 'USB', 'osa' and 'startup' and 'utilities' directories. seemingly most important are the osa and usb dir's for USB support. I have tried adding the usb components and those folders are still missing with no obvious way to recreate the keyboard host demo. 

As an attempted workaround I started with the keyboard/mouse usb host demo for the supposedly correct dev board for my K22FX512, the TWR-K21, but can't properly port it to my chip for further modification and development. 

As you can see, I have tried 3 ways to get basic examples properly running on this chip without success. 

Very frustrated.
Please advise. 

0 Kudos