KL27Z DMA from TPM2,CH0 CnV register causes bus error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL27Z DMA from TPM2,CH0 CnV register causes bus error

Jump to solution
642 Views
jamescollier
Contributor I

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.

0 Kudos
1 Solution
491 Views
mjbcswitzerland
Specialist V

James

What is cnv_reg? If the BES bit is set it would mean that this is an invalid address.

Regards

Mark

View solution in original post

2 Replies
492 Views
mjbcswitzerland
Specialist V

James

What is cnv_reg? If the BES bit is set it would mean that this is an invalid address.

Regards

Mark

491 Views
jamescollier
Contributor I

I've edited the post to show what cnv_reg is.

Note that it now becomes obvious what the problem is: cnv_reg is pointing to TPM0, when TPM2 was initialised and intended for use.

Thanks for the help!

0 Kudos