On the one hand I have a RAM linked piece of test code that executes marvelously. It sets a usecond timer for some number of milliseconds, sets the ADC up for samples at a predetermined rate and then runs several digital filters on the fly. I have it down to 3us per sample running 8 DFT's. I like it. (RAM based IQmathLib was 18.2us).
On the other hand I have a stub of the working code that is FLASH based and provides a CAN interface to the chip, etc. My code takes 24us per sample running from FLASH because of the wait states. I expected this. Point is, the code WORKS inserted into the FLASH project (which is the minimal part of a larger project that my code will be one command in).
... calling C routine:
// sets ADC and switch states, backs up old settings
PD_SetADCtoPD (sensor);
// start a count down timer at MeasTime
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 100, MeasTime);
NumSamp = asmMeasLoop (ReIm, CSTime, CosSin);
// stop ADC
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // stop
...
Note, I have verified that all clock setups are identical so the 8x slow-down is just the wait states. Simple solution - change it from .text to .ramfuncs. This locates my function at 0x8000 in SRAM (verified by examining PC on entry.) SP is 0xA8 on first line of code, but the first PUSH sends PC to 0x0088 and sends the SP into left field.
;**************************************************************************** FP .set XAR2 .sect "ramfuncs" ;.sect ".text" .global _asmMeasLoop .global _CpuTimer0Regs .global _AdcRegs .global _AdcMirror ;---------------------------------------------------------------------- ; 13 | unsigned long int asmMeasLoop (_iq15* ReIm, _iq30* CSTime, _iq30* CosSin) _asmMeasLoop: ; CosSin *-SP[22] passed on stack ; unknown *-SP[20] passed on stack is 0x00008568, probably PC PUSH XAR7 ; *-SP[18] save to use as temporary CosSin pointer PUSH XAR6 ; *-SP[16] save to use as temp variable PUSH XAR5 ; *-SP[14] save incoming pointer to CSTime PUSH XAR4 ; *-SP[12] save incoming pointer to ReIm PUSH XAR3 ; *-SP[10] save to use as pointer to AdcRegs.ADCST PUSH XAR2 ; *-SP[8] save to use as pointer to AdcMirror.ADCRESULT0 ADDB SP,#4 ; NumSamp at *-SP[6], i at *-SP[4] PUSH DP ; *-SP[2] PUSH ST0 ; *-SP[1] MOV *-SP[6],#0 ; NumSamp MSW MOV *-SP[5],#0 ; NumSamp LSW MOVL XAR2,#_AdcMirror ; save cycles MOVL XAR3,#_AdcRegs+25 ; save cycles MOVL XAR7,*-SP[22] ; CosSin[0]; assume XAR7 is available SPM 0 ; no shift P
The FLASH code is a part of a CCS3.3 project (I am using 5.2), so I have had to hack and hack again while newly learning C2000. There is a lot of .asm code in there besides mine. I wiped it down to the least it can do (receive ECHO, VERSION?, REBOOT, and my command on CAN and return results) ad reverted the CMD files to F2806.cmd (default) and DSP280x_Headers_nonBIOS.cmd (examples default).
MEMORY
{
PAGE 0: /* Program Memory */
/* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE1 for data allocation */
RAML0 : origin = 0x008000, length = 0x001000 /* on-chip RAM block L0 */
OTP : origin = 0x3D7800, length = 0x000400 /* on-chip OTP */
FLASHD : origin = 0x3F0000, length = 0x002000 /* on-chip FLASH */
FLASHC : origin = 0x3F2000, length = 0x002000 /* on-chip FLASH */
FLASHA : origin = 0x3F6000, length = 0x001F80 /* on-chip FLASH */
CSM_RSVD : origin = 0x3F7F80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
BEGIN : origin = 0x3F7FF6, length = 0x000002 /* Part of FLASHA. Used for "boot to Flash" bootloader mode. */
CSM_PWL : origin = 0x3F7FF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */
ROM : origin = 0x3FF000, length = 0x000FC0 /* Boot ROM */
RESET : origin = 0x3FFFC0, length = 0x000002 /* part of boot ROM */
VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */
PAGE 1 : /* Data Memory */
/* Memory (RAM/FLASH/OTP) blocks can be moved to PAGE0 for program allocation */
/* Registers remain on PAGE1 */
RAMM0 : origin = 0x000000, length = 0x000400 /* on-chip RAM block M0 */
BOOT_RSVD : origin = 0x000400, length = 0x000080 /* Part of M1, BOOT rom will use this for stack */
RAMM1 : origin = 0x000480, length = 0x000380 /* on-chip RAM block M1 */
RAML1 : origin = 0x009000, length = 0x001000 /* on-chip RAM block L1 */
FLASHB : origin = 0x3F4000, length = 0x002000 /* on-chip FLASH */
}
/* Allocate sections to memory blocks.
Note:
codestart user defined section in DSP28_CodeStartBranch.asm used to redirect code
execution when booting to flash
ramfuncs user defined section to store functions that will be copied from Flash into RAM
*/
SECTIONS
{
/* Allocate program areas: */
.cinit : > FLASHA PAGE = 0
.pinit : > FLASHA, PAGE = 0
.text : > FLASHC PAGE = 0
codestart : > BEGIN PAGE = 0
ramfuncs : LOAD = FLASHD,
RUN = RAML0,
LOAD_START(_RamfuncsLoadStart),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
PAGE = 0
csmpasswds : > CSM_PWL PAGE = 0
csm_rsvd : > CSM_RSVD PAGE = 0
/* Allocate uninitalized data sections: */
.stack : > RAMM0 PAGE = 1
.ebss : > RAML1 PAGE = 1
.esysmem : > RAML1 PAGE = 1
/* Initalized sections go in Flash */
/* For SDFlash to program these, they must be allocated to page 0 */
.econst : > FLASHA PAGE = 0
.switch : > FLASHA PAGE = 0
/* Allocate IQ math areas: */
IQmath : > FLASHC PAGE = 0 /* Math Code */
IQmathTables : > ROM PAGE = 0, TYPE = NOLOAD /* Math Tables In ROM */
/* .reset is a standard section used by the compiler. It contains the */
/* the address of the start of _c_int00 for C Code. /*
/* When using the boot ROM this section and the CPU vector */
/* table is not needed. Thus the default type is set here to */
/* DSECT */
.reset : > RESET, PAGE = 0, TYPE = DSECT
vectors : > VECTORS PAGE = 0, TYPE = DSECT
}
The problem is 100% repeatable. It occurs in debug (XDS510USB) and release (i.e. other commands answer on CAN but this one needs a power cycle). The RAM based test code and the FLASH based app link to the same files. Both work if the section for this function is text.
Also, I had to remove DSP280x_usDelay - apparently for the same reason - before I realized this was happening.
I am sure the issue is largely that I took a generic CMD and don't know enough to fix it... If there is an easy answer I am all ears. if there is a hard answer, I'll put in the work but would appreciate the reading to be as focused as possible.
Thanks!