MSPM0G3507-Q1: Using DMA read GPIO PIN

Part Number: MSPM0G3507-Q1

Tool/software:

Here is the English translation of your content:


My program uses mspm0_sdk_2_03_00_07 and KEIL tools, and I intend to use DMA Channel 1 together with TIMG6 to read data (digital signals) from a GPIO pin.

The DMA CH1 is configured as follows:

static const DL_DMA_Config gDMA_SAMPLE_READConfig = {
    .transferMode   = DL_DMA_SINGLE_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        = DMA_SAMPLE_READ_TRIGGER_SEL_FSUB_0,
    .triggerType    = DL_DMA_TRIGGER_TYPE_EXTERNAL,
};

static uint32_t sample_map[1024];

Afterward, my program sets parameters and starts the TIMG6 timer, and the source and destination addresses for the DMA are set as follows:

DL_DMA_setSrcAddr(DMA, DMA_SAMPLE_READ_CH, (uint32_t) &(SDA_GPIO_PORT->DIN31_0));
DL_DMA_setDestAddr(DMA, DMA_SAMPLE_READ_CH, (uint32_t) sample_map);
DL_DMA_setTransferSize(DMA, DMA_SAMPLE_READ_CH, 1024);

Then, the DMA is started and the program waits for it to complete:

DL_DMA_enableChannel(DMA, DMA_SAMPLE_READ_CH);
while (DL_DMA_isChannelEnabled(DMA, DMA_SAMPLE_READ_CH)) { 
    // waiting DMA completed
}
DL_TimerG_stopCounter(TIMER_SAMPLE_READ);

However, the result is that all elements in sample_map are zero.

I had to use an SRAM variable as an intermediate buffer, and continuously update that variable with the value of SDA_GPIO_PORT->DIN31_0 in order for the DMA to correctly read pin data:

static uint32_t temp_data;
DL_DMA_setSrcAddr(DMA, DMA_SAMPLE_READ_CH, (uint32_t) &temp_data);

DL_DMA_enableChannel(DMA, DMA_SAMPLE_READ_CH);
while (DL_DMA_isChannelEnabled(DMA, DMA_SAMPLE_READ_CH)) { 
    temp_data = DL_GPIO_readPins(SDA_GPIO_PORT, SDA_1_GPIO_PIN | SDA_2_GPIO_PIN | SDA_3_GPIO_PIN | SDA_4_GPIO_PIN);
}

This way, the result is correct.


How do I setting and use DMA read GPIO PIN directly?