Other Parts Discussed in Thread: UNIFLASH
Hello, I used it
Proj_lab10a / 2802 x0_flashapi_bootromsymbols_v2. 01. Lib
This flash library, found the first power on the normal storage failure, can also be stored several times, but after the storage failure, it is found that the re-powered chip seems to die, which is why,
Initial see as follows: Is to change what configuration /, are the official code.
void InitFlash(void) { EALLOW; // // Enable Flash Pipeline mode to improve performance of code executed from // Flash. // FlashRegs.FOPT.bit.ENPIPE = 1; // // CAUTION // Minimum waitstates required for the flash operating // at a given CPU rate must be characterized by TI. // Refer to the datasheet for the latest information. // #if (CPU_FRQ_60MHZ) // // Set the Paged Waitstate for the Flash // FlashRegs.FBANKWAIT.bit.PAGEWAIT = 2; // // Set the Random Waitstate for the Flash // FlashRegs.FBANKWAIT.bit.RANDWAIT = 2; // // Set the Waitstate for the OTP // FlashRegs.FOTPWAIT.bit.OTPWAIT = 2; #elif (CPU_FRQ_40MHZ) // // Set the Paged Waitstate for the Flash // FlashRegs.FBANKWAIT.bit.PAGEWAIT = 1; // // Set the Random Waitstate for the Flash // FlashRegs.FBANKWAIT.bit.RANDWAIT = 1; // // Set the Waitstate for the OTP // FlashRegs.FOTPWAIT.bit.OTPWAIT = 1; #endif // // CAUTION: ONLY THE DEFAULT VALUE FOR THESE 2 REGISTERS SHOULD BE USED // FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF; FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF; EDIS; // // Force a pipeline flush to ensure that the write to the last register // configured occurs before returning. // asm(" RPT #7 || NOP"); } void usermain_flash( void ) { /*------------------------------------------------------------------ To use the Flash API, the following steps must be followed: 1. Modify Flash2802x_API_Config.h for your targets operating conditions. 2. Include Flash2802x_API_Library.h in the application. 3. Add the approparite Flash API library to the project. The user's code is responsible for the following: 4. Initalize the PLL to the proper CPU operating frequency. 5. If required, copy the flash API functions into on-chip zero waitstate RAM. 6. Initalize the Flash_CPUScaleFactor variable to SCALE_FACTOR 7. Initalize the callback function pointer or set it to NULL 8. Optional: Run the Toggle test to confirm proper frequency configuration of the API. 9. Optional: Unlock the CSM. 10. Make sure the PLL is not running in limp mode 11. Call the API functions: Flash_Erase(), Flash_Program(), Flash_Verify() The API functions will: Disable the watchdog Check the device PARTID. Disable interrupts during time critical code. Perform the desired operation and return status ------------------------------------------------------------------*/ Uint16 Status; /*------------------------------------------------------------------ Initalize the PLLCR value before calling any of the F2802x Flash API functions. Check to see if the PLL needs to changed PLLCR_VALUE is defined in Example_Flash2802x_API.h 1) Make sure PLL is not in limp mode 2) Disable missing clock detect logic 3) Make the change 4) Wait for the DSP to switch to the PLL clock This wait is performed to ensure that the flash API functions will be executed at the correct frequency. 5) While waiting, feed the watchdog so it will not reset. 6) Re-enable the missing clock detect logic ------------------------------------------------------------------*/ // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2802x_SysCtrl.c file. //InitSysCtrl(); /*------------------------------------------------------------------ Unlock the CSM. If the API functions are going to run in unsecured RAM then the CSM must be unlocked in order for the flash API functions to access the flash. If the flash API functions are executed from secure memory (L0-L3) then this step is not required. ------------------------------------------------------------------*/ Status = Example_CsmUnlock(); if(Status != STATUS_SUCCESS) { Example_Error(Status); } /*------------------------------------------------------------------ Copy API Functions into SARAM The flash API functions MUST be run out of internal zero-waitstate SARAM memory. This is required for the algos to execute at the proper CPU frequency. If the algos are already in SARAM then this step can be skipped. DO NOT run the algos from Flash DO NOT run the algos from external memory ------------------------------------------------------------------*/ // If the build links in the 2802x_FlashAPI_BootROMSymbols.lib, then // The API is in boot ROM and we do not need to copy it from flash. // // If the build links in the software API library: // i.e. Flash2802x_API_<version>.lib // then we need to copy the flash API from the flash memory to RAM. #if (BOOT_ROM_API == 0) // Example_MemCopy(&Flash28_API_LoadStart, &Flash28_API_LoadEnd, &Flash28_API_RunStart); #endif // We must also copy required user interface functions to RAM. // Example_MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart); /*------------------------------------------------------------------ Initalize Flash_CPUScaleFactor. Flash_CPUScaleFactor is a 32-bit global variable that the flash API functions use to scale software delays. This scale factor must be initalized to SCALE_FACTOR by the user's code prior to calling any of the Flash API functions. This initalization is VITAL to the proper operation of the flash API functions. SCALE_FACTOR is defined in Example_Flash2802x_API.h as #define SCALE_FACTOR 1048576.0L*( (200L/CPU_RATE) ) This value is calculated during the compile based on the CPU rate, in nanoseconds, at which the algorithums will be run. ------------------------------------------------------------------*/ EALLOW; Flash_CPUScaleFactor = SCALE_FACTOR; EDIS; /*------------------------------------------------------------------ Initalize Flash_CallbackPtr. Flash_CallbackPtr is a pointer to a function. The API uses this pointer to invoke a callback function during the API operations. If this function is not going to be used, set the pointer to NULL NULL is defined in <stdio.h>. ------------------------------------------------------------------*/ EALLOW; Flash_CallbackPtr = &MyCallbackFunction; EDIS; MyCallbackCounter = 0; // Increment this counter in the callback function // Jump to SARAM and call the Flash API functions // Example_CallFlashAPI(); }