void Setup_PTD6_EIRQ14_for_DMA(void)
{
// 1. Aktivácia hodinového deliča pre filtre v SIUL2 (ak už nie je povolený inde)
IP_SIUL2->IFCPR = 0U; // Nastavenie deličky filtra na Functional Clock (bez dodatočného delenia)
// 2. Voliteľne vypnite filter pre daný EIRQ index alebo ho nastavte na minimálny počet cyklov
// Pre EIRQ14 (v závislosti od mapovania registrov IFMCR):
IP_SIUL2->IFMCR[14] = 0U; // 0U vypína digitálny filter, hrana prechádza okamžite ako čistý hardvérový trigger
/* 1. Configuration of physical pin PTD6 via MSCR register */
// PTD6 corresponds to index MSCR[102] (as seen on your screenshot)
IP_SIUL2->MSCR[102] = 0; // Clear register
IP_SIUL2->MSCR[102] |= (1 << 19); // IBE = 1 (Input Buffer Enable - configures pin as input)
IP_SIUL2->IMCR[542-(512)] = 3u;
// Optional: if the signal floats, you can enable Pull-Up (PUE=1, PUS=1) or Pull-Down (PUE=1, PUS=0)
/* 2. Activation of edge detection on line EIRQ[14] */
// We want to capture the timestamp on every rising edge
IP_SIUL2->IREER0 |= (1 << 14); // IREER0[EIRE14] = 1 (Enable Rising Edge)
IP_SIUL2->IFEER0 &= ~(1 << 14); // IFEER0[EIRE14] = 0 (Disable Falling Edge)
/* 3. Request routing: Change from Interrupt to DMA */
// This step ensures that the edge does not wake up the CPU (NVIC), but triggers the DMA line instead
IP_SIUL2->DIRSR0 |= (1 << 14); // DIRSR0[DIRS14] = 1 (Select DMA Request instead of Interrupt)
/* 4. Final enable of DMA request generation for EIRQ[14] */
IP_SIUL2->DIRER0 |= (1 << 14); // DIRER0[EIRE14] = 1 (Activate DMA request line)
}
void Setup_DMAMUX_Channel0_ToTCD16_Capture_PIT1(void)
{
/* 1. DMAMUX Initialization for eDMA Channel 4 */
// Podľa NXP tabuľky prislúcha SIUL2 DMA request 4 zdrojový index 7u
//IP_DMAMUX_1->CHCFG[4] = DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(7u);
//follow doc ,first disable channel 4, then configure it, and finally enable it
IP_DMAMUX_1->CHCFG[0] = 0u;
/* 2. TCD Configuration for Channel 4 pointing to PIT_1 (Exact S32K3 bare-metal syntax) */
// Source: Current value of PIT_1 Timer 0
IP_TCD->TCD16_SADDR = (uint32_t)&(IP_PIT_1->TIMER[0].CVAL);
IP_TCD->TCD16_SOFF = 0; // Source does not increment
IP_TCD->TCD16_ATTR = 0x0202; // 32-bit source, 32-bit destination
// Minor Loop: Number of bytes transferred per single trigger
// In S32K3 this corresponds to the NBYTES_MLOFFNO register (no minor loop linking)
IP_TCD->NBYTES16.TCD16_NBYTES_MLOFFNO = 4; // Transfer 4 bytes (32-bit) per trigger
// Destination: Our array in RAM
IP_TCD->TCD16_DADDR = (uint32_t)dma_timestamps;
IP_TCD->TCD16_DOFF = 4; // Shift by 4 bytes in RAM after each edge
// Circular buffer: wrap around to the beginning after filling the entire array
IP_TCD->TCD16_DLAST_SGA = -(BUFFER_SIZE * 4);
// Major Loop Counter: Total number of iterations in the loop
//IP_TCD->CITTER20.TCD20_CITER_ELINKNO = BUFFER_SIZE;
IP_TCD->CITER16.TCD16_CITER_ELINKNO = BUFFER_SIZE;
IP_TCD->BITER16.TCD16_BITER_ELINKNO = BUFFER_SIZE;
//IP_TCD->CH16_CSR |= 3u; // ERQ=1, EARQ=1
//enable DMAMUX channel 0
IP_DMAMUX_1->CHCFG[0] = DMAMUX_CHCFG_ENBL_MASK | DMAMUX_CHCFG_SOURCE(6u);
__asm volatile ("nop");
__asm volatile ("nop");
IP_TCD->CH16_CSR |= 3u;
}
And I'm still not able fire up DMA transfer by EIRQ(14) when is this assert. On Debugger I can see flag appear when I change signal on MCU PTD6 pin .
Next I can start manually DMA transfer by TCD16_CSR START bit and on TCD channel CITTER value is decreased and value form PIT1_TIMER[0] is stored to my dma_timestamps array.
Btw: This should be defined in "normal" SRAM section. I had before set this to data_cache section , what lead to DMA "Destination bus error"
new definition:
__attribute__((aligned(32))) __attribute__((section(".mcal_data")))
uint32_t dma_timestamps[BUFFER_SIZE];
but If I skip manual START (need to be never set from beginning of code) and I change signal on PTD6 pin , DMA channel do nothing , CITTER register stay on initialize value.
Please, can you help identify where I have problem?
I still guess that I have issue with proper connection from PTD6-EIRQ(14) asserted flag to the TCD16 channel.
Maybe correct source for DMAMUX channel?
For DMAMUX1-CH[0] I tested all sources (1 to of SUIL2 instances listed on DMAMUX excel table, without any success , but here I'm not sure if my steps was correct too