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.
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
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.
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
Hi Xing Chang,
MCUXpresso IDE v11.0.0 [Build 2516] [2019-06-05]
SDK: 2.2.1
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]
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.
Repeat the above sequence for all Build Configurations (typically Debug and Release).
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.