Kerry: Thanks.
I've brought in the DSDK 2.2 flash driver as well as copied some of the start up code from the demo examples. I get identical results to the 1.3, i.e., the routines complete with successful return status, but the flash never changes.
I'm beginning to suspect the problem my be in the 1.3 header files, such as fsl_device_registers.h, but I can't bring in the 2.2 version since all of my other code relies on 1.3.
Really bizarre such a simple piece of code can't work. Please have a look and see if I've done anything really stupid that keeps this from working.
Here's output from the version using the 2.2 driver:
@fffffffffffffffffffffffffe1affff
FLASH_Init(): rc = 0x00
PFlash Example Start
PFlash Information:
Flash block base address: 0x0
Total Program Flash Size: 32 KB, Hex: (0x8000)
Program Flash Sector Size: 1 KB, Hex: (0x400)
FLASH_Erase(): rc = 0x00
FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe
fffffffffffffffffffffffffe1affff
FLASH_VerifyErase(): rc = 0x00
FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe
FLASH_Program(): rc = 0x00
FSEC=0xfe, FOPT=0x1a, flash protection (next reset):DISABLED, buf = 0x00001afe
fffffffffffffffffffffffffe1affff
/* ----------------------------------------------------------------------------
Copyright (c) 2017, ZOS, Inc.
Author(s): Bill Fox <billfox@bct.com>
Target(s): ISO/IEC 9899:1999 (C99)
------------------------------------------------------------------------- */
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "fsl_flash.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "constants.h"
#include "delay.h"
#define FLASH_LOGGING_ENABLE 1
#if (FLASH_LOGGING_ENABLE == 1)
#define FLASH_LOG(...) debug_printf(__VA_ARGS__)
#else
#define FLASH_LOG(...)
#endif
#define FTFA_FSEC_ADDR 0x040c
#define FTFA_FOPT_ADDR 0x040d
uint8_t const *pFTFA_FSEC = (uint8_t *)FTFA_FSEC_ADDR;
uint8_t const *pFTFA_FOPT = (uint8_t *)FTFA_FOPT_ADDR;
static flash_config_t s_flashDriver;
static void printFLASH( uint32_t addr, size_t size ){
for(;size;size--){
FLASH_LOG("%02x", *(uint8_t*)addr++);
}
FLASH_LOG("\n");
}
void
flash_protection(void){
uint8_t config_FSEC = *pFTFA_FSEC;
uint8_t config_FOPT = *pFTFA_FOPT;
uint32_t buf = (config_FOPT << 8) | config_FSEC;
uint32_t rc = 0;
uint32_t pflashBlockBase = 0;
uint32_t pflashTotalSize = 0;
uint32_t pflashSectorSize = 0;
printFLASH( 0x400, 16 );
memset(&s_flashDriver, 0, sizeof(flash_config_t));
rc = FLASH_Init(&s_flashDriver);
FLASH_LOG("FLASH_Init(): rc = 0x%02x\n", rc );
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
/* print welcome message */
debug_printf("\r\n PFlash Example Start \r\n");
/* Print flash information - PFlash. */
debug_printf("\r\n PFlash Information: ");
debug_printf("\r\n Flash block base address:\t0x%0x", pflashBlockBase);
debug_printf("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);
debug_printf("\r\n Program Flash Sector Size:\t%d KB, Hex: (0x%x)\n\n", (pflashSectorSize / 1024), pflashSectorSize);
rc = FLASH_Erase(&s_flashDriver, 0x400, 1024, kFLASH_ApiEraseKey);
FLASH_LOG("FLASH_Erase(): rc = 0x%02x\n", rc );
FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n",
*pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",
buf );
printFLASH( 0x400, 16 );
rc = FLASH_VerifyErase(&s_flashDriver, 0x400, 1024, kFLASH_MarginValueUser);
FLASH_LOG("FLASH_VerifyErase(): rc = 0x%02x\n", rc );
FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n",
*pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",
buf );
rc = FLASH_Program(&s_flashDriver, FTFA_FSEC_ADDR, &buf, 4 );
FLASH_LOG("\nFLASH_Program(): rc = 0x%02x\n", rc );
FLASH_LOG("\nFSEC=0x%02x, FOPT=0x%02x, flash protection (next reset):%s, buf = 0x%08x\n",
*pFTFA_FSEC, *pFTFA_FOPT, *pFTFA_FSEC ? "DISABLED" : "enabled",
buf );
printFLASH( 0x400, 16 );
}