This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

About the MSPM0G3507 evaluation board,The data stored between DMA and internal flash interacts

Other Parts Discussed in Thread: MSPM0G3507, SYSCONFIG

hi team:

       I'm using the MSPM0G3507 evaluation board,I used ADC conversion and DMA output,I also want to use internal flash to store the variables I want to store。Now I find that the data stored by DMA will update the data stored by internal flash, but they are stored by different variables, is there any way to solve it?

       Here is some of the code:

code---ADC and DMA:

volatile uint16_t RF_AD_Value[4];

static const DL_ADC12_ClockConfig gADC_ClockConfig = {
.clockSel = DL_ADC12_CLOCK_SYSOSC,
.divideRatio = DL_ADC12_CLOCK_DIVIDE_1,
.freqRange = DL_ADC12_CLOCK_FREQ_RANGE_24_TO_32,
};
SYSCONFIG_WEAK void SYSCFG_DL_ADC_DMA0_CH0_init(void)
{
DL_ADC12_setClockConfig(ADC0_INST, (DL_ADC12_ClockConfig *) &gADC_ClockConfig);

DL_ADC12_configConversionMem(ADC0_INST, ADC01_ADCMEM,
DL_ADC12_INPUT_CHAN_1, DL_ADC12_REFERENCE_VOLTAGE_VDDA, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC0_INST, ADC02_ADCMEM,
DL_ADC12_INPUT_CHAN_2, DL_ADC12_REFERENCE_VOLTAGE_VDDA, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC0_INST, ADC04_ADCMEM,
DL_ADC12_INPUT_CHAN_4, DL_ADC12_REFERENCE_VOLTAGE_VDDA, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
DL_ADC12_configConversionMem(ADC0_INST, ADC05_ADCMEM,
DL_ADC12_INPUT_CHAN_5, DL_ADC12_REFERENCE_VOLTAGE_VDDA, DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, DL_ADC12_AVERAGING_MODE_DISABLED,
DL_ADC12_BURN_OUT_SOURCE_DISABLED, DL_ADC12_TRIGGER_MODE_AUTO_NEXT, DL_ADC12_WINDOWS_COMP_MODE_DISABLED);

DL_ADC12_initSeqSample(ADC0_INST,DL_ADC12_REPEAT_MODE_ENABLED,DL_ADC12_SAMPLING_SOURCE_AUTO,DL_ADC12_TRIG_SRC_SOFTWARE,DL_ADC12_SEQ_START_ADDR_00,DL_ADC12_SEQ_END_ADDR_03,DL_ADC12_SAMP_CONV_RES_12_BIT,DL_ADC12_SAMP_CONV_DATA_FORMAT_UNSIGNED);

DL_ADC12_enableFIFO(ADC0_INST);
DL_ADC12_setPowerDownMode(ADC0_INST,DL_ADC12_POWER_DOWN_MODE_MANUAL);
DL_ADC12_setSampleTime0(ADC0_INST,500);
DL_ADC12_enableDMA(ADC0_INST);
DL_ADC12_setDMASamplesCnt(ADC0_INST,4);
DL_ADC12_enableDMATrigger(ADC0_INST,(DL_ADC12_DMA_MEM0_RESULT_LOADED));
DL_ADC12_enableDMATrigger(ADC0_INST,(DL_ADC12_DMA_MEM1_RESULT_LOADED));
DL_ADC12_enableDMATrigger(ADC0_INST,(DL_ADC12_DMA_MEM2_RESULT_LOADED));
DL_ADC12_enableDMATrigger(ADC0_INST,(DL_ADC12_DMA_MEM3_RESULT_LOADED));

/* Enable ADC12 interrupt */
DL_ADC12_clearInterruptStatus(ADC0_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableInterrupt(ADC0_INST,(DL_ADC12_INTERRUPT_DMA_DONE));
DL_ADC12_enableConversions(ADC0_INST);

SYSCFG_DL_DMA_CH0_init();
DL_ADC12_startConversion(ADC0_INST);
}


static const DL_DMA_Config gDMA_Config = {
.transferMode = DL_DMA_FULL_CH_REPEAT_BLOCK_TRANSFER_MODE,
.extendedMode = DL_DMA_NORMAL_MODE,
.destIncrement = DL_DMA_ADDR_INCREMENT,
.srcIncrement = DL_DMA_ADDR_UNCHANGED,
.destWidth = DL_DMA_WIDTH_WORD,
.srcWidth = DL_DMA_WIDTH_WORD,
.trigger = ADC_INST_DMA_TRIGGER,
.triggerType = DL_DMA_TRIGGER_TYPE_EXTERNAL,
};
SYSCONFIG_WEAK void SYSCFG_DL_DMA_CH0_init(void)
{
DL_DMA_initChannel(DMA, DMA_CH0_CHAN_ID , (DL_DMA_Config *) &gDMA_Config);

/* Configure DMA source, destination and size */
DL_DMA_disableChannel(DMA, DMA_CH0_CHAN_ID);
DL_DMA_setSrcAddr(DMA, DMA_CH0_CHAN_ID,(uint32_t) DL_ADC12_getFIFOAddress(ADC0_INST));
DL_DMA_setDestAddr(DMA, DMA_CH0_CHAN_ID, (uint32_t)&RF_AD_Value[0]);
DL_DMA_setTransferSize(DMA, DMA_CH0_CHAN_ID, 4);
DL_DMA_enableChannel(DMA, DMA_CH0_CHAN_ID);
}

code---internal flash:

volatile uint32_t SendData[8];
volatile uint32_t SavedData[8];
#define SavedDataSize (sizeof(SavedData) / sizeof(*(SavedData)))

DL_FLASHCTL_COMMAND_STATUS gCmdStatus;
void EEPROM_write_ALLData(uint32_t* datatoEEPROM)
{
/* Unprotect sector in main memory with ECC generated by hardware */
DL_FlashCTL_unprotectSector(
FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
/* Erase sector in main memory */
gCmdStatus = DL_FlashCTL_eraseMemoryFromRAM(
FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_COMMAND_SIZE_SECTOR);
if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
/* If command was not successful, set a breakpoint */
__BKPT(0);
}

/* 32-64bit write to flash in main memory */
DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
while (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED);
// gCmdStatus = DL_FlashCTL_programMemoryFromRAM32WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS), &datatoEEPROM[0]);
gCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS), &datatoEEPROM[0]);
if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
/* If command was not successful, set a breakpoint */
__BKPT(0);
}
/* 32-64bit write to flash in main memory */
DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
while (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED);
// gCmdStatus = DL_FlashCTL_programMemoryFromRAM32WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+8), &datatoEEPROM[1]);
gCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+8), &datatoEEPROM[2]);
if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
/* If command was not successful, set a breakpoint */
__BKPT(0);
}
/* 32-64bit write to flash in main memory */
DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
while (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED);
// gCmdStatus = DL_FlashCTL_programMemoryFromRAM32WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+16), &datatoEEPROM[2]);
gCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+16), &datatoEEPROM[4]);
if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
/* If command was not successful, set a breakpoint */
__BKPT(0);
}
/* 32-64bit write to flash in main memory */
DL_FlashCTL_unprotectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
while (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED);
// gCmdStatus = DL_FlashCTL_programMemoryFromRAM32WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+24), &datatoEEPROM[3]);
gCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, (MAIN_BASE_ADDRESS+24), &datatoEEPROM[6]);
if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
/* If command was not successful, set a breakpoint */
__BKPT(0);
}

DL_FlashCTL_protectSector(FLASHCTL, MAIN_BASE_ADDRESS, DL_FLASHCTL_REGION_SELECT_MAIN);
}

void EEPROM_read_ALLData(uint32_t *data)
{
uint32_t *ReadRecordPointer;
uint32_t ReadRecordAddress;

ReadRecordAddress = MAIN_BASE_ADDRESS;
for (uint16_t num = 0; num < SavedDataSize; num++) {
ReadRecordPointer = (void *) ReadRecordAddress;
data[num] = *ReadRecordPointer;
ReadRecordAddress += 4;
}
}

During the simulation, it is found that the data of SavedData changes with the change of RF_AD_Value data:

How can I solve it,Thanks。

  • Hi lxy,

    Let me make the operation of your code:

    1. use DMA to transfer the ADC result from FIFO to the RF_AD_Value

    2. Write the datatoEEPROM[] to the flash

    3. Read the flash to SavedData[]

    Please share the flash data of your MAIN_BASE_ADDRESS, does it change?

    Also, you can set the two avarible location away from the other, in case your pointer overflow and change the next variable.

    B.R.

    Sal

  • Hi 

           I looked at the flash data of MAIN_BASE_ADDRESS, The data is unchanged。but the SavedData[0] and SavedData[1] Change in existence。I tried to change the number of DMA conversions to 2,and then the SavedData[0] and SavedData[1] don't change,but The chip will not be recognized the next time the program is burned, and the chip will need to be restarted to re-burn the program。Could it be a DMA configuration problem?Thanks。

  • Hi Lxy,

    Sorry for the late response. I missed your reply.

    .destWidth = DL_DMA_WIDTH_WORD,
    .srcWidth = DL_DMA_WIDTH_WORD,

    You set a word (4 bytes) for the DMA, but your destination is a 16-bit array, I thinks this is the problem.

    B.R.

    Sal