Disona

F28M35 Flash M3: Init

Jun 13th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | None | 0 0
  1. int main(void) {
  2.     Uint16 i;
  3.     Uint32 j;
  4.  
  5.     // Disable Interrupts
  6.     IntMasterDisable();
  7.  
  8.     // Sets up PLL, M3 running at 75MHz and C28 running at 150MHz
  9.     // SysCtlClockSet(0x8007 000F)
  10.     // 20MHZ x 15 = 300MHZ/2 (PLL has a defualt built in divide by 2)
  11.     // sysctl_div_1 = 1 => output from PLL = 150MHZ
  12.     // M3 divider = 2 => clkc to M3 = 75 MHZ
  13.     // XCLKOUT divider = 4 => XCLKOUT = 37.5 MHZ
  14.     // C28 divder = 1 = > clck to C28 = 150 MHZ
  15.     HWREG(SYSCTL_MWRALLOW) =  0xA5A5A5A5;
  16.     SysCtlClockConfigSet(SYSCTL_USE_PLL | (SYSCTL_SPLLIMULT_M & 0xF) |\
  17.                          SYSCTL_SYSDIV_1 | SYSCTL_M3SSDIV_2 |\
  18.                          SYSCTL_XCLKDIV_4);
  19.    
  20.     // Copy stuff from flash to RAM
  21.     memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
  22.    
  23.     // Init M3 flash and leave flash pump
  24.     FlashInit();
  25.     FlashLeavePump();
  26.  
  27.     // M3 EALLOW
  28.     HWREG(SYSCTL_MWRALLOW) =  0xA5A5A5A5;
  29.     SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG1);
  30.     SysCtlPeripheralDisable(SYSCTL_PERIPH_WDOG0);
  31.  
  32.     // Give Shared RAM block 1 to C28 (C28 will put its programming status in this block)
  33.     RAMMReqSharedMemAccess(S1_ACCESS,1);
  34.  
  35.     // Now clocking and memory are set up, so we can start C28
  36.     IPCMtoCBootControlSystem(CBROM_MTOC_BOOTMODE_BOOT_FROM_FLASH);
  37.  
  38.     // Wait a little for C28 to boot up (not necessary, i think, but let it be)
  39.     j = 100000;
  40.     while (j > 0)
  41.         j--;
  42.  
  43.     // Prepare data for programming for C28
  44.     // "flashData" structure resides in RAM S0 block, which is dedicated to M3
  45.     for (i = 0; i < 1024; i++){
  46.         flashData.dataBuffer[i] = i;
  47.     }
  48.     flashData.numOfWords = 1024;
  49.     flashData.flashAddress = 0x00128000;    // Sector F
  50.    
  51.     // Now set a command for Erasing C28 flash sector
  52.     flashData.cmd = M3_CMD_ERASE_FLASH;
  53.     flashData.sectorMask = SECTOR_F_MASK;
  54.  
  55.     // By setting IPC_FLAG 10, we tell C28 that all needed data is prepared, command issued (M3_CMD_ERASE_FLASH)
  56.     // and it can perform this command
  57.     IPCMtoCFlagSet(IPC_FLAG10);
  58.  
  59.     // Now we should wait for acknowledge of this flag
  60.     while (IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC10) == 1){};
  61.  
  62.     // By setting IPC_FLAG 11, C28 will tell us, that it had performed operation
  63.     while (IPCCtoMFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0){};
  64.     IPCCtoMFlagAcknowledge(IPC_CTOMIPCSTS_IPC11);
  65.    
  66.     // Now when flash is erased, we can program it with our block
  67.     flashData.cmd = M3_CMD_FLASH_DATA;
  68.     IPCMtoCFlagSet(IPC_FLAG10);
  69.     while (IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC10) == 1){};
  70.     while (IPCCtoMFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0){};
  71.     IPCCtoMFlagAcknowledge(IPC_CTOMIPCSTS_IPC11);
  72.  
  73.     while (1){
  74.  
  75.         IPCMtoCFlagBusy(IPC_CTOMIPCSTS_IPC11) == 0;
  76.         IPCMtoCFlagSet(IPC_FLAG12);
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment