at least I managed to run the debug mode successfully. To be hornest, which ChibiStudio it is pretty simple, as long you know which cfg file you have to use
So I will try to figure out why the DMA doesn't work
BR
Moderator: RoccoMarco
Code: Select all
// TIM1_CH2
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1));
rccEnableTIM1(FALSE);
rccResetTIM1();
// enable DMA2 clock
//RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
// 6 (TS): Trigger selection: Input 2 (TI2FP2)
// 4 (SMS): Reset Mode
TIM1->SMCR |= 0x0064;
// CC2 is mapped on TI2 -> input capture
TIM1->CCMR1 |= 0x0100;
// Polarity: falling edge
TIM1->CCER |= STM32_TIM_CCER_CC2P;
// CC1 capture enabled
TIM1->CCER |= STM32_TIM_CCER_CC2E;
// CC1 DMA request enabled
TIM1->DIER |= STM32_TIM_DIER_CC2DE;
TIM1->CR2 |= STM32_TIM_CR2_CCDS;
// Enable Counter
TIM1->CR1 |= STM32_TIM_CR1_CEN;
Code: Select all
uint16_t buffer[100];
// Allocate the stream
dmaStreamAllocate( STM32_DMA2_STREAM2, 0, NULL, NULL );
// Set the source Address
dmaStreamSetPeripheral( STM32_DMA2_STREAM2, &GPIOB->IDR);
// Set the destination address
dmaStreamSetMemory0( STM32_DMA2_STREAM2, buffer);
// set the size of the output buffer
dmaStreamSetTransactionSize( STM32_DMA2_STREAM2, 100);
// config 16-bit HWORD transfers, peripheral to memory,
// fixed source address, inc dest address
dmaStreamSetMode( STM32_DMA2_STREAM2,
STM32_DMA_CR_PL(2) | STM32_DMA_CR_PSIZE_HWORD |
STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_DIR_P2M | STM32_DMA_CR_TCIE |
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_TEIE |
STM32_DMA_CR_CHSEL(6) | STM32_DMA_CR_HTIE | STM32_DMA_CR_TCIE);
dmaStreamSetFIFO(STM32_DMA2_STREAM2, 0);
dmaStreamEnable(STM32_DMA2_STREAM2);
dmaWaitCompletion(STM32_DMA2_STREAM2);
dmaStreamRelease(STM32_DMA2_STREAM2);
// --> Transfer to computer Code: Select all
uint16_t samples = 100;
static struct memory_heap *dma_heap;
static uint16_t *buffer;
chHeapObjectInit(dma_heap, (void*)0x20000000, 0x7D0);
buffer = chHeapAlloc(dma_heap, 2*samples);
// Allocate the stream
dmaStreamAllocate( STM32_DMA2_STREAM2, 0, NULL, NULL );
// Set the source Address
dmaStreamSetPeripheral(STM32_DMA2_STREAM2, &(GPIOB->IDR));
// Set the destination address
dmaStreamSetMemory0( STM32_DMA2_STREAM2, buffer);
// set the size of the output buffer
dmaStreamSetTransactionSize(STM32_DMA2_STREAM2, samples);Code: Select all
if (dma_heap == NULL) {
palSetPad(GPIOB, 6);
}Code: Select all
static struct memory_heap dma_heap;
chHeapObjectInit(&dma_heap, (void*)0x20000000, 0x7D0);
Skadi wrote:Just a comprehension question, for me it looks like the SRAM is accessed as bytes. Because the memory 0 address starts at 0x2000 0008 and not at a multiple of 16 (0xF). Or are 8 bit just an offset of the start address?
rew wrote:You are mixing bytes, bits and different numbers. 16 is not 0xf, but 0x10. you say "8 bit" when you mean "8 bytes", I think.
rew wrote:That requires a bit of accounting that goes at 0x2000 0000 - 0x2000 0007.