AN4368 on K60 issue

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

AN4368 on K60 issue

Jump to solution
1,412 Views
kkkk
Contributor II

I tried to use a USB MSD host bootloader on K60(MK60FN1M0VLQ12). I found the document AN4368 and followed the steps.

When I built up my project and debug on my K60 board, it can print the message"Waiting for USB mass storage to be attached".

Then I plug-in the USB flash,it doesn't work. I use the debug mode and find that it will trigger an interrupt and stop at "B Default_Handler". The Handler happens when the code goes to

if (tr_params_ptr->DEV_REQ_PTR != NULL) {

      pipe_tr_ptr->setup_packet =

         *((USB_SETUP_PTR)tr_params_ptr->DEV_REQ_PTR);

   }

of the function "_usb_host_set_up_TR" in the file "host_main.c"

I try another project"USBFS_Host"build from"KINETIS_120MHZ_SC" and get the same problem.

My K60 board can use USB host with MFS in MQX4.0.

But I need AN4368 work fine on my board without MQX.

Please help me and thanks.

Labels (2)
1 Solution
957 Views
adriancano
NXP Employee
NXP Employee

Hi,

You can refer to this document and example:

TWR-K70 MSD HOST Bootloader based on AN4368 source code

I tested the bootloader code from the above link with a TWR-K60F120M and flashed the image.S19 file that toggles a led.

Attached you can find the bootloader code with the modifications for the TWR-K60F120M, you can see the printf outputs through the OSJTAG connector on a Terminal (I used TERATERM) and the image.S19 I used to test it.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

8 Replies
958 Views
adriancano
NXP Employee
NXP Employee

Hi,

You can refer to this document and example:

TWR-K70 MSD HOST Bootloader based on AN4368 source code

I tested the bootloader code from the above link with a TWR-K60F120M and flashed the image.S19 file that toggles a led.

Attached you can find the bootloader code with the modifications for the TWR-K60F120M, you can see the printf outputs through the OSJTAG connector on a Terminal (I used TERATERM) and the image.S19 I used to test it.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

957 Views
kkkk
Contributor II

Thanks for help. But I meet another issue when K60 detect the USB flash. It goes to load_image() and fails to load. I trace the code and find that when the function "check_fs" the return vale is 2. This is caused from a failed reading of the sectors.After plug in, demo test execute check_fs(...) to read information from MBR (sector 0) and initialize fat table structures. But with some pendrives there was problems while low level reading sector (function disk_read(), the buffer out it's never written and the software scan a wrong buffer). I solve the issue after trying other USB flashs.

But I want to ask the setting of *.icf of my own project to program the flash by USB host update. According to K60N120m, do I need to change the values of __ICFEDIT_intvec_start,__ICFEDIT_region_ROM_start,__INTERNAL_FLASH_BASE,__VECTOR_TABLE_ROM_START?

I have changed the value of MAX_FLASH1_ADDRESS to 0x000FFFFF in Bootloader.h in the bootloader code.

0 Kudos
957 Views
adriancano
NXP Employee
NXP Employee

Hi,

Yes as you see one of the comments in the document post I forgot to change the MAX FLASH ADDRESS:

  arnogir Jan 22, 2015 11:52 PM

It work fine. I just need to do some correction because the Boot was Max address for a K60 (512K) no for a K70 (1M)

Then I modified following:

#define MAX_FLASH_ADDRESS 0x0007FFFF 

to

#define MAX_FLASH_ADDRESS 0x000FFFFF 

and in main.c

  1. uint_8 erase_flash(void) 
  2. /* Body */ 
  3.     uint_8 error = FALSE;
  4.     uint_8 i;
  5. [...]

to

uint_8 erase_flash(void) {   

/* Body */   

uint_8 error = FALSE;   

uint_16 i;

[...]

Thank


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

957 Views
arnogir
Senior Contributor II

Yes,

You have to convert the srec file generated, not only rename it.

In the link above, you have the step to convert the srec to an s19 file (Format S3, with limited byte per line).

If you respect the good s19 format, bootloader will work without any problem (§4 of attached document named TWR-K70 msd bootloader.pdf)

957 Views
kkkk
Contributor II

I have solve the S19 file even if it is S1or S2 format. I modified the function "FLASHLineS19" "for (i = offset; i < (length - 3); i++)" when my .srec is s1 format.

I am sure that the whole application image is written to the flash from 0x10000 after loading image.

I also find the message "Erase flash error" when function "Flash_SectorErase" trys to erase flash address 0x00100000. It causes the set of ACCERR and CCIF bit of register FTFE_FSTAT.

Although "Erase flash error" when trying erase address 0x00100000, the bootloader still can load image S19 file in S1 format and show"Flash image file complete".

But I still can't get the message from hello world project after message "User application is running"when function "switch mode" goes through

asm("mov32   r4,New_sp");

            asm("ldr     sp,[r4]");

            asm("mov32   r4,New_pc");

            asm("ldr     r5, [r4]");

            asm("blx     r5");.

The new_sp value is 0x2000FFF8 and new_pc value is 0x00010411.

Can you help me check the 1MB_Pflash.icf of hello world and MK70F120M_Flash.icf of bootloader?

Thanks.

0 Kudos
957 Views
adriancano
NXP Employee
NXP Employee

Hi,

I am tying to test this but I am not able to do it, can you please send the Hello World project and also the .elf file of it.

Than you.

Best Regards,

Adrian

0 Kudos
957 Views
kkkk
Contributor II

I download the Hello world project from http://www.freescale.com/webapp/sps/download/license.jsp?colCode=KINETIS_120MHZ_SC&prodCode=K70_120&...

and use the IAR with hellow world_K70 tower setting. I also modified the1MB_Pflash.icf in config files as I mentioned before. I only modified the Hello world project at the UART channel 3 with PTC16&17 to print debug message. The baudrate is 115200.

Thank you for trying to help me.

0 Kudos
957 Views
kkkk
Contributor II

Thanks a lot. But I have another question. I get the debug message when erase_flash happens. It prints Erase flash error when the i value is 120 in for loop. I set MAX_FLASH1_ADDRESS as 0xFFFFF, IMAGE_ADDR as 0x00000,and ERASE_SECTOR as 0x800. The erase loop should end when i value reach 0x1DF,but it always fails when i is 0x78. Even though the loop prints error message, the bootloader always shows messages as "ERASE complete" and "Flash image file complete".

Alough the message shows "Flash image file complete",it doesn't print "hello world" after the message prints"User application is running"when reboot the board.

Does "Erase flash error" affects the result of printing "hello world"?

I have change the hello world project __ICFEDIT_region_ROM_start__ as 0x00010000 and __ICFEDIT_region_ROM_end__ as 0x000FFFFF  of 1MB_Pflash.icf of KINETIS_120MHZ_SC. Other parameters are default value.

0 Kudos