AnsweredAssumed Answered

KL27Z DMA from TPM2,CH0 CnV register causes bus error

Question asked by James Collier on Oct 6, 2017
Latest reply on Oct 9, 2017 by James Collier

I am using a Kinetis KL27Z prototyping board and KSDK 2.2.1 generated by MCUXpresso.

In the MCUXpresso pins tool I've enabled DMA channel 3 routed to the TPM2_CH0_Event. I've also enabled TPM2,0 on pin 37. On the board itself I have a signal generator attached to pin 37.

 

I've configured the TPM2,0 in input capture mode and set it to trigger DMA. I want to DMA the channel counter (CnV) register to a memory location but on the trigger the DMA BSE bit is set.

 

//TPM is initialised with:

TPM_Init(TPM2, &tpmConfig); //default config
TPM_SetupInputCapture(TPM2, kTPM_Chnl_0, kTPM_RiseAndFallEdge);
TPM2->SC |= TPM_SC_DMA_MASK;
TPM2->CONTROLS[0].CnSC |= TPM_CnSC_DMA_MASK;

 

//set the DMA source address

uint32_t cnv_reg = (uint32_t)&(TPM0->CONTROLS[kTPM_Chnl_0].CnV);

 

//Then DMA

DMAMUX_Init(DMAMUX0);

DMAMUX_SetSource(DMAMUX0, DMA_CHANNEL3_IDX, (uint8_t)kDmaRequestMux0TPM2Channel0);

DMA_Init(DMA0);

dma_handle_t dma_handle;
DMA_CreateHandle(&dma_handle, DMA0, 3U);

DMA_PrepareTransfer(&dma_config,
                                      (void*)cnv_reg, sizeof(uint32_t),
                                      &output_buffer, sizeof(uint32_t),
                                      0x4, kDMA_PeripheralToMemory);
DMA_SubmitTransfer(&dma_handle, &dma_config, kDMA_NoOptions);
DMA_EnableCycleSteal(DMA0, 3U, true);
DMA_StartTransfer(&dma_handle);

 

//Start the TPM timer

TPM_StartTimer(TPM2, kTPM_SystemClock);

 

//And finally wait for results (turn on the output of the signal generator manually)

PRINTF("TPM STATUS: 0x%x  DMA_DSR_BCR: 0x%x\r", TPM2->STATUS, DMA0->DMA[3U].DSR_BCR);

//this results in "TPM STATUS: 0x101  DMA_DSR_BCR: 0x210ffffc" printed (note the BSE bit is set)

How can I avoid a bus error here?

Thanks very much for any help.

Outcomes