Programming K66 Flash over UART serial port

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

Programming K66 Flash over UART serial port

3,568 Views
nhitpad
Contributor II

 I'd like to re-programming the my NXP chip over Kinetis Flash Tool.

I try to pull up NMI to high and reset the chip. but I will can not touch to bootloader over the tool.

Here is the error message what I saw.

Error: Connect device failed(Error: Initial ping failure: No response received for ping command.).

I want to confirmed is that possible to programming the K66 inner  flash  over serial UART by Kinetis Flash Tool. if yes please tell what I can do for it. if not is there any way can achieve this. 

 

 

0 Kudos
Reply
9 Replies

3,555 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @nhitpad 

I hope you are doing well, 

The short answer is : It is possible to program your K66 over UART with the Kinetis flash tool (or BLhost  utility) 

Detailed answer is :  there are three kind of bootloaders within our Kinetis MCU:  Flash-resident , ROM resident and Flashloader. In the MCUboot  page, under the Supported Devices you will see which bootloader options are supported with our Kinetis MCUs.

The K66 does not have ROM resident bootloader, but it has Flash-resident bootloader , which  will reside  at  the beginning of the flash , reserving several KB of memory. If you consider to use this bootloader option , you must ensure that  application images are above  the bootloader  area, usually 0xA000 address.

diego_charles_1-1622740349689.png

Here I am making sure that my target application image is above the flash-resident bootloader area.

The flash-resident bootloader project for the MK66 can be found on the MCUxpresso SDK  and can be imported and flashed as a standard project ( we recommend to build the flash-loader  under release mode with optimizations to reduce its code size) . 

When you have this resident bootloader you can load the binary of your application  (with its respective offset ) as you usually do. 

Below you will find an snapshot of me using the Kinetis flash tool to load my a blinky binary at 0xA00 offset (with the FRDM-K64F). In my case I pressed the NMI pin, during reset to stop the bootloader from booting the application.

diego_charles_0-1622740302425.png

Please take a look at the documentation at MCUBOOT. Where we provide  further details

I hope this could help you.

Diego.

 

 

 

3,549 Views
nhitpad
Contributor II

HI, Diego

   Really appreciate for your quickly response. As you mentioned, to make the target application boot to bootloader module. I must create an bootloader area and put in the the correct memory address.

I still have a little uncertainly how to create it. Could you provide the sample code to me about how create the bootloader image. if could ,could you please also give me the memory link script of the bootloader image that I can reference.     

0 Kudos
Reply

3,540 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @nhitpad

Just a point that I forgot to mention : on the K66 SDK, the flash-resident bootloader is named as frdmk66f_freedom_bootloader. 

Regarding the creation of the image, there is a sample project that you can check frdmk66f_led_demo_freedom_a000 .  You can find its linker script directly following this path:  frdmk66f_led_demo_freedom_a000->middleware->mcu-boot.  (Depending your toolchain its location may change a bit, but that's for the MCUXpresso IDE)

I recommend you to take a look at the MCU Bootloader Demo Applications
User's Guide There you will find relevant information how to use the bootloader to load an application image. Also, regarding the 0xA000 offset for the image, chapter 7.1 Memory map overview will be useful to  visualize  the use of the memory by the application and the bootloader.

To move and application to the 0xA000 with ease, in the MCUXpresso IDE, you can go to project properties->MCU settings-> Memory details and adjust the base address of the flash.

I hope it helps,

Diego.

0 Kudos
Reply

3,522 Views
nhitpad
Contributor II

HI ,  Diego 

   Thanks for you response but I still can not made my board  too bootloader mode.I tried to reprogramming the FW as blow I Programming both Freedeom_bootlaoder and led_demo_freedeom_a000. I've set update the start address for both led_demo_freedom_a000.

Set application image (led_demo_freedeom_a000)

        Set on project Explorer  Project_settings ==> Memory ==>edit memory ==> change flash location to 0xa000. Size to 0x200000.  Build image and create binary image 

No change for the Freedeom_bootlaoder  and build image and create binary image.(start from 0x0000) 

 

Programming step 

1. using J-Flash Lite programming the Freedeom_bootlaoder start from 0x00

2. Programming the application image(led_demo_freedeom_a000) 

3. PULL high NMI and press rest Switch. 

4. Sen command  blhost -p COM5 -- get-property 12

5. ==> Get  Error: Initial ping failure: No response received for ping command. 

Did I do any operation wrong .

 Thanks 

Kent Yeh 

0 Kudos
Reply

3,518 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @nhitpad 

Thank you for your reply!

Ok, could you check if you have the same serial pins that the K66 bootloader uses?

See Table 9. MK66F18 bootloader – FRDM-K66F

Also , Double check the boot-pin for the K66 bootloader , see  Figure 24. FRDM-K66F platform  , on the FRDM-K66F the boot-pin corresponds to the SW3, which is PTA10, actually it is not NMI. 

diego_charles_0-1623122917451.png

Let me know your findings

All the best

Diego.

 

0 Kudos
Reply

3,463 Views
nhitpad
Contributor II

Hi , Diego.

  Sorry for  take so long time to response. Because of we met some of the hardware level issue. 

On the board. We have discuss with the PIN but according the hardware design is already there. 

I can not heck the board for SW 3.   Therefore I want to check is there any SW level way to led the board to boot loader mode.

I have 2 question wait to check wit you.

1 . From the Kite tool is there is any way can control and PTA 10 over Software level ?( or using bhost)

2. In my current design I can control the PIN PTA4. Is there any way I can bypass the PTA 4 to PTA10  to handling the PIN status?

 

Thanks 

Kent Yeh 

3,441 Views
nhitpad
Contributor II

Hi, Diego

  Becasue of hardware is there , I only can use MCU_State0 and UART0 from PTA for bootloader test. 

Try try to change the code from the Bootloader example code from SDK. but it still doesn't work. 

Need your help on this.

Here is the change what I did: 

 Boot Pin change :

      under baord/pin_mux.h

              #define BOOT_PIN_SW3_GPIO GPIOA /*!<@brief GPIO device name: GPIOA */
             #define BOOT_PIN_SW3_PORT PORTA /*!<@brief PORT device name: PORTA */
             #define BOOT_PIN_SW3_PIN 4U /*!<@brief PORTA pin index: 10 */

      under baord/pin_mux.c    

           PORTA->PCR[4] = ((PORTA->PCR[4] &
          /* Mask bits to zero which are setting */
            (~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_ISF_MASK)))

         /* Pull Select: Internal pullup resistor is enabled on the corresponding pin, if the
          * corresponding PE field is set. */
          | (uint32_t)(kPORT_PullUp));

For  Serial port change:

   under baord/pin_mux.h

        void UART0_InitPins(void);

      /*! @@name PORTB16 (coord E10), U7[4]/UART0_R
      @{ */
      #define UART0_RESTOREDEFAULT_RX_PORT PORTA /*!<@brief PORT device name:         PORTB */ 
     #define UART0_RESTOREDEFAULT_RX_PIN 15U /*!<@brief PORTB pin index: 16 */
/* @} */

    /*! @name PORTB17 (coord E9), U10[1]/UART0_TX
  @{ *
   #define UART0_RESTOREDEFAULT_TX_PORT PORTA /*!<@brief PORT device name:    PORTB */
    #define UART0_RESTOREDEFAULT_TX_PIN 14U /*!<@brief PORTB pin index: 17 */

  Could you specific tell me anything I missed for the change. 

 

Thanks 

Kent Yeh

0 Kudos
Reply

3,384 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @nhitpad 

I think that you will also need to corroborate the following defines for the default boot pin  the file hardware_init_MK66F12.c. For example, those are for the MK64 bootloader.

 

#define BOOT_PIN_NUMBER 6
#define BOOT_PIN_GPIO GPIOC

 

The function  is_boot_pin_asserted() checks for the state of the boot pin of the bootloader, using the  BOOT_PIN_NUMBER define.  That's  why this definitions are required .

 

bool is_boot_pin_asserted(void)
{
#ifdef BL_TARGET_FLASH
    BOARD_InitBootPin();

    uint32_t readCount = 0;

    // Sample the pin a number of times
    for (uint32_t i = 0; i < BOOT_PIN_DEBOUNCE_READ_COUNT; i++)
    {
        readCount += ((BOOT_PIN_GPIO->PDIR) >> BOOT_PIN_NUMBER) & 1;
    }

    // boot pin is pulled high so we are measuring lows, make sure most of our measurements
    // registered as low
    return (readCount < (BOOT_PIN_DEBOUNCE_READ_COUNT / 2));
#else
    // Boot pin for Flash only target
    return false;
#endif
}

 

Please accept my apologies as well for the late response (I have missed your reply to an error in the system). Probably , in the meantime,  you did completed this modification to your bootloader.

Let me hear from you.

Diego.

 

 

0 Kudos
Reply

3,170 Views
nhitpad
Contributor II

 

Hi, Diego 

Thanks  for your response , actually I still have some other issue want to check.

1. as you response   

#define BOOT_PIN_NUMBER 6

This one should be  4 right right ? because the MCU_state pin is PTA4. So it should be number 4 or there is other definition for it ?

Also I have one issues I 'd like to change the boot UART port from UART0( original bootloader define) to UART 4.  

2 tings need your help:

1. Because of I am not using EVK for test and my test board is using external clock. Should I modified the BOARD_BootClockRUN_PEE(void) to external clock definition?

2. To change the UART port from 0 to 4 

I direct replace the UART0 to UART 4 as follow. 

But it still doesn't work could you specific tell me does there have any place I also need to change.

void UART4_InitPins(void)
{

/* Port B Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC);

const port_pin_config_t UART4_RX = {/* Internal pull-up/down resistor is disabled */
kPORT_PullDisable,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Pin is configured as UART0_RX */
kPORT_MuxAlt3,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORTD2 (pin C4) is configured as UART2_RX */
PORT_SetPinConfig(PORTC, 14U, &UART4_RX);

const port_pin_config_t UART4_TX = {/* Internal pull-up/down resistor is disabled */
kPORT_PullDisable,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Pin is configured as UART0_TX */
kPORT_MuxAlt3,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORTD3 (pin B4) is configured as UART2_TX */
PORT_SetPinConfig(PORTC, 15U, &UART4_TX);

SIM->SOPT5 = ((SIM->SOPT5 &
/* Mask bits to zero which are setting */
(~(SIM_SOPT5_UART0TXSRC_MASK)))

/* UART 0 transmit data source select: UART0_TX pin. */
| SIM_SOPT5_UART0TXSRC(SOPT5_UART0TXSRC_UART_TX));

0 Kudos
Reply