• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » C2000™ Microcontrollers » C2000 32-bit Microcontrollers Forum » F021 Flash API Example Code
Share
C2000™ Microcontrollers
  • Forums
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
C2000 Resources
  • Product Folder
  • C2000 Training Portal
  • C2000 Technical Training Catalog
  • C2000 Datasheets, App Notes, User Guides
  • C2000 Hardware Design Kits
  • controlSUITE for C2000 Software Library


  • InstaSPIN Resources
  • What is InstaSPIN?
  • Videos and Support


  • InstaSPIN-FOC and InstaSPIN-MOTION Resources
  • What is InstaSPIN-FOC?
  • What is InstaSPIN-MOTION?
  • Product Folder: F28069F, F28068F, F28062F, F28068M, F28069M
  • User’s Guide
  • Technical User’s Manual
  • Tools
  • F021 Flash API Example Code

    F021 Flash API Example Code

    This question has suggested answer(s)
    Mario Willeit
    Posted by Mario Willeit
    on Jan 09 2012 07:43 AM
    Prodigy550 points

    Hello,

    are there any code examples available how to use the F021 Flash API in Concerto ?

    I'm especially interested how to properly link the F021_API_CortexM3_LE.lib so that it can be copied to SRAM for execution
    and how to set/get the the correct load (SRAM) and store (Flash) addresses.

    Thank you in advance,
    Mario

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Chrissy Chang
      Posted by Chrissy Chang
      on Jan 09 2012 09:36 AM
      Expert3760 points

      Mario:

      Currently, there is not yet a code example for the F021 Flash API in Concerto.  The plan is to release a basic example by the next release of controlSUITE though.

       

      Regards,
      Chrissy Chang

      If a post answers your question, please mark it with the "verify answer" button.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mario Willeit
      Posted by Mario Willeit
      on Jan 09 2012 09:42 AM
      Prodigy550 points

      Chrissy,

      thank you for your fast answer.

      When do you expect the next ControlSuite release ? Is there any chance to get some preliminary code/hints etc. ?

      Best regards,
      Mario  

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Jan 09 2012 09:56 AM
      Suggested Answer
      Genius14440 points

      Hi Mario,

      You ask an extremely good question.  The short answer is no, there aren't any examples that have been released yet.  However, I'm working on a Flash bootloader for Concerto, so I should be able to help you out directly.

      With previous C2000 flash APIs, the library code was assigned to a section called ramfuncs.  This made it easy for customers to use a generic linker command file and simply call the memcopy function before calling the flash functions.  The F021 (Concerto) API is done slightly differently in that it is not part of any pre-defined section.  The user must manually link this library into a section that will be copied into RAM.  This can easily be done using the linker command file...see below for an example:

          GROUP
          {
              ramfuncs
              { -l F021_API_CortexM3_LE.lib}
           
          } LOAD = FLASHLOAD, RUN = C0,
            LOAD_START(RamfuncsLoadStart),
            LOAD_SIZE(RamfuncsLoadSize),
            RUN_START(RamfuncsRunStart),
            PAGE = 0

      More information about linking in libraries can be found in the assembly language tools user guide  for the ARM compiler (spnu118j).  Beyond that all you will need to do is extern the Load/Run symbols in your main.c:

      #include <string.h>
      #include "F021_Concerto_Cortex.h"

      extern unsigned int RamfuncsLoadStart;
      extern unsigned int RamfuncsLoadSize;
      extern unsigned int RamfuncsRunStart;

      and then call memcpy before initialize the Flash API:

          memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
          
          oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 80);

      Please note we have deprecated the old MemCopy function that used to be found in utils/memcopy.c.  Instead we are now using the C standard memcpy which is part of the runtime support library.

      Hope this helps, let me know if you have further questions,

      Trey German

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Jan 09 2012 14:19 PM
      Suggested Answer
      Genius14440 points

      Mario,

      I put together some example code that is working.  Here are a few more pointers:

      • You'll need to secure the Flash Pump semaphore before executing anything from the Flash API.  Try using a line like this:

          // Give M3 Control of the flash pump
          HWREG(MTOCIPC_BASE + IPC_O_MPUMPREQUEST) = IPC_MPUMPREQUEST_KEY | 0x2;

      The IPC_MPUMPREQUEST_KEY isn't defined in the current device support release, but you can add:

      #define IPC_MPUMPREQUEST_KEY      0xA5937EC0 // Key Value

      to the top of you main source file.

      • Don't forget to setup clocking correctly.  This is critical to getting the Flash API to work.  Make sure you make a call to:

          // Setup main clock tree for 75MHz - M3 and 150MHz - C28x
          SysCtlClockConfigSet(SYSCTL_SYSDIV_1 | SYSCTL_M3SSDIV_2 | SYSCTL_USE_PLL |
                               (SYSCTL_SPLLIMULT_M & 0x0F));

      before calling anything from the Flash API.

      • I put together a Flash API test function that programs a pattern at 0x208000.  Try running this code, if you see a pattern at that location you have the Flash API working:

      #pragma CODE_SECTION(flashTest, "ramfuncs");
      void flashTest(void)
      {
          unsigned char pucProgTest[0x100];
          unsigned int i;
          
          Fapi_StatusType oReturnCheck;
          Fapi_FlashStatusType oFlashStatus;
          Fapi_FlashBankSectorsType oMyBank;
          Fapi_FlashStatusWordType oBlankStatus;
          
          for(i=0 ; i<0x100; i++)
              pucProgTest[i] = i;
          
          oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 75);
          oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);
          
          oReturnCheck = Fapi_getBankSectors(Fapi_FlashBank0, &oMyBank);
          
          
          oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, 2);
          while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy)
          {
          }
          oFlashStatus = Fapi_getFsmStatus();
          
          oReturnCheck = Fapi_doBlankCheck(0x208000, 0x1000, &oBlankStatus);
          
          for(i=0 ; i<0x10; i++)
          {
              oReturnCheck = Fapi_issueProgrammingCommand(0x208000 + (i*0x10), pucProgTest + (i*0x10), 0x10, 0, 0, Fapi_AutoEccGeneration);
              while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy)
              {
              }
              oFlashStatus = Fapi_getFsmStatus();    
          }
          
          while(1);
          
      }

      Let me know if you have any trouble,

      Trey German



      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jeremy RAMU
      Posted by Jeremy RAMU
      on Feb 15 2012 03:28 AM
      Prodigy20 points

      Hi,

      I follow your example and it's a real pleasure to make it work.

      But now, I try to do the same on the C28 side but I can't found some information about the C28's IPC PUMP REQUEST.

      So I was wondering if you could provided me some lines. I already got the Flash API example, I just need to give C28 the control of the flash pump.

      thank you for your help.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Agnes Cassin-Delauriere
      Posted by Agnes Cassin-Delauriere
      on Feb 15 2012 03:42 AM
      Intellectual1950 points

      Hello Jeremy,

      I would suggest to try the below code.

          EALLOW;
       
          // Wait for flashpump to be idle
          while(CtoMIpcRegs.CPUMPREQUEST != 0){}
         
          // Take control of the flash pump
          CtoMIpcRegs.CPUMPREQUEST = 0x4CE73950 | 0x1;
         
          EDIS;

      Cheers,

      Agnès

      Agnès Cassin-Delaurière

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jeremy RAMU
      Posted by Jeremy RAMU
      on Feb 15 2012 03:59 AM
      Prodigy20 points

      Thanks

      you are always a great help !

      Cheers.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Feb 15 2012 07:45 AM
      Genius14440 points

      Jeremy,

      Glad to hear you got it working.  Were you able to successfully program flash on the C28x?  One some of the parts there is a bug in the ECC patterns that will cause an NMI when flash on the 28 is programmed.  Curious if you are seeing this behavior or not.

      Regards,

      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Slava Ermachkov
      Posted by Slava Ermachkov
      on Feb 16 2012 02:10 AM
      Prodigy110 points

      Hello !

      There are a pair of questions about using Fapi.

      Q1:  When I try to use m3 at frequency 100 (PLL programmed as in lwip example), then function Fapi_setActiveFlashBank returns error Fapi_Error_InvalidHclkValue.

         oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 100);
         oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0); - returns error

      But at 75 MHz (PLL programmed as in Fapi example) this couple of functions works fine

         oReturnCheck = Fapi_initializeAPI(F021_CPU0_BASE_ADDRESS, 75);
         oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);  - returns success

      What's wrong about using Fapi at 100 MHz?

      Q2a: I need to program flash with Fapi within both m3 and c28 cores. Both cores' programs executed from Flash and permanently have data in Flash. Ram functions are used only when Fapi job occurs. So what should I do to correctly give "Flash Pump semaphore control" to specified core? Is it up to software to  ensure that other core has finished Fapi job before switching semaphore?

      Q2b: What should I do when Fapi job is finished if I want to continue executing without restart? Should I "unlock back" semaphore at any core?

      As a bonus - there is an error in your example: function oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, 2) isn't workable, there must be 0x208000 instead of "2".

      Thanks in advance.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Feb 17 2012 08:35 AM
      Genius14440 points

      Slava,

      A1) Hmmm, I just tried the same thing in my example (which also works at 75Mhz), but I'm having the same issue as you.  I believe you should be able to perform flash programming and erase operations at 100Mhz, but I will have to check with our flash experts.

      A2a) You are correct, software must ensure the flash pump semaphore is owned by the core doing the flash operations.  This should be relatively straightforward as each core can read the state of the semaphore.  In software you should just wait to run your programming code until you have the semaphore.

      A2b) The semaphore is only needed for programming and erase operations.  Normal program reads do not need the semaphore.  I would recommend after each core is finished programming you set the semaphore back to its default state.

      I'll get back to you on the 100Mhz issue ASAP.

      Regards,
      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Christian L
      Posted by Christian L
      on Mar 13 2012 08:49 AM
      Prodigy40 points

      Hi all,

      Thanks for these posts and the new F021 Flash API example on the concerto.

      I still have one question that remains unanswered though:

      Does this API and flash technology support re-programming of bits holding zeroes within a previously programmed word?

      (This is explicitly stated for other flash APIs but not for the F021. For example on page 5 of the doc for TMS320F2802x Flash API V2.01, it says: ".... a flash or OTP location can be programmed with 0xFFFE and later the same location can be programmed with 0xFFFC without going through an erase cycle. During the second programming call, the program operation will detect that bit 0 was already programmed and will only program bit 1." )

      Best regards,

      Christian

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Trey German
      Posted by Trey German
      on Mar 13 2012 09:48 AM
      Genius14440 points

      Christian,

      I'm honestly not sure as I haven't given this a shot.  I don't see why this wouldn't work, so why don't you give it a shot and let us know if this works or not.  I would do it myself, but I'm out on vacation the rest of this week and I'm working on finishing up some other tasks before I go.

      Regards,

      Trey

      Trey German

      C2000 Applications

      If a post answers your question, please mark it with the "verify answer" button.
      Visit these helpful C2000 Links!
      C2000 TI Wiki Pages
      TI Forum Sitemap
      ControlSUITE
      C2000 Getting Started
      CLA FAQs
      Workshop Material!
      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Vamsi Gudivada
      Posted by Vamsi Gudivada
      on Mar 13 2012 13:29 PM
      Intellectual2885 points

      Christian,

      In F021 also, a partially programmed word can be programmed to again to change 1s to 0s in later program iterations.

      That will work if you don't program ECC.  Once you program ECC also for a flash location, you will not be able to reprogram that location to change 1s to 0s with out erase.

      Thanks and regards,

      Vamsi

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Vamsi Gudivada
      Posted by Vamsi Gudivada
      on Mar 13 2012 14:48 PM
      Intellectual2885 points

      Slava,

      For (A1),  Before performing FSM operations, you need to set the waitstates for FSM operations calculated using

           RWAIT = (SYSCLK/(2*24MHz))-1

      If RWAIT results in a fractional value, round it up to the nearest integer.  These details are mentioned in the Flash API example.  For 100MHz, you have to set RWAIT to 2.  For 75MHz, you have to set RWAIT to 1.

       Please note that RWAIT for read operation should be calculated differently.  See section 5.3 Flash Controller Memory Module and 5.4 Flash registers in Concerto TRM located at http://www.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=spruh22b&fileType=pdf for more details.

       Thanks and best regards,

      Vamsi

       

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Christian L
      Posted by Christian L
      on Mar 14 2012 01:13 AM
      Prodigy40 points

      Vamsi,

      Thanks for clarifying (I was worried it could effect tear and wear although it works, since you expose the same transistors for more than one programming operation within an erase cycle)

      I assume you could also reprogram when the associated ECC byte has been set, provided the reprogramming only ever changes the 8 byte-data block to one that has the same ECC? If this is possible, my next question is how to characterize all 8 byte words having the same 1 byte ECC for a given flash address?

      Best regards,

      Christian

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    12
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use