Good morning everyone,
I'm trying to implement DMA on the k1 to then be able to link the ADC results to it.
I tried to configure the DMA registers as follows:
void DMA_Init(void)
{
uint8_t i = 0;
//just for safe, for configuration deactive DMA channel on CSR register:
DMA->TCD->CSR &= !DMA_TCD_CSR_ACTIVE_MASK; //put 0 on ACTIVE bitof CSR register
//1. Write to the CR if a configuration other than the default is desired.
DMA->CR = DMA_CR_EMLM(1)|DMA_CR_ERCA(1);//enable minor loop. use round robin prior
for (i = 0; i<DMAD_CHAN_NMB; i++) //cicla su tutti i canali di DMA usati
{
// 4. Write the 32-byte TCD for each channel that may request service.
// 4.1 Source ADDRESS:
DMA->TCD->SADDR = DMAD_CfgTable[i].SourceAddr;
// 4.2 Source ADDRESS OFFSET:
DMA->TCD->SOFF = DMA_TCD_SOFF_SOFF(0); //proviamo a usare un offset 0
// 4.3 Transfer Attributes, SMOD, SSIZE, DMOD, DSIZE:
DMA->TCD->ATTR =
DMA_TCD_ATTR_SMOD(0) |
DMA_TCD_ATTR_SSIZE(0x2) | //0x2 = 010b -> 32-bit //TODO ROR: mettere in tabella di config
DMA_TCD_ATTR_DMOD(0) |
DMA_TCD_ATTR_DSIZE(0x2) ; //0x2 = 010b -> 32-bit //TODO ROR: mettere in tabella di config
// 4.4 Minor Byte Count, Signed Minor Loop Offset N, Signed Minor Loop Offset Y:
DMA->TCD->NBYTES.MLNO = DMA_TCD_NBYTES_MLNO_NBYTES(0x4); //proviamo a usare 4 byte
// 4.5 Last Source Address Adjustment:
DMA->TCD->SLAST = 0x0; //proviamo a usare un adjustment di 0
// 4.6 Destination Address:
DMA->TCD->DADDR = DMAD_CfgTable[i].DestinAddr;
// 4.7 Signed Destination Address Offset:
DMA->TCD->DOFF = DMA_TCD_DOFF_DOFF(0); //proviamo a usare un offset 0
// 4.9 Last Destination Address Adjustment/Scatter Gather Address :
DMA->TCD->DLASTSGA = 0x0; //proviamo a usare un adjustment di 0
// 4.11 Beginning Minor Loop Link, Major Loop Count, Beginning Minor Loop Link, Major Loop Count:
DMA->TCD->BITER.ELINKNO = 0x0001; //test wit channel-to-channel linking disable 0x0001
DMA->TCD->BITER.ELINKYES = 0x0001; //test wit channel-to-channel linking disable 0x0001
}
// 5. Enable any hardware service requests via the ERQ register.
DMA->ERQ = 0x00000000; //all disabled at the moment
// 6. Request channel service via either:
// - Software: setting the TCDn_CSR[START]
// - Hardware: slave device asserting its eDMA peripheral request signal
for (i = 0; i<DMAD_CHAN_NMB; i++) //cicla su tutti i canali usati di DMA
{
//Set START and ACTIVE on Control and Status:
DMA->TCD->CSR = DMA_TCD_CSR_START(1) | DMA_TCD_CSR_ACTIVE(1);
}
//Activate DMA:
DMA->CR = DMA_CR_ACTIVE(1);//eDMA is executing a channel
}
In debug a problem is generated(HardFault) as soon as we execute DMA->TCD->CSR = DMA_TCD_CSR_START(1) | DMA_TCD_CSR_ACTIVE(1);
The initialization configuration seems correct even studying the S32K-RM manual reference. are there any registers missing to configure? any help/advice is welcome. thanks in advance