Any update fro AN4379 MSD device bootloader?

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

Any update fro AN4379 MSD device bootloader?

Jump to solution
4,945 Views
kai_liu
Senior Contributor I

FSL has a great application note AN4379 regarding MSD device bootloader for Kirin3/Flexis JM/Kinetis K60 w/ CW, written by Derek Snell.

Additionally FSL also offers USB source for MSD device for emulated RAM and external SD card (via SPI bus) for multiple platforms.

I am looking for MSD device bootloader for KL25Z for IAR toolchain.

Is there any update for AN4379? I just want to make sure I am not going to re-invent the wheel on bootloader, ‘cause application development is my focus.

Tags (2)
1 Solution
2,862 Views
kai_liu
Senior Contributor I

UPDATE 07

The revised MSD device bootloader has been released on USB MSC device bootloader revision for FRDM-KL25Z (IAR)

The code is developed on USB stack v4.0.3 with reused functions from AN2295/AN4370. Its version has been promoted to v1.0 beta.

I have verified the project by a relocated user application starts from 0x8000. Just download them and try it on your FRDM-KL25Z.

Yours sincerely

Allan K Liu

View solution in original post

0 Kudos
Reply
21 Replies
2,863 Views
kai_liu
Senior Contributor I

UPDATE 07

The revised MSD device bootloader has been released on USB MSC device bootloader revision for FRDM-KL25Z (IAR)

The code is developed on USB stack v4.0.3 with reused functions from AN2295/AN4370. Its version has been promoted to v1.0 beta.

I have verified the project by a relocated user application starts from 0x8000. Just download them and try it on your FRDM-KL25Z.

Yours sincerely

Allan K Liu

0 Kudos
Reply
2,774 Views
Danzo
Contributor I

im having trouble importing and compiling for the kl25 processor

can some one make a CW10.3,4,5 file set ....  to upload

im getting al sorts of errors about the audio classes.....

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

I have not installed CW, so... Maybe you must check the macro definitions (for conditional build).

But I would like to propose you to use the IAR bootloader as is, if you can just use it as a black box.

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

UPDATE 06

Now code is working and verified. :smileyhappy: Finally !

There is a bug in low-level flash programming for long word. The control loop is controlled by size, which is Nr of byte. So the size = size - 4, rather than -1.

LWord FLASH_ProgramSectionByLongs(LWord destination, LWord* pSource, LWord size)

{

  //dumpBuf((unsigned char*)pSource,size,0);

  //while(size--)

  while(size)

  {

    if(FLASH_ProgramLongWord(destination, *pSource++) != FLASH_OK)

      return FLASH_FAIL;

    destination += 4;

    size -= 4;

  }

  printf("\r\n");

  return FLASH_OK;

}

In next official release, I will prepare an application note with source code as well as demo firmware and icf file.

I spent a week on porting AN4379 on FRDM-KL25Z with IAR. Although this question was posted 4 months ago.

That is another problem I solve by myself. I did wish any FSL team can help me to accelerate this process. It took too much time than my expectation.

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

UPDATE 05

There are no code update. Just sharing my latest experiences.

I move printf( ) before running low-level flash programming routines (FCCOB). The buffer dumping seems correct. From very beginning to end.

So far I have collected references manuals for K20/KL25, and I found they are not sharing same code base. There are many parallel releases from FSL teams.

Compare to K20 FTFL and K60 FTFE, KL25 has a simpler flash module called FTFA without RAM based sector programming and some other features.

But most of the basic FCCOB is same. No idea why programming failed anyway.

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

UPDATE 04 with more questions/bugs


CarlosCasillas

PabloBaena

dereksnell

Dear all,

I list you guys on my help list, 'cause I think you are experienced on this topic and can help me on AN4379 USB MSC/MSD bootloader porting to FRDM-KL25Z.

The current code base is:

  • I reuse code from USB MSD example from FSL USB stack v4.0.3 as new baseline, and I migrate AN4379 code by Derek to v4.0.3 for its FAT16/disk driver.
  • I also reuse code from AN2295 bootloader for flash routines, since I have verified that code already.
  • I reuse image project image from AN4370 DFU bootloader for downloading, S19, (0xA000~0xCA20)
  • The serial port driver has been added for debug purpose.

Current performance:

  • USB enumeration works
  • Serial port via FRDM-KL25Z works.
  • S-Record identified.
  • All S-Record stored in buffer is dumped on a terminal window

Bugs:

  • The erasing routine erase_flash() will be called twice inside the MSD_Event_Callback(), the second time will read file from very beginning even the file has not been transferred completely. (Follow-up: By disabling printf(), the OS only writes once.)
  • The buffer dumping sometimes missed some records. Different dumping, different result. I doubt it has something to do with USB interrupt. I will try to inspect internal flash memory, instead of printing out its content. (Follow-up: By disabling printf(), then I found the content have been programmed from 0xA000 to 0xCA4F, longer than our expectation, and only first 16 bytes are corret)
  • The content has not been programmed into desired address (0xA000). Before migrating code, I do find content inside flash memory, however only first 128B is correct.(Follow-up: its performance changes every time)
  • I am confused about disk.c USB_MSC_DEVICE_WRITE_REQUEST for its lba_data_ptr->offset>>9 judgement. dereksnell, could you offer some background information about it? Thanks (I can figure out the purpose of the code, I just want to know the meaning of right shift 9 times, do you have any document support that?)
  • I saw may write_request to this virtual FAT16 disk. What kind of write requests are filtered out?

Attached file:

  • demo image S19 file (usb_device_tower_.s19, starts from 0xA000, we need an image file starts from 0x8000)
  • terminal dump files (x2)
  • project zip file, (should be copied into FSL USB stack v4.0.3)



FSL USB stack is hard to share a single project, I have to zip them all. Please using compare tools carefully to avoid replacing your own version. Especially the common sources have been revised slightly.

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

UPDATE 3

The previous version fails on USB enumeration. I gave up on debugging low-level USB driver. So I re-create project on USB stack v4.0.3 with bootloader file. Now we can see BOOTLOADER driver now, but downloading firmware with wrong content.

Anyone who is interested on AN4379 on FRDM-KL25Z with IAR?

Please download and help us to remove the bugs together.

The zip file should unzipped into USB stack source tree, in following path:

X:\Freescale\Freescale USB Stack v4.0.3\Source\Device\app\

Thanks.

2,774 Views
kai_liu
Senior Contributor I

UPDATE 2

Here comes a update version. This version has famous issue "Unrecognized devices" in Windows XP. Yep, it must have bugs in USB communication. Still not a working version, available for debug only.

We are approaching our target, anyway.

Allan K Liu

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

UPDATE 1

The firmware have been merged based upon original CW for K60 to IAR for KL25Z. Also I reuse code from AN2295 for its flash driver and simple drivers for timer, watchdog and etc.

The source code is built successfully. I attach my very first version here. However, it is not a working bootloader. I have not made it working on FRDM yet.

I put it here just in case someone who need it urgently and want to debug by himself. And don't freak out if you find the source is too messy.

I will release my final code with FSL community. It will be a very simple version without verification, authentication, personalization and other features.

However I have to say. FSL should help us to develop and verify all the bootloaders, including AN2295 serial bootloader, AN4370 USB DFU bootloader, AN4379 USB MSC bootloader, as well as other bootloader including USB  host MSC bootloader, SD Card bootloader, Ethernet bootloader, CAN bootloader, I2C/SPI bootloader.

At least, FSL should align a standard driver for bootloaders, including drivers for K/KL flash memories, USB interface, serial com, file parser, FAT File system.

Yours sincerely

Allan K Liu

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

I spent one day to port this MSC/MSD bootloader to KL25Z with IAR. It is not finished yet.

And I found that it is easy to port from CW to IAR. Porting from K60 to KL25Z takes more time. They have differences in many ways, including registers in GPIO/SIM/FTFA ......

It only matters on time to delivery. It is not so difficult since we can cut and past some sources from AN2295, and it is working for KL25Z anyway.

So, my porting path is:

  1. Based upon AN4379, setup a new project with IAR
  2. Reuse AN4379 for USB MSC, bootloader parser and other high level modules.
  3. Using conditional build with macro definition (MCU_MKL25Z4), will support KL24/26/45/46 in future.
  4. Reuse flash drivers from AN2295.

The source code is messy. Too many macros are used.

Keep tuned.

0 Kudos
Reply
2,774 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi Kai,

 

I have contacted to AN4379’s author and he said me that there aren’t plans of updating the application note for supporting KL25 devices.

However, Kinetis L devices are supported on the last version of USB Stack; so, you could use the MSD stack example for KL25 as base, and adding the Bootloader support from the application note similar to the current implementations. If you have troubles with the Flash routines, you could use the C90TFS Flash driver. On the following link you can find an example for KL25 device:

    https://community.freescale.com/docs/DOC-94593

    

Hope this will be useful for you.

Best regards!

/Carlos

0 Kudos
Reply
2,774 Views
PabloBaena
Contributor III

Hi Carlos,

I've found AN4379 is a great tool not only for bootloading easily but also a great template for modifying to get another funcionalities. For example, I'm developing an application which will store some sensor data into the own MCF51JM128's flash memory and the goal is to present this few bytes as a plain text file to the PC.   With the help of FAT16 documentation I've learned how to "create" directories, files, give attributes, etc...It is all to be defined in the FAT16_RootDirSector variable. So here comes my question: how can I get to "write" the content of the file, for example some simple ascii characters inside some example.txt file and when the PC open file the content can in effect be retrieved and copied to local drive ???

Do I have to look for FAT16 cluster write methods?, And, what could be the structure inside AN4379's FAT16.c source file and SCSI functions?.  Of course I understand the given source files are not intented for a complete file system, but for emulation purposes that helps one's application and that's just great :smileyhappy:

Really appreciating your valuable comments and guidance,

Pablo B.

0 Kudos
Reply
2,774 Views
CarlosCasillas
NXP Employee
NXP Employee

Hello Pablo.

You could refer to application note AN4115, which implements the FAT file system from DEMOFLEXISJMSD board on MM/JE Flexis devices, and create/modify files stored on a SD card. This document is available at the following link:

www.freescale.com/files/microcontrollers/doc/app_note/AN4115.pdf

Hope this will be useful for you.

Best regards!

/Carlos

0 Kudos
Reply
2,774 Views
PabloBaena
Contributor III

Hello,

I managed to modify AN4379 code in order to respond to SCSI commands such as sector read, and understand the strategy corresponding to the AN's own code. Now I can generate my own plain and image files for custom applications...Very useful for low memory requirements and fast implementations not relying on additional SD Card! Just be careful with cluster and sector definitions according to FAT16 specification.

If anyone should find it useful or needs help on this, just leave me a message and will be glad to help.

Regards,

Pablo

2,774 Views
kai_liu
Senior Contributor I

Hi, Pablo,

It is great if you can share any resources like source code/library or even binary release. 

Because my project is too urgent to wait for AN4379, and MSD bootloader has a big ass (about 22KB) to fit into my board. I use AN2295 bootloader from FSL so far.

However, the original design has not been tested on FRDM-KL25Z. As a result, I changed some code and release my own tool, and my paper is here: https://community.freescale.com/docs/DOC-95429

Alternatively, BlackNight has published serial bootloader on github. mcuoneclipse/Examples/FRDM-KL25Z/FRDM_Bootloader at master · ErichStyger/mcuoneclipse · GitHub

hemingzhang

0 Kudos
Reply
2,774 Views
PabloBaena
Contributor III

Hi Kai, surely I will gladly post my results once I get my code very debugged, structured and documented for you colleagues to use it at best.

Thank you for your feedback.

Pablo

0 Kudos
Reply
2,774 Views
PabloBaena
Contributor III

Hello Carlos,

Very useful AN...

Muchas gracias!!

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

Thanks, Carlos.

I will share my work, anyway.

2,774 Views
bala_aadhav
Contributor I

Hi Kai,

Any update on your work? Curious to know...

Thanks

Bala

0 Kudos
Reply
2,774 Views
kai_liu
Senior Contributor I

Nope, sorry.

0 Kudos
Reply