Boot from flash

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

Boot from flash

Jump to solution
1,783 Views
onurdemirel
Contributor III

Hello there,

I am using a custom board with MKE18F512VLH16 that is the 64 pinout and 512kb Flash memory version. I am using MCUXpresso v10.2. I want to boot my controller from flash memory. I have some problems about this issue.

I made a research about this issue and found a figure (Figure 3. Boot Flow Chart) in KE1xF datasheet: Technical Data document in subject 2.1.5. I need to set RCM_FM[FORCEROM] bits to 00 that means Boot from Flash as it says in Kinetis KE1xF Sub-Family Reference Manual subject 24.3.5. After that I need to program the FTFE_FOPT register properly as it explains in 22.3.1. However this FOPT register is a Read-only register.

In my situation, I only able to use Debug Mode to program and run my code. I set RCM_FM[FORCEROM] bits to 00 and I press reset button that pulls down the RESET_b pin[63] to GND. Afterwards it doesnt boot with the same program. When I use Debug Mode again and look to memory location of RCM_MR register it shows 0x06 in LSB; that means: "Boot from ROM due to both BOOTCFG0 pin assertion and FOPT[7] configuration" that is written in 24.3.5. RCM_FM register shows 0x04 that means: Force boot from ROM with RCM_MR[2] set.

As far as I read it says BOOTCFG0 and NMI pins and same and multiplexed that is PTD3[45]. Its voltage is 0.33V after and during pushing the reset button.

I am looking forward to how I can change FTFE_FOPT register [BOOTSRC_SEL] and [BOOTPIN_OPT] bits; or any other solutions for this issue.

Thanks in advance,

BR

Onur

Labels (1)
Tags (2)
1 Solution
1,285 Views
mjbcswitzerland
Specialist V

Onur

It is not possible to change flash configuration values using the in-circuit programming (actually it is but it would need the complete first sector to first be backed up in SRAM, modified accordingly and written back, which is risky since power loss during the process would cause program loss).

The method to use is to change it in the code.

If you use MCUXpresso's SDK it can be done by modifying the startup file called something like "startup_mke18f.c" at the following location:


//*****************************************************************************
// Flash Configuration block : 16-byte flash configuration field that stores
// default protection settings (loaded on reset) and security information that
// allows the MCU to restrict access to the Flash Memory module.
// Placed at address 0x400 by the linker script.
//*****************************************************************************

__attribute__ ((used,section(".FlashConfig"))) const struct {
    unsigned int word1;
    unsigned int word2;
    unsigned int word3;
    unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF7DFE};

You need to work out what the bytes mean by studying the users manual and then adjusting the bits accordingly.

Or you can modify this to do it in a more maintainable and portable fashion by creating a struct and some meaningful defines (as the uTasker project has done since 2011).

Regards

Mark

View solution in original post

4 Replies
1,285 Views
mjbcswitzerland
Specialist V

Onur

You need to define the BOOT ROM (along with NMI)  in the flash configuration (stored in program Flash in the address range 0x400..0x40f). This is "latched" to the read-only registers at boot to determine the start-up behavior.

In the uTasker project there is a user define:

#define KINETIS_FLASH_CONFIGURATION_NONVOL_OPTION  (FTFL_FOPT_LPBOOT_CLK_DIV_1 | FTFL_FOPT_RESET_PIN_ENABLED | FTFL_FOPT_BOOTSRC_SEL_FLASH | FTFL_FOPT_BOOTPIN_OPT_DISABLE | FTFL_FOPT_NMI_DISABLED) // never use boot ROM and disable NMI pin

In the NXP library code it is in an assembler file that needs to be calculated and modified manually.

Regards

Mark


Kinetis: http://www.utasker.com/kinetis.html
Kinetis KE:
- http://www.utasker.com/kinetis/FRDM-KE02Z.html
- http://www.utasker.com/kinetis/FRDM-KE02Z40M.html
- http://www.utasker.com/kinetis/FRDM-KE04Z.html
- http://www.utasker.com/kinetis/FRDM-KE06Z.html
- http://www.utasker.com/kinetis/FRDM-KE15Z.html
- http://www.utasker.com/kinetis/TWR-KE18F.html
- http://www.utasker.com/kinetis/HVP-KE18F.html

1,285 Views
onurdemirel
Contributor III

Hello Mark,

Thanks for your reply. I assume I understood your explanation about Flash memory and the register. I got the point that I should change the part in the Flash memory, located in 0x40C.

As I said I am using MCUXpresso with its own SDK. Things are a bit different then utasker because the that flash option byte could not be set like you said. I know what to set but I couldn't figure out how to set it. That byte is said read-only and blocks me to write into it. I am trying to set it using FLASH library functions i.e. FlashProgram() but not sure that I am using it correctly. 

I am still working on it, further help will be appreciated. Thanks in advance.

Regards,

Onur

0 Kudos
1,286 Views
mjbcswitzerland
Specialist V

Onur

It is not possible to change flash configuration values using the in-circuit programming (actually it is but it would need the complete first sector to first be backed up in SRAM, modified accordingly and written back, which is risky since power loss during the process would cause program loss).

The method to use is to change it in the code.

If you use MCUXpresso's SDK it can be done by modifying the startup file called something like "startup_mke18f.c" at the following location:


//*****************************************************************************
// Flash Configuration block : 16-byte flash configuration field that stores
// default protection settings (loaded on reset) and security information that
// allows the MCU to restrict access to the Flash Memory module.
// Placed at address 0x400 by the linker script.
//*****************************************************************************

__attribute__ ((used,section(".FlashConfig"))) const struct {
    unsigned int word1;
    unsigned int word2;
    unsigned int word3;
    unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF7DFE};

You need to work out what the bytes mean by studying the users manual and then adjusting the bits accordingly.

Or you can modify this to do it in a more maintainable and portable fashion by creating a struct and some meaningful defines (as the uTasker project has done since 2011).

Regards

Mark

1,285 Views
onurdemirel
Contributor III

Mark,

Thanks for your explanation. The first paragraph widen my horizon and I understand the reason of the problems that I faced.

I solve my problem with your help. I changed the byte in startup file 

__attribute__ ((used,section(".FlashConfig"))) const struct {
    unsigned int word1;
    unsigned int word2;
    unsigned int word3;
    unsigned int word4;
} Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFF7BFE};

I used the option you explained; 

never use the boot room: FOPT[1] = 1 and FOPT[7] = 0

disable NMI pin: FOPT[2] = 0

I am not sure that I am that much experienced to modify the code as you explained but this method is fine for now.

Have a nice day,

Onur

0 Kudos