Changing K22 Start Address in MCUXPresso IDE

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

Changing K22 Start Address in MCUXPresso IDE

3,125 Views
gsinde
Contributor III

I am using the FRDM-K22F development board and I have the freedom_bootloader downloaded and working on the target. I can drag and drop the "led_demo_a000" onto the bootloader via USB and everything works. So, now I try using another demo application which by default is linked to 0x0000 and not 0xA000.

I would have thought this would be an easy change but so far, I must be doing something wrong. The led demo has a custom linker script which should not be needed for such a simple change but may I am wrong? 

I attached where I thought to make the change in the IDE but it doesn't allow me to drag and drop this binary on the target. I can debug the code if I link it to 0x0000 and essentially destroy the bootloader.

Any Ideas?

0 Kudos
Reply
8 Replies

2,784 Views
gsinde
Contributor III

One more piece of info (related to why my system did not work). I set the Bootloader timeout to ZERO which I thought meant it would be immediate jump to application unless button was pressed to stay in bootloader. However, ZERO means it will never jump to my Application (aka no timeout as the comment says).

Default:

#define BL_DEFAULT_PERIPHERAL_DETECT_TIMEOUT 5000

0 Kudos
Reply

2,784 Views
gsinde
Contributor III

Ok, the secret is to not drag and drop a binary file on to the K22 Bootloader USB (FSL Loader) because I think it messes things up, you must convert it first to a SB formatted file. I can now drag and drop applications linked to 0xA000 on to the Bootloader. 

Here is how you make a command file (*.bd) and call the elftosb tool

C:\temp>type led.bd
sources {
# BIN File path
myBINFile = "frdmk22f_led_demo_freedom_a000.bin";
}

section (0) {
#1. Erase the internal flash
erase 0x0000a000..0x0010000;
#2. Load BIN File to internal flash
load myBINFile > 0xa000;
#3. Reset target.
reset;
}

C:\temp>elftosb -V -c led.bd -o image.sb
Boot Section 0x00000000:
ERAS | adr=0x0000a000 | cnt=0x00006000 | flg=0x0000
LOAD | adr=0x0000a000 | len=0x00000678 | crc=0x1a0c562d | flg=0x0000
RESET

Now, This case can be closed and I will now focus on trimming down my bootloader and moving the bootloader UART over to LPUART for my end target. 

Thanks to all,

Gary

0 Kudos
Reply

2,784 Views
gsinde
Contributor III

I found  this in the bootloader manual -

the USB MSC download only supports SB file drag-and-drop

.

So, it would assume I am messing things up by dragging and dropping binaries on the K22 Bootloader. I will start over and see how this goes after I learn how to make SB files. 

Gary

0 Kudos
Reply

2,784 Views
gsinde
Contributor III

Thanks Alexis,

Yes, I agree with you (you have great details above). I have a K20 (running OpenSDA) just as you say. I also have the Bootloader running on the K22 by drag and dropping on the OpenSDA USB Port as you suggest. However, now I can plug in the K22 USB port and it mounts as a USB device as well.

test.png

So, in theory, I can drag and drop new Applications such as the Bootloader at address 0x0000 by drag and dropping on the OpenSDA USB drive (FRDM-K22FJ) or I can drag and drop Applications like led_freedom_a0000.bin on to the Bootloader USB drive (FSL Loader) and it should program.

Having said all  of that, I will go though your detailed step by steps today and see if that works with Kinetis Flash Tools. My bootloader has UART, I2C, and SPI disabled but I can put them back in. Only USB VID/PID & USB Mass Storage options are enabled on mine.

#if !defined(BL_CONFIG_SCUART)
#define BL_CONFIG_SCUART (0)
#endif
#if !defined(BL_CONFIG_I2C)
#define BL_CONFIG_I2C (0)
#endif
#if !defined(BL_CONFIG_DSPI)
#define BL_CONFIG_DSPI (0)
#endif
#if !defined(BL_CONFIG_USB_HID)
#define BL_CONFIG_USB_HID (1)
#endif
#if !defined(BL_CONFIG_USB_MSC)
#define BL_CONFIG_USB_MSC (1)
#endif

Thank You,

Gary

0 Kudos
Reply

2,784 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Gary Sinder,

I think you're mixing concepts here, the FRDM-K22 has a K20 that function with the OpenSDA app, and the K22.

pastedImage_1.png

If you drag and drop a program to the device, you're using the K20 OpenSDA application to upload a program to the K22. This device listed as a mass storage is the K20 with the OpenSDA application.

pastedImage_2.png

If you want to program an application with other memory location different from 0x00000000 you will need the freedom_bootloader because the MCU after a reset always check the 0x00000000 location where is the vector table and the location to jump to the Reset Interrupt. You need a program to help you jump to your application, if you only upload this program to the MCU, the location 0x0000000 will not have any information.

First upload the freedom_bootloader.bin to the board, this will help you to upload your new program.

Using the led_freedom_a000 as an example, you will need the location of the RAM program to the 0xa000 using the MCUXpresso, after that create a binary for your application.

pastedImage_3.png

To upload the program, using the kinetis flash tool( the link to download MCU Bootloader | NXP) , you will find the flash tool in the next route:  ..\NXP_Kinetis_Bootloader_2_0_0\bin\Tools\KinetisFlashTool\win

Browse the image you want to download in the BCA Utilities TAB.

pastedImage_4.png

In the config button, enable the tag check box and include timeout to start your application. If you send a command throug UART, I2C, SPI, CAN or USB before the timeout, the bootloader will catch the instrucction and you will be able to upload a new program. 

pastedImage_7.png

Save the changes to the images.

pastedImage_10.png

After this, you're ready to upload your image. Go to the update tab, select the image you want to upload and select the start point of writing, if you upload the program to the 0x00000000 you will overwrite the freedom_bootloader.

pastedImage_13.png

For more information, check the documentation for MCU_boot in the next route: ..\NXP_Kinetis_Bootloader_2_0_0\doc, the Kinetis Bootloader Demo Application User's Guide has a some examples.

I hope this helps you.

Best Regards,

Alexis Andalon

0 Kudos
Reply

2,784 Views
gsinde
Contributor III

Ok, now my Demo Application doesn't work either.

From OpenSDA USB Mass Storage, I can drag and drop my blinky-125msec.bin (0x0000), my blinky-250msec.bin (0x0000), and my frdmk22f_freedom_bootloader.bin (0x0000) and they all run fine. The blinky programs blink the LED at various rates and all colors. The bootloader runs and you can plug in the K22 USB to the laptop and see the E-Drive FSL Loader (E:) but any applications (linked at 0xa000) drag and  dropped on to E: just sit there and it looks like nothing gets programmed. I unplug and reinsert the K22 USB and it still mounts as FSL Loader (E:).

I must be close...

0 Kudos
Reply

2,784 Views
gsinde
Contributor III

Hi Erich,

Thanks for the reply ( I am reading that document again to see what I may have missed )

In the Bootloader, I have the jump address set (default)

#if !defined(BL_APP_VECTOR_TABLE_ADDRESS)
#define BL_APP_VECTOR_TABLE_ADDRESS 0xa000
#endif

In the Application MAP file, I see the vector table correctly located in the text section. 

0x0000a000 __base_PROGRAM_FLASH = 0xa000
0x0000a000 __base_Flash = 0xa000
0x00080000 __top_PROGRAM_FLASH = 0x80000
0x00080000 __top_Flash = 0x80000
0x20000000 __base_SRAM_UPPER = 0x20000000
0x20000000 __base_RAM = 0x20000000
0x20010000 __top_SRAM_UPPER = 0x20010000
0x20010000 __top_RAM = 0x20010000
0x1fff0000 __base_SRAM_LOWER = 0x1fff0000
0x1fff0000 __base_RAM2 = 0x1fff0000
0x20000000 __top_SRAM_LOWER = 0x20000000
0x20000000 __top_RAM2 = 0x20000000

.text 0x0000a000 0x1718
FILL mask 0xff
0x0000a000 __vectors_start__ = ABSOLUTE (.)
*(SORT_BY_ALIGNMENT(.isr_vector))
.isr_vector 0x0000a000 0x168 ./startup/startup_mk22f51212.o
0x0000a000 g_pfnVectors
0x0000a000 __Vectors
0x0000a168 . = ALIGN (0x4)
0x0000a168 __section_table_start = .
0x0000a168 __data_section_table = .
0x0000a168 0x4 LONG 0xb718 LOADADDR (.data)
0x0000a16c 0x4 LONG 0x20000000 ADDR (.data)
0x0000a170 0x4 LONG 0x10 SIZEOF (.data)
0x0000a174 0x4 LONG 0xb718 LOADADDR (.data_RAM2)
0x0000a178 0x4 LONG 0x1fff0000 ADDR (.data_RAM2)
0x0000a17c 0x4 LONG 0x0 SIZEOF (.data_RAM2)
0x0000a180 __data_section_table_end = .
0x0000a180 __bss_section_table = .
0x0000a180 0x4 LONG 0x20000010 ADDR (.bss)
0x0000a184 0x4 LONG 0x21c SIZEOF (.bss)
0x0000a188 0x4 LONG 0x1fff0000 ADDR (.bss_RAM2)
0x0000a18c 0x4 LONG 0x0 SIZEOF (.bss_RAM2)
0x0000a190 __bss_section_table_end = .
0x0000a190 __section_table_end = .

I am not sure why the Demo project that works uses a custom linker script file instead of just letting the tool IDE control the address but there must be a reason ...

0 Kudos
Reply

2,784 Views
BlackNight
NXP Employee
NXP Employee

can you check that you don't have anything linked below the vector table address?

Check the .map file or the S19 file addresses.

Otherwise: Flash-Resident USB-HID Bootloader with the NXP Kinetis K22 Microcontroller | MCU on Eclipse 

I hope this helps,

Erich

0 Kudos
Reply