Hello I have two question regarding the FLASH_Program from the fsl_flash files. When the memory is 0xFFFFFFFF (empty) the FLASH_Program is able to write it and then as the firmware tries to program it again, it fails. And the function FLASH_Program does not crash and the result is kStatus_Success. Why?
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*******************************************************************************
* Includes
******************************************************************************/
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_flash.h"
#include "fsl_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define BUFFER_LEN 4
/*******************************************************************************
* Prototypes
******************************************************************************/
void error_trap(void);
void app_finalize(void);
/*******************************************************************************
* Variables
******************************************************************************/
/*! @brief Flash driver Structure */
static flash_config_t s_flashDriver;
/*! @brief Buffer for program */
static uint32_t s_buffer[BUFFER_LEN];
/*! @brief Buffer for readback */
static uint32_t s_buffer_rbc[BUFFER_LEN];
/*******************************************************************************
* Code
******************************************************************************/
/*
* @brief Gets called when an error occurs.
*
* @details Print error message and trap forever.
*/
void error_trap(void)
{
PRINTF("\r\n\r\n\r\n\t---- HALTED DUE TO FLASH ERROR! ----");
while (1)
{
}
}
/*
* @brief Gets called when the app is complete.
*
* @details Print finshed message and trap forever.
*/
void app_finalize(void)
{
/* Print finished message. */
PRINTF("\r\n End of PFlash Example \r\n");
while (1)
{
}
}
/*!
* @brief Use Standard Software Drivers (SSD) to modify pflash.
*
* @details This function uses SSD to demonstrate flash mode:
* + Check pflash information.
* + Erase a sector and verify.
* + Program a sector and verify.
*/
int main(void)
{
status_t result; /* Return code from each flash driver function */
uint32_t destAdrss; /* Address of the target location */
uint32_t i;
uint32_t pflashBlockBase = 0;
uint32_t pflashTotalSize = 0;
uint32_t pflashSectorSize = 0;
/* Init hardware */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
/* Clean up Flash driver Structure*/
memset(&s_flashDriver, 0, sizeof(flash_config_t));
FLASH_SetProperty(&s_flashDriver, kFLASH_PropertyFlashClockFrequency, 20000000U);
/* Setup flash driver structure for device and initialize variables. */
result = FLASH_Init(&s_flashDriver);
if (kStatus_FLASH_Success != result)
{
error_trap();
}
/* Get flash properties*/
pflashBlockBase = s_flashDriver.PFlashBlockBase;
pflashTotalSize = s_flashDriver.PFlashTotalSize;
pflashSectorSize = s_flashDriver.PFlashSectorSize;
/* print welcome message */
PRINTF("\r\n PFlash Example Start \r\n");
/* Print flash information - PFlash. */
PRINTF("\r\n PFlash Information: ");
PRINTF("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);
PRINTF("\r\n Program Flash Sector Size:\t%d B, Hex: (0x%x) ", pflashSectorSize, pflashSectorSize);
/* Debug message for user. */
/* Erase several sectors on upper pflash block where there is no code */
PRINTF("\r\n Erase a sector of flash");
/* In case of the protected sectors at the end of the pFlash just select
the block from the end of pFlash to be used for operations
SECTOR_INDEX_FROM_END = 1 means the last sector,
SECTOR_INDEX_FROM_END = 2 means (the last sector - 1) ...
in case of FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP it is
SECTOR_INDEX_FROM_END = 1 means the last 2 sectors with width of 2 sectors,
SECTOR_INDEX_FROM_END = 2 means the last 4 sectors back
with width of 2 sectors ...
*/
#ifndef SECTOR_INDEX_FROM_END
#define SECTOR_INDEX_FROM_END 1U
#endif
/* Erase a sector from destAdrss. */
#if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
/* Note: we should make sure that the sector shouldn't be swap indicator sector*/
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize * 2));
#else
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
#endif
result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
if (kStatus_FLASH_Success != result)
{
error_trap();
}
/* Print message for user. */
PRINTF("\r\n Program a buffer to a sector of flash ");
/* Prepare user buffer. */
for (i = 0; i < BUFFER_LEN; i++)
{
s_buffer[i] = i;
}
/* Program user buffer into flash*/
result = FLASH_Program(&s_flashDriver, destAdrss, s_buffer, sizeof(s_buffer));
if (kStatus_FLASH_Success != result)
{
error_trap();
}
#if defined(__DCACHE_PRESENT) && __DCACHE_PRESENT
/* Clean the D-Cache before reading the flash data*/
SCB_CleanInvalidateDCache();
#endif
/* Verify programming by reading back from flash directly*/
for (i = 0; i < BUFFER_LEN; i++)
{
s_buffer_rbc[i] = *(volatile uint32_t *)(destAdrss + i * 4);
if (s_buffer_rbc[i] != s_buffer[i])
{
error_trap();
}
}
PRINTF("\r\n Successfully Programmed and Verified Location 0x%x -> 0x%x \r\n", destAdrss,
(destAdrss + sizeof(s_buffer)));
FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFLASH_ApiEraseKey);
app_finalize();
return 0;
}
Hello, my name is Pavel, and I will be supporting your case, could you let me know about the number of your MCU? and What kind of example are you using? is the flash iap?
Best regards, Pavel
0
项奖励
回复
'
var data = div.getElementsByClassName("video-js");
var script = document.createElement('script');
script.src = "https://players.brightcove.net/" + data_account + "/" + data_palyer + "_default/index.min.js";
for(var i=0;i< data.length;i++){
videodata.push(data[i]);
}
}
}
for(var i=0;i< videodata.length;i++){
document.getElementsByClassName('lia-vid-container')[i].innerHTML = videodata[i].outerHTML;
document.body.appendChild(script);
}
}
catch(e){
}
/* Re compile html */
$compile(rootElement.querySelectorAll('div.lia-message-body-content')[0])($scope);
}
if (code_l.toLowerCase() != newBody.getAttribute("slang").toLowerCase()) {
/* Adding Translation flag */
var tr_obj = $filter('filter')($scope.sourceLangList, function (obj_l) {
return obj_l.code.toLowerCase() === newBody.getAttribute("slang").toLowerCase()
});
if (tr_obj.length > 0) {
tr_text = "内容由 lilicon-trans-text 使用 AI 辅助工具翻译".replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='查看原文';
try {
if ($scope.wootMessages[$rootScope.profLang] != undefined) {
tr_text = $scope.wootMessages[$rootScope.profLang].replace(/lilicon-trans-text/g, tr_obj[0].title);
tr_text +='查看原文';
}
} catch (e) {
}
} else {
//tr_text = "This message was translated for your convenience!";
tr_text = "lilicon-trans.your.convenience";
}
try {
if (!document.getElementById("tr-msz-" + value)) {
var tr_para = document.createElement("P");
tr_para.setAttribute("id", "tr-msz-" + value);
tr_para.setAttribute("class", "tr-msz");
tr_para.style.textAlign = 'justify';
var tr_fTag = document.createElement("IMG");
tr_fTag.setAttribute("class", "tFlag");
tr_fTag.setAttribute("alt", "翻译图标");
// tr_fTag.setAttribute("title", "翻译图标免责声明");
tr_fTag.setAttribute("src", "/html/assets/translate-icon.svg");
tr_para.appendChild(tr_fTag);
var container = document.createElement('span');
container.innerHTML = tr_text;
//var tr_textNode = document.createTextNode(container);
tr_para.appendChild(container);
/* Woot message only for multi source */
if(rootElement.querySelector(".lia-message-body-content").previousElementSibling != null && rootElement.querySelector(".lia-message-body-content").previousElementSibling.getAttributeNames().includes("data-generation-timestamp")){
rootElement.querySelector(".lia-message-body-content").previousElementSibling.remove()
}
if(rootElement.querySelector(".lia-quilt-forum-message")){
rootElement.querySelector(".lia-quilt-forum-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-message-view-blog-topic-message")) {
rootElement.querySelector(".lia-message-view-blog-topic-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-blog-reply-message")){
rootElement.querySelector(".lia-quilt-blog-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-tkb-reply-message")){
rootElement.querySelectorAll(".lia-quilt-tkb-reply-message .lia-message-body")[0].insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-message")){
rootElement.querySelector(".lia-quilt-idea-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector(".lia-quilt-idea-reply-message")){
rootElement.querySelector(".lia-quilt-idea-reply-message .lia-message-body").insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
} else if(rootElement.querySelector('.lia-quilt-occasion-message')){
rootElement.querySelector('.lia-quilt-occasion-message .lia-message-body').insertBefore(tr_para,rootElement.querySelector(".lia-message-body-content"));
}
else {
if (rootElement.querySelectorAll('div.lia-quilt-row-footer').length > 0) {
rootElement.querySelectorAll('div.lia-quilt-row-footer')[0].appendChild(tr_para);
} else {
rootElement.querySelectorAll('div.lia-quilt-column-message-footer')[0].appendChild(tr_para);
}
}
}
} catch (e) {
}
}
} else {
/* Do not display button for same language */
// syncList.remove(value);
var index = $scope.syncList.indexOf(value);
if (index > -1) {
$scope.syncList.splice(index, 1);
}
}
}
}
}
}
/*if(mszList_l.length <= 0){
setTimeout(()=>{
var mszListl = [];
angular.forEach(document.querySelectorAll("[class*='lia-js-data-messageUid']"), function(element) {
var mszId = element.getAttribute("data-lia-message-uid");
if (mszId != null) {
mszListl.push(mszId);
}
});
var mszListid = mszListl;
console.log("mszListl:",mszListl);
},2000)
}else{
var mszListid = mszList_l;
}*/
console.log("mszList_l:",mszList_l.length);
angular.forEach(mszList_l, function (value) {
if (document.querySelectorAll('div.lia-js-data-messageUid-' + value).length > 0) {
var rootElements = document.querySelectorAll('div.lia-js-data-messageUid-' + value);
}else if(document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view').length >0){
var rootElements = document.querySelectorAll('.lia-occasion-message-view .lia-component-occasion-message-view')[0].querySelectorAll('.lia-occasion-description')[0];
}else {
var rootElements = document.querySelectorAll('div.message-uid-' + value);
}
angular.forEach(rootElements, function (rootElement) {
if (value == '2006977' && "ForumTopicPage" == "TkbArticlePage") {
rootElement = document.querySelector('.lia-thread-topic');
}
/* V1.1 Remove from UI */
if (document.getElementById("tr-msz-" + value)) {
document.getElementById("tr-msz-" + value).remove();
}
if (document.getElementById("tr-sync-" + value)) {
document.getElementById("tr-sync-" + value).remove();
}
/* XPath expression for subject and Body */
var lingoRBExp = "//lingo-body[@id = "+"'lingo-body-"+value+"'"+"]";
lingoRSExp = "//lingo-sub[@id = "+"'lingo-sub-"+value+"'"+"]";
/* Get translated subject of the message */
lingoRSXML = doc.evaluate(lingoRSExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i=0;i 0){
angular.forEach(document.querySelectorAll(".PageTitle"), function(subEle) {
subEle.textContent = sub_L;
});
}
}
}
// Label translation
try{
var labelEle = document.querySelector("#labelsForMessage");
if(!labelEle){
labelEle = document.querySelector(".LabelsList");
}
if(labelEle) {
var listContains = labelEle.querySelector('.label');
if (listContains) {
/* Commenting this code as bussiness want to point search with source language label */
// var tagHLink = labelEle.querySelectorAll(".label")[0].querySelector(".label-link").href.split("label-name")[0];
var lingoLabelExp = "//lingo-label/text()";
trLabels = [];
trLabelsHtml = "";
/* Get translated labels of the message */
lingoLXML = doc.evaluate(lingoLabelExp, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var labelsLength = document.querySelector(".LabelsList").querySelectorAll(".label").length;
var labelSnapshotLength = lingoLXML.snapshotLength;
if (labelsLength == labelSnapshotLength){
for (var k = 0; k < lingoLXML.snapshotLength; k++) {
//trLabels.push(lingoLXML.snapshotItem(i).textContent);
if (k != 0) {
//trLabelsHtml = trLabelsHtml + '