FSMC, DMA and interrupts
Posted: Thu Aug 18, 2011 7:41 pm
I'm using the STM32 FSMC to talk to a QVGA LCD with onboard framebuffer. I want to use DMA to do 2^16 transfers at a time, freeing the CPU for other things.
I already have DMA2Channel5 up and running (manually setting up the hardware through it's registers). Up until now i just waited for the transfer complete flag:
etc.
To give other threads a chance while using DMA, things need to become interrupt-based. This is what i came up with:
in the LCD thread, when ready to write (DMA now has DMA_CCR5_TCIE enabled for IRQ generation):
main:
Interrupt handler:
This looked like it should work to me, until I found out that the DMA helper driver already has interrupt handlers defined for all DMA channels. I took a shot at the dma helper driver, but i don't have a clue as to how to use and configure it honestly. Could someone please explain how to make this work?
Also, is a semaphore faster than events for this case? Only one thread will be communicating with FSMC/DMA, so events would be an option also.
I like this OS a lot, but the source sometimes is hard to read. Maybe some clear examples of events, semaphores, mutexes and mailboxes should be documented on the site.
I already have DMA2Channel5 up and running (manually setting up the hardware through it's registers). Up until now i just waited for the transfer complete flag:
Code: Select all
DMA2_Channel5->CCR |= DMA_CCR5_EN; //enable DMA
while (!(DMA2->ISR & DMA_ISR_TCIF5)); //wait for completion
DMA2->IFCR |= DMA_IFCR_CGIF5; //clear TC flag
DMA2_Channel5->CCR &= ~DMA_CCR5_EN; //disable DMA
To give other threads a chance while using DMA, things need to become interrupt-based. This is what i came up with:
in the LCD thread, when ready to write (DMA now has DMA_CCR5_TCIE enabled for IRQ generation):
Code: Select all
chBSemWait(&bsemFSMC_IRQ); //wait for DMA completion
DMA2_Channel5->CCR &= ~DMA_CCR5_EN; //disable DMA channel
// <... some code ...>
DMA2_Channel5->CCR |= DMA_CCR5_EN; //enable DMAmain:
Code: Select all
chBSemInit(&bsemFSMC_IRQ, FALSE); //Init as taken == false
NVIC_EnableIRQ(DMA2_Channel4_5_IRQn); //enable IRQ vector in NVICInterrupt handler:
Code: Select all
CH_IRQ_HANDLER(DMA2_Ch4_5_IRQHandler) {
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
// DMA2Ch5 global interrupt clear
DMA2->IFCR = DMA_IFCR_CGIF4;
DMA2->IFCR = DMA_IFCR_CGIF5;
/* Wakes up the thread.*/
chBSemSignalI(&bsemFSMC_IRQ);
chSysUnlockFromIsr();
CH_IRQ_EPILOGUE();
}This looked like it should work to me, until I found out that the DMA helper driver already has interrupt handlers defined for all DMA channels. I took a shot at the dma helper driver, but i don't have a clue as to how to use and configure it honestly. Could someone please explain how to make this work?
Also, is a semaphore faster than events for this case? Only one thread will be communicating with FSMC/DMA, so events would be an option also.
I like this OS a lot, but the source sometimes is hard to read. Maybe some clear examples of events, semaphores, mutexes and mailboxes should be documented on the site.