Flash write is always failing in MKW36 controller.

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

Flash write is always failing in MKW36 controller.

1,806 Views
mahadeva_hn
Contributor I

Flash write is failing in -Os optimisation but the same code is working for any other optimisation.

Can any one of you help me with this bug.

0 Kudos
7 Replies

1,558 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Mahadeva, I hope you're doing well!

 

It is not encouraged to use the usual optimization configurations for the KW36 family of MCUs, as they can mess with the BLE Stack and some of its components, and functionality may not work as intended.

The recommended way to minimize the storage space used by the application is to choose the reduced version of the BLE Host library, depending on if the device is going to act as a Peripheral or a Central device.

 

This can be seen explained in section 3.4 of the BLE Application Developer's Guide, found in the following path:

<…\SDK_2.2.2_FRDM-KW36\docs\wireless\Bluetooth\Bluetooth Low Energy Application Developer Guide.pdf>

 

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 Kudos

1,558 Views
mahadeva_hn
Contributor I

Hi Sebastian,

I am not at all using BLE stack, We are using this MCU as a Gateway.

Flash program is working properly in other than -Os optimisation. I am seeing this issue only in -Os optimisation.

steps following for flash programming,

1) FLASH_Erase

2) FLASH_Program

Can you please confirm flash write will not work in -Os optimisation.

0 Kudos

1,558 Views
xing_chang
NXP Employee
NXP Employee

Hi Mahadeva,

What IDE do you use, MCUXpresso or IAR?

Can you reproduce this issue with the flash driver project?  DIR: boards\frdmkw36\driver_examples\flash

0 Kudos

1,558 Views
mahadeva_hn
Contributor I

Hi Xing Chang,

MCUXpresso IDE v11.0.0 [Build 2516] [2019-06-05]

SDK: 2.2.1

0 Kudos

1,558 Views
xing_chang
NXP Employee
NXP Employee

Hi Mahadeva,

I cannot reproduce your issue with latest MCUXpresso and SDK, can you try it with my setup.

SDK: 2.2.2  release_conn_ksdk_2.2_kw35a_1.3.6_RC3.2

Project: ...sdk\boards\frdmkw36\driver_examples\flash\flexnvm_dflash

MCUXpresso IDE v11.1.0 [Build 3209] [2019-12-12]

0 Kudos

1,558 Views
mahadeva_hn
Contributor I

Hi Xing chang,

I switched the C library from __REDLIB__ to __NEWLIB__, after this my code is working fine.

To switch between library I followed the below steps.

    1. Select the project in Project Explorer
    2. Right-click and select Properties
    3. Expand C/C++ Build and select Settings
    4. In the Tools settings tab, select Miscellaneous under MCU C Compiler. Note that Redlib is not available for C++ projects
    5. In Use Library headers, select Newlib or Redlib
    6. In the Tools setting tab, select Architectcure & Headers under MCU Assembler
    7. In Library headers, select Newlib or Redlib

 

Repeat the above sequence for all Build Configurations (typically Debug and Release).

 

  • To then change the libraries actually being linked with (assuming you are using Managed linker scripts):

 

    1. Select the project in Project Explorer
    2. Right-click and select Properties
    3. Expand C/C++ Build and select Settings
    4. In the Tools settings tab, select Managed Linker Script under MCU Linker
    5. In the Library drop-down, select the Newlib, NewlibNano or Redlib library variant that you require (None, Nohost, Semihost).
    6. In the Tools settings tab, select Miscellaneous under MCU Linker. remove linker flags "--sort-section=alignment" and "--cref".
0 Kudos

1,558 Views
myke_predko
Senior Contributor III

Can you give a description of the code (and development system) you're using?  

I'm using SDK 2.3.1 for the MK22FN1M0Axxx12 and found that you cannot just "write" the Flash, assuming that you are only changing "1"s to "0"s.  You need to erase the sector before writing to it, which means that you need to have an image of the sector in SRAM before you erase the sector.  My method for writing to a sector (which is effectively the ONLY size unit that you can read and write) is:

uint32_t flashSectorEraseWrite(flash_config_t* flashConfig
                             , uint32_t sector
                             , uint32_t* source) {
uint32_t returnValue = FLASH_RESPONSE_NOERROR;


  __disable_irq();
  if (kStatus_FLASH_Success !=

        FLASH_Erase(flashConfig
                  , sector
                  , FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
                  , kFLASH_ApiEraseKey)) {
    returnValue = FLASH_RESPONSE_WRITEFAILURE;
  }
  __enable_irq();
  if (FLASH_RESPONSE_NOERROR == returnValue) {
    __disable_irq();
    if (kStatus_FLASH_Success !=

          FLASH_Program(flashConfig
                      , sector
                      , source
                      , FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE)) {
      returnValue = FLASH_RESPONSE_WRITEFAILURE;
    }
    __enable_irq();
  }

  return returnValue;

}

Note that you may have to use different APIs depending on the SDK that you are using and select the block (0 or 1) explicitly rather than using the single API that covers either block that I am using.  

0 Kudos