KL27z getting crash on program booting from ROM(bootloader) using blhost reset command

cancel
Showing results for 
Search instead for 
Did you mean: 

KL27z getting crash on program booting from ROM(bootloader) using blhost reset command

1,297 Views
rafaeltoledo
Contributor III


Hi,

I'm developing a application to update my firmware using the kinetis blHost.

I'm using the kl27z256, so in my program i have a way to enter in ROM bootloader to update the firmware by the blHost.exe

CODE:

void (*runBootloader)(void * arg);

  uint32_t runBootloaderAddress;

    // Read the function address from the ROM API tree.

  runBootloaderAddress = **(uint32_t **)(0x1c00001c);

  runBootloader = (void (*)(void * arg))runBootloaderAddress;

  // Start the bootloader.

  runBootloader(NULL);

This call works fine, I get the uc on ROM bootloader, and can execute the update using the commands from CMD on windows10:

blhost.exe -u 0x15a2,0x073 flash-erase-all

blhost.exe -u 0x15a2,0x073 write-memory 0 my_test_program.bin

blhost.exe -u 0x15a2,0x073 reset

Note:
I tested the same steps in FRDM-KL27, and got success, my new program (my_test_program.bin version to kl27z64) executes normally.

But on my board using the kl27z256, when i use the command "blhost reset", my new program

(my_test_program.bin version to kl27z256), got stopped after PE_low_level_init(), if I power off and power on the power supply(5V Vcc) to force a reset on my board, the new program works fine.

But I need to jump to program without remove the power supply.

I have enabled:

-UART

-PIT

-LPTMR

-USB HID

-SPI

-ADC

-LPUART

all this modules are enabled on my firmware. I'm using KDS 3.0.0, with KSDK 1.2.0. and PEx.

Have any step that I forgot to perform?

Have another way to jump from ROM bootloader to my program using the blhost?

Labels (1)
0 Kudos
12 Replies

402 Views
JeremyWood
Contributor II

I think I'm having the same or similar problem, but using SDK 2.0 + kl27z256 (or kl27z128 if it will fit).

Is this fix still relevant? And where and how would I apply it?

Thank you,

Jeremy Wood

0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,

I'd highly recommend you to create a new thread to describe the issue, then share the link with me.

Thanks for your cooperation.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

402 Views
JeremyWood
Contributor II
0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Rafael,

According to the commands which had been illustrated above, I find that you choose the USB HID to update the application, in another word, you already initialized the USB module (Fig 1).

blhost.exe -u 0x15a2,0x073 flash-erase-all

blhost.exe -u 0x15a2,0x073 write-memory 0 my_test_program.bin

blhost.exe -u 0x15a2,0x073 reset

2016-06-07_11-22-22.jpg

So it may causes some issues when reinitialize the USB module.
Have a great day,

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

402 Views
rafaeltoledo
Contributor III

Hi jeremyzhou,

Thanks alot for the help.

Really the problem is the ''dirt'' that comes from initialized USB on bootloader.

How I resolve this?

I'm trying to force the USB0 registers to default value at the beginning of my code, but the same problem occours when I try write a value to any usb register.

Any suggestion?

0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Rafael,

Thanks for your reply.

After had investigated the issue more deeper, I'd like to suggest that disable the clock of the USBFS module prior to the PE_low_level_init(), then kind registers of the USBFS module will come back to the default value after been enabled again.

So you can insert the code below to work it out.

SIM_SCGC4 &=(~SIM_SCG4_USBFS_MASK);

Hope it helps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Rafael,

Thanks for your reply.

After verified it, the MCU doesn't jump out the debug mode after inject the reset command.

So I'd highly recommend you to figure out which the code line the MCU stuck in by using the usage of step into function.

It's easy to illustrate the root cause of issue by implement the approach.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

402 Views
rafaeltoledo
Contributor III

Hi jeremyzhou,

thanks for the help.

I'm testing what's causing the program halt after command reset, and I found this thread on forum:

KL27Z Bootloader ROM problems

The reply from Mark Butcher helped me alot.

Now i'm testing component by component instantiated on my code, and for my surprise, when I disabled all code related about my USB HID, the reset command works fine.

I'm reading capter 13(Kinetis ROM bootloader) from KL27Z reference manual, to understand the bootloader better

You have any suggestion for study the problem resolution?

0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Rafael,

After had a brief look through the statement, I have some queries and I'll appreciate a lot if you can clarify them.

1. Does the MCU stuck after the PE_low_level_init() when debug the MCU?

2. I was wondering if you can share the codes of the PE_low_level_init() function.

3. What's the differences between the FRDM-KL27 and your own board?
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

402 Views
rafaeltoledo
Contributor III

Hi jeremyzhou,

thanks for the reply,

answering your questions:

1- to know that crashed after the function, I set up an LED on the board. And I can see that executes the code, but the impression I have is that run only once the main loop

3- I think the major difference is the MCU, i'm using kl27z256, and FRDM uses kl27z64, but at the same time I think that difference is only flash memory capacity. Obviously I have a whole set of hardware necessary for my project, but with reference to the CPU, this is the main difference.

I was checking out, and I noticed that the versions of the bootloader are different, this interferes?

FRDM:

command executed:

     blhost.exe -u 0x15a2,0x0073 get-property 1

response:

     Inject command 'get-property'

     Response status = 0 (0x0) Success.

     Response word 1 = 1258356992 (0x4b010100)

     Current Version = K1.1.0

On my board:

command executed:

     blhost.exe -u 0x15a2,0x0073 get-property 1

response:

    Inject command 'get-property'

     Response status = 0 (0x0) Success.

     Response word 1 = 1258356736 (0x4b010000)

     Current Version = K1.0.0

2- PE_low_level_init() is automatically generated from Processor Expert,to initialize added components

void Components_Init(void)

{

  /*! lpTmr1 Auto initialization start */

  OSA_InstallIntHandler(LPTMR0_IRQn, LPTMR0_IRQHandler);

  LPTMR_DRV_Init(FSL_LPTMR1,&lpTmr1_State,&lpTmr1_lptmrCfg0);

  LPTMR_DRV_InstallCallback(FSL_LPTMR1,lpTmr1_OnTimerCompare);

  /*! lpTmr1 Auto initialization end */

  /*! UART Auto initialization start */

  OSA_InstallIntHandler(UART2_FLEXIO_IRQn, UART_IRQHandler);

  UART_DRV_Init(FSL_UART,&UART_State,&UART_InitConfig0);

  UART_DRV_InstallRxCallback(FSL_UART, UART_RxCallback, &dadoRX, NULL, true);

  /*! UART Auto initialization end */

  /*! PIT Auto initialization start */

  OSA_InstallIntHandler(PIT_IRQn,  PIT_IRQHandler);

  PIT_DRV_Init(FSL_PIT,true);

  PIT_DRV_InitChannel(FSL_PIT,FSL_PIT_CHANNEL,&PIT_256Hz);

  PIT_DRV_StartTimer(FSL_PIT,FSL_PIT_CHANNEL);

  /*! PIT Auto initialization end */

  /*! hid1 Auto initialization start */

  (void)USB_Class_HID_Init(USBFMW1_USB_CONTROLLER_ID, &hid1_HidConfigStructure, &hid1_HidHandle);

  /*! hid1 Auto initialization end */

  /*! SPI Auto initialization start */

  SPI_DRV_MasterInit(FSL_SPI, &SPI_MasterState);

  SPI_DRV_MasterConfigureBus(FSL_SPI, &SPI_MasterConfig0, &SPI_calculatedBaudRate);

  /*! SPI Auto initialization end */

 

  /*! ADC Auto initialization start */

  ADC16_DRV_Init(FSL_ADC, &ADC_InitConfig0);

  ADC16_DRV_ConfigConvChn(FSL_ADC, 0U, &ADC_ChnConfig0);

  /*! ADC Auto initialization end */

 

  /*! SPI_ADS Auto initialization start */

  SPI_DRV_MasterInit(FSL_SPI_ADS, &SPI_ADS_MasterState);

  SPI_DRV_MasterConfigureBus(FSL_SPI_ADS, &SPI_ADS_MasterConfig0, &SPI_ADS_calculatedBaudRate);

  /*! SPI_ADS Auto initialization end */

 

  /*! GPIO Auto initialization start */

  OSA_InstallIntHandler(PORTCD_IRQn,  GPIO_PORTC_IRQHandler);

  GPIO_DRV_Init(GPIO_InpConfig0,GPIO_OutConfig0);

  /*! GPIO Auto initialization end */

 

  /*! pwrMan1 Auto initialization start */

  OSA_InstallIntHandler(LLWU_IRQn, pwrMan1_llwuIRQHandler);

  POWER_SYS_Init(powerConfigsArr, 2U, powerStaticCallbacksConfigsArr, 2U);

  POWER_SYS_SetWakeupPin(kPowerManagerWakeupPin6, kLlwuExternalPinFallingEdge, NULL);

  INT_SYS_EnableIRQ(LLWU_IRQn);

  /*! pwrMan1 Auto initialization end */

  /*! lpuartCom1 Auto initialization start */

  OSA_InstallIntHandler(LPUART0_IRQn, lpuartCom1_IRQHandler);

  LPUART_DRV_Init(FSL_LPUARTCOM1,&lpuartCom1_State,&lpuartCom1_InitConfig0);

  LPUART_DRV_InstallRxCallback(FSL_LPUARTCOM1, lpuartCom1_RxCallback, &dado_gps_RX, NULL, true);

  /*! lpuartCom1 Auto initialization end */

}

0 Kudos

402 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Rafael,

Thanks for your reply.

I'd like to suggest you to configure the the bit field BOOTSRC_SEL=00 at the 0x40D by using the write-memory <addr> [<file> | {{<hex-data>}}] command after program the BIN file to the flash, then execute the reset command.

With the approach, the MCU can boot from the flash directly and please give a shot.
Have a great day,

Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

402 Views
rafaeltoledo
Contributor III

Hi jeremyzhou,

I'm tested the follow simple project:

int main(void)

/*lint -restore Enable MISRA rule (6.3) checking. */

{

       int bootloader = 0;

       /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/

       PE_low_level_init();

       /*** End of Processor Expert internal initialization.                    ***/

       while(!GPIO_DRV_ReadPinInput(GPIOC1))

       {

            OSA_TimeDelay(1000);

            bootloader++;

            if(bootloader > 10)

            {

                  void (*runBootloader)(void * arg);

                  uint32_t runBootloaderAddress;

                  // Read the function address from the ROM API tree.

                  runBootloaderAddress = **(uint32_t **)(0x1c00001c);

                  runBootloader = (void (*)(void * arg))runBootloaderAddress;

                  // Start the bootloader.

                  runBootloader(NULL);

            }

       }

       while(1)

       {

              GPIO_DRV_ClearPinOutput(LED1_GREEN);

              OSA_TimeDelay(500);

              GPIO_DRV_SetPinOutput(LED1_GREEN);

              OSA_TimeDelay(500);

       }

  /* Don't write any code pass this line, or it will be deleted during code generation. */

  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

  #ifdef PEX_RTOS_START

    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

  #endif

  /*** End of RTOS startup code.  ***/

  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/

  for(;;){}

  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/

} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */

This works on my board, but I dont initialize any other component, just the GPIO.

When I flash this code using blhost.exe, i can use reset command, and this reboot and launch my program, blinking the led or entering in bootloader by pressing button for 5secs.

My original project dont works, and the write to BOOTSRC returns a error:

>> blhost.exe -u 0x15a2,0x0073 write-memory 0x40D {{0x00}}

Inject command 'write-memory'

Successful generic response to command 'write-memory'

(1/1)100% Completed!

Response status = 101 (0x65) kStatus_FlashAlignmentError

Wrote 2 of 2 bytes.

>> blhost.exe -u 0x15a2,0x0073 read-memory 0x40D 1

Inject command 'read-memory'

Successful response to command 'read-memory'

3f

(1/1)100% Completed!

Successful generic response to command 'read-memory'

Response status = 0 (0x0) Success.

Response word 1 = 1 (0x1)

Read 1 of 1 bytes.

0 Kudos