/* \file cc2538.gel * \brief GEL script for CC2538 device family. This file includes a * system reset macro. * * \revision $Revision: 31199 $ */ menuitem "StartUp" hotmenu StartUp() { memorymap_init(); } menuitem "CC2538" unsigned int _GEL_Backup_FP_COMP0; unsigned int _GEL_Backup_FP_COMP1; unsigned int _GEL_Backup_FP_COMP2; unsigned int _GEL_Backup_FP_COMP3; unsigned int _GEL_Backup_FP_COMP4; unsigned int _GEL_Backup_FP_COMP5; unsigned int _GEL_WaitTimeout = 0; int GEL_Timer1Lock = 0; int GEL_Timer2Lock = 0; hotmenu MassErase() { // Store connect states int ctxWasConnected = GEL_IsConnected(); GEL_EvalOnTarget("", "ConnectStateStore()", 1); GEL_EvalOnTarget("", "GEL_EvalOnTarget(\"\",\"ConnectStateStore()\", 1)", 1); // If connected to Cortex, disconnect if(ctxWasConnected == 1) { GEL_Disconnect(); } // Disconnect DAP GEL_EvalOnTarget("", "DisconnectIfConnected()", 1); // Connect to icepick and do mass erase GEL_EvalOnTarget("", "GEL_EvalOnTarget(\"\",\"ConnectIfDisconnected()\", 1)", 1); GEL_EvalOnTarget("", "GEL_EvalOnTarget(\"\",\"IP_CC2538_MASSERASE = 1\", 1)", 1); // Reset device GEL_AdvancedReset("System Reset"); // Restore connect state if(ctxWasConnected == 1) { // Connects to cortex, dap and icepick GEL_Connect(); } else { GEL_EvalOnTarget("", "ConnectStateRestore()", 1); GEL_EvalOnTarget("", "GEL_EvalOnTarget(\"\",\"ConnectStateRestore()\", 1)", 1); } GEL_TextOut("Mass Erase Complete.\n"); } hotmenu SystemReset() { GEL_Timer1Lock = 0; GEL_Timer2Lock = 0; GEL_Halt(); // 1. Save all FPB unit registers _GEL_Backup_FP_COMP0 = *((int*)(0xE0002008)); _GEL_Backup_FP_COMP1 = *((int*)(0xE000200C)); _GEL_Backup_FP_COMP2 = *((int*)(0xE0002010)); _GEL_Backup_FP_COMP3 = *((int*)(0xE0002014)); _GEL_Backup_FP_COMP4 = *((int*)(0xE0002018)); _GEL_Backup_FP_COMP5 = *((int*)(0xE000201C)); // Write to RAM area that signals resetISR to stop execution *((int*)(0x20003000)) = 0xA5F01248; // Let the arm run freely GEL_RunF(); GEL_SetTimer( 100, 1, "WaitForRun()", 1 ); // Don't let this function return until all the callbacks are finished GEL_EvalOnTarget("IcePick_C", "GEL_Waiting = 1", 1); GEL_EvalOnTarget("IcePick_C", "WaitForSignal()", 1); } WaitForRun() { int wasFirstThread = ++GEL_Timer1Lock; if( 1 != wasFirstThread ) return; GEL_CancelTimer( 1); _GEL_WaitTimeout = 0; // 2. Issue reset from icepick GEL_EvalOnTarget("IcePick_C", "GEL_AdvancedReset(\"System Reset\")"); // Wait for reset to complete by using a timer and checking // every 100 ms GEL_SetTimer( 100, 2, "WaitForReset()", 1 ); } WaitForReset() { unsigned int isAtResetIsr; unsigned int FP_CTRL; int wasFirstThread = ++GEL_Timer2Lock; if( 1 != wasFirstThread ) return; GEL_CancelTimer( 2 ); // Wait for reset to complete // 3. Halt CPU GEL_Halt(); isAtResetIsr = *((int*)(0x20003004)); if(isAtResetIsr != 0xAABBAABB && _GEL_WaitTimeout == 0) { _GEL_WaitTimeout = 1; GEL_RunF(); GEL_Timer2Lock = 0; GEL_SetTimer( 100, 2, "WaitForReset()", 1 ); return; } // 4.1 Enable FPB unit (FP_CTRL |= 0x03) FP_CTRL = *((int*)(0xE0002000)); FP_CTRL |= 0x3; *((int*)(0xE0002000)) = FP_CTRL; // 4.2 Restore all FPB unit registers *((int*)(0xE0002008)) = _GEL_Backup_FP_COMP0; *((int*)(0xE000200C)) = _GEL_Backup_FP_COMP1; *((int*)(0xE0002010)) = _GEL_Backup_FP_COMP2; *((int*)(0xE0002014)) = _GEL_Backup_FP_COMP3; *((int*)(0xE0002018)) = _GEL_Backup_FP_COMP4; *((int*)(0xE000201C)) = _GEL_Backup_FP_COMP5; // Signal to resetISR it can continue run *((int*)(0x20003000)) = 0; // Issue CPU reset GEL_Reset(); // Let SystemReset() complete GEL_EvalOnTarget("IcePick_C", "GEL_Waiting = 0", 1); if(_GEL_WaitTimeout == 1) { // Target code does not implement "catch" for system reset workaround GEL_TextOut("CPU Reset.\n"); } else { GEL_TextOut("System Reset.\n"); } } // Issue System Reset after flash load OnFileLoaded(int nErrorCode, int bSymbolsOnly) { // Only do system reset if a program is downloaded onto device. if(!bSymbolsOnly) { // Issue a system reset SystemReset(); // Only restart if "Run to label on restart" is enabled if ( DEBUG_GetBoolProperty("AutoRunToLabelOnRestart") ) { GEL_Restart(); } } } memorymap_init() { GEL_MapOff(); GEL_MapReset(); GEL_MapOn(); /* * Syntax for GEL_MapAddStr. * GEL_MapAddStr(address, page, length, "attribute", waitstate); Basic Attribute Types Derived Attribute Types String Description String Description R Read NONE No memory/protected W Write RAM Read and write P Port ROM Read only EX External WOM Write only EM Emulator INPORT Port read only PR Programmable OUTPORT Port write only ER Erasable IOPORT Port read and write DA Dual access SARAM Single access RAM ASn Access size DARAM Dual access RAM SHnC Shared FLASH Flash ROM CACHE Cache EXRAM External RAM TX Text EXROM External ROM MN Monitor EPROM Erasable write-able EPROM SA Single access MONITOR Monitor ROM FL Flash PRAM Program RAM MR Memory mapped PROM Program ROM NULL NULL NULL NULL */ GEL_MapAddStr(0x00200000, 0, 0x00080000, "R", 0); /* Flash */ GEL_MapAddStr(0x00000000, 0, 0x00004000, "R", 0); /* ROM */ GEL_MapAddStr(0x00280000, 0, 0x00001000, "R", 0); /* Flash info page */ GEL_MapAddStr(0x20000000, 0, 0x00008000, "R|W", 0); /* SRAM */ GEL_MapAddStr(0x40000000, 0, 0x04010100, "R|W", 0); /* Peripherals */ GEL_MapAddStr(0xE000E000, 0, 0x00001000, "R|W", 0); /* NVIC */ GEL_MapAddStr(0xE0002000, 0, 0x00000020, "R|W", 0); /* FPB */ GEL_TextOut("Memory Map Initialization Complete.\n"); } wait() { int delay = 0; for (delay = 0; delay <= 100; delay ++) {} }