FRDMk64 internal flash write problem

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

FRDMk64 internal flash write problem

1,883 Views
sudhakarp
Contributor V

Hi,

i am using FRDMk64f120, kds 2.0 and KSDk 1.1.0 example.i tried flash demo example project. example project working fine.

bt when i write 8 byte data its writing data successfully. but when i write 7byte or 15 byte data i am getting error. its supporting only multiple of

8 byte only like 8,16,24,32 byte.

i want to write byte by byte how to do that one.

ret = FlashProgram(&flashSSDConfig, destination, 8, &exist_params, g_FlashLaunchCommand);    //this time success

ret = FlashProgram(&flashSSDConfig, destination, 7,  &exist_params, g_FlashLaunchCommand);  //this time ERROR


is any other API function available for flash writing..?


thanks and regards,

sudhakar p

0 Kudos
8 Replies

791 Views
DavidS
NXP Employee
NXP Employee

​To learn about the flash programming do's and don'ts please review the K64 Reference Manual Flash chapter.

In summary the K64 must write/program 8bytes at a time and not more or less.

Another warning:

A flash memory location must be in the erased state before being programmed. Cumulative programming of bits (back-to-back program operations without an intervening erase) within a flash memory location is not allowed. Re-programming of existing 0s to 0 is not allowed as this overstresses the device.

Regards,

David

0 Kudos

791 Views
sudhakarp
Contributor V

Hi,

     i did external flash read/write program code(AT45DB161) throught SPI communication using KSDK 1.2.0 dspi loopback example project. its working fine. i can able to write and read data from External flash.but after i intergrated that code into ethernet_to_serial project its not working.i am using KDSK1.1.0 ethernet_to_serial example project.am using KDS 2.0 IDE.

     i think its related to OSA_Init(); function but am not sure. because MQX OSA_init() function different from what i used in KSDK 1.2.0 OSA_init().

KSDK 1.2.0 OSA_init()

osa_status_t OSA_Init(void)

{

#if (TASK_MAX_NUM > 0)

    task_init();

#endif

#if (FSL_OSA_BM_TIMER_CONFIG != FSL_OSA_BM_TIMER_NONE)

    OSA_TimeInit();

#endif

    return kStatus_OSA_Success;

}

KSDK 1.1.0 OSA_init()     //but this is MQX

osa_status_t OSA_Init(void)

{

    #if MQX_CUSTOM_MAIN

        extern MQX_INITIALIZATION_STRUCT MQX_init_struct;

        return MQX_OK == mqx_init(&MQX_init_struct) ? kStatus_OSA_Success : kStatus_OSA_Error;

    #else //* MQX_CUSTOM_MAIN

       return kStatus_OSA_Success;

  #endif //* MQX_CUSTOM_MAIN

}

     and also in my code MQX_CUSTOM_MAIN  0 (was zero). so its simply return success.

my code also hanging after calling " DSPI_DRV_MasterTransferBlocking()" function, this following comment mentioned in KSDK 1.2.0 dspi_loopback example code.

// Init OSA layer, used in DSPI_DRV_MasterTransferBlocking.

    OSA_Init();

can you tell what exact problem what changes i want to do?

thanks and regards,

sudhakar p

0 Kudos

791 Views
RadekS
NXP Employee
NXP Employee

Hi Sudhakar,

Idea: Could you please check task priorities?

There is priority level shift between MQX priority level and OSA priority level.

MQX RTOS Priority = OSA Priority + 7

So, if you use combination of OSA and MQX tasks, priories should be set accordingly this fact.

Some more details about this topic you can find in chapter 6.7.2 Adjust task priorities of Porting an MQX RTOS Application to MQX RTOS for Kinetis SDK document.


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos

791 Views
sudhakarp
Contributor V

hi,

     i made it work. but unexpected problem coming i dnt know why. if i call all API function in single function its working fine.(all DSPI init and write, read function). i made seperate function for DSPI initialization , data_write and data_read that time its not working i dnt know why.

that code i added below.

WORKING CODE:

void DSPI_init()

{

uint32_t dataLength, numBytes;

    uint8_t statusRegister;

    dspi_status_t spiStatus;

    uint8_t i,data_w;

dspi_master_user_config_t userConfig;

userConfig.isChipSelectContinuous = true;

userConfig.isSckContinuous = false;

userConfig.pcsPolarity = kDspiPcs_ActiveLow;

userConfig.whichCtar = kDspiCtar1;//kDspiCtar0;

userConfig.whichPcs = kDspiPcs1;//kDspiPcs0;

/* Init the DSPI module */

dspi_master_state_t dspiMasterState;

dspi_status_t status = DSPI_DRV_MasterInit(SPI_INSTANCE, &dspiMasterState, &userConfig);

/* Define bus configuration */

dspi_device_t spiDevice;

spiDevice.dataBusConfig.bitsPerFrame = 8;

spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_SecondEdge;//kDspiClockPhase_FirstEdge;

spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveLow;//kDspiClockPolarity_ActiveHigh;

spiDevice.dataBusConfig.direction = kDspiMsbFirst;

spiDevice.bitsPerSec =  500000;

/* Configure the SPI bus */

uint32_t calculatedBaudRate;

status = DSPI_DRV_MasterConfigureBus(SPI_INSTANCE, &spiDevice, &calculatedBaudRate);

/* Configure pins for SPI */

configure_spi_pins(SPI_INSTANCE);

/* SPI use interrupt, must be installed in MQX and file fsl_dspi_irq.c must not be included in project */

int32_t IRQNumber = g_dspiIrqId[SPI_INSTANCE];

_int_install_isr(IRQNumber, (INT_ISR_FPTR)DSPI_DRV_MasterIRQHandler, (void*)SPI_INSTANCE);

   data_w='A';

    while(1)

        {

            printf("\n\rgoing to write data");

            write_backup_data(data_w);          //INSIDE THIS FUNCTION AM CALLING                                                                        // "DSPI_DRV_MasterTransferBlocking"

            data_w=read_backup_data();

            printf("\n\rF_data=%c",data_w);

            _time_delay(1500);

        }

}

NOT WORKING CODE:

same code only i am calling different function for read/write

void DSPI_init()

{

uint32_t dataLength, numBytes;

    uint8_t statusRegister;

    dspi_status_t spiStatus;

    uint8_t i,data_w;

dspi_master_user_config_t userConfig;

userConfig.isChipSelectContinuous = true;

userConfig.isSckContinuous = false;

userConfig.pcsPolarity = kDspiPcs_ActiveLow;

userConfig.whichCtar = kDspiCtar1;//kDspiCtar0;

userConfig.whichPcs = kDspiPcs1;//kDspiPcs0;

/* Init the DSPI module */

dspi_master_state_t dspiMasterState;

dspi_status_t status = DSPI_DRV_MasterInit(SPI_INSTANCE, &dspiMasterState, &userConfig);

/* Define bus configuration */

dspi_device_t spiDevice;

spiDevice.dataBusConfig.bitsPerFrame = 8;

spiDevice.dataBusConfig.clkPhase = kDspiClockPhase_SecondEdge;//kDspiClockPhase_FirstEdge;

spiDevice.dataBusConfig.clkPolarity = kDspiClockPolarity_ActiveLow;//kDspiClockPolarity_ActiveHigh;

spiDevice.dataBusConfig.direction = kDspiMsbFirst;

spiDevice.bitsPerSec =  500000;

/* Configure the SPI bus */

uint32_t calculatedBaudRate;

status = DSPI_DRV_MasterConfigureBus(SPI_INSTANCE, &spiDevice, &calculatedBaudRate);

/* Configure pins for SPI */

configure_spi_pins(SPI_INSTANCE);

/* SPI use interrupt, must be installed in MQX and file fsl_dspi_irq.c must not be included in project */

int32_t IRQNumber = g_dspiIrqId[SPI_INSTANCE];

_int_install_isr(IRQNumber, (INT_ISR_FPTR)DSPI_DRV_MasterIRQHandler, (void*)SPI_INSTANCE);

}

void read_write_external_data()

{

while(1)

        {

            printf("\n\rgoing to write data");

            write_backup_data(data_w);          //INSIDE THIS FUNCTION AM CALLING                                                                        // "DSPI_DRV_MasterTransferBlocking"

            data_w=read_backup_data();

            printf("\n\rF_data=%c",data_w);

            _time_delay(1500);

        }

}

so if i did like that my code was hanging i dnt know why? can you give some solution for this.

same code only i dnt know why..? or i want to initialize every read/write ?

thanks and regards,

sudhakar p

0 Kudos

791 Views
sudhakarp
Contributor V

Hi David,

     using  this Flash demo example code only i am planning to write bootloader code. i am storing my application

code in External data flash. from external data flash using flash demo code am planning to write my application code into internal data flash. i cant expect always my code size will be multiple of 8byte so how to solve this problem. do u have any any bootloader code related to this one? its useful to me.

thanks and regards,

sudhakar p

0 Kudos

791 Views
RadekS
NXP Employee
NXP Employee

Hi Sudhakar,

Yes, Flash driver in KSDK could work only with data sizes dividable by phrase size.

Phrase size is defined by FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE macro in MK64F12_features.h file.

Flash driver in KSDK is just low level driver with minimum abstraction.

On other side, flashX driver in MQX4.2 is high level driver – we simply use fopen, fseek, write(),…functions, and the rest is handled automatically by flashX driver. You can use it as inspiration…

In fact, if you want update one byte/word inside already written phrase, you will have to allocate buffer in RAM with one flash sector size (4Kbytes for MK64), load whole sector from flash to RAM, erase this sector, modify sector data in RAM and write whole sector back to flash.

From this point of view, flash swap is good solution for firmware update. You simply write new code to unused flash block(s) and after that you will swap blocks mutually.

On other side, FlexNVM (emulated EEPROM) is right solution for cases where we want often updating some parameters.

I hope it helps you.

Have a great day,
RadekS

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

0 Kudos

791 Views
sudhakarp
Contributor V

Hi,

if i change

FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE  1 Byte

it will work..? is this condition it will support 1byte write?. do u have any bootloader code working with KDS2.0 IDE then i can easily understand. i need bootloader code for custom board. if any UART bootloader code available?

thanks and regards,

sudhakar p

0 Kudos

791 Views
RadekS
NXP Employee
NXP Employee

Hi Sudhakar,

No, modification of FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE macro will not work.

This macro describes hardware ability of flash module.

You have to program flash per phrases (8bytes) or more (Section programming) and that phrase/section must be erased prior programming. Flash sector is minimum part of flash which could be erased.

About bootloader)

KSDK do not contain bootloader example code, however you could use Kinetis Bootloader|Freescale

This includes a KDS project for K64.

There are other examples about bootloader implementations for your reference, such as AN2295 (UART bootloader):

http://www.freescale.com/files/microcontrollers/doc/app_note/AN2295.pdf

http://www.freescale.com/files/microcontrollers/doc/app_note/AN2295SW.zip


I hope it helps you.

Have a great day,
RadekS

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

0 Kudos