Skip to content

Commit

Permalink
working now
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jan 29, 2018
1 parent 7fa4808 commit 8b7e849
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions board/drivers/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,33 @@ void uart_dma_drain() {

enter_critical_section();

// disable DMA
//q->uart->CR3 &= ~USART_CR3_DMAR;
DMA2_Stream5->CR &= ~DMA_SxCR_EN;
while (DMA2_Stream5->CR & DMA_SxCR_EN);

int i;
for (i = 0; i < USART1_DMA_LEN - DMA2_Stream5->NDTR; i++) {
char c = usart1_dma[i];
uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE;
if (next_w_ptr != q->r_ptr_rx) {
q->elems_rx[q->w_ptr_rx] = c;
q->w_ptr_rx = next_w_ptr;
if (DMA2_Stream5->NDTR != USART1_DMA_LEN) {
// disable DMA
//q->uart->CR3 &= ~USART_CR3_DMAR;
DMA2_Stream5->CR &= ~DMA_SxCR_EN;
while (DMA2_Stream5->CR & DMA_SxCR_EN);

int i;
for (i = 0; i < USART1_DMA_LEN - DMA2_Stream5->NDTR; i++) {
char c = usart1_dma[i];
uint16_t next_w_ptr = (q->w_ptr_rx + 1) % FIFO_SIZE;
if (next_w_ptr != q->r_ptr_rx) {
q->elems_rx[q->w_ptr_rx] = c;
q->w_ptr_rx = next_w_ptr;
}
}
}

// reset DMA len
DMA2_Stream5->NDTR = USART1_DMA_LEN;
// reset DMA len
DMA2_Stream5->NDTR = USART1_DMA_LEN;

// clear interrupts
DMA2->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5;
//DMA2->HIFCR = DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5;
// clear interrupts
DMA2->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5;
//DMA2->HIFCR = DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5;

// enable DMA
DMA2_Stream5->CR |= DMA_SxCR_EN;
//q->uart->CR3 |= USART_CR3_DMAR;
// enable DMA
DMA2_Stream5->CR |= DMA_SxCR_EN;
//q->uart->CR3 |= USART_CR3_DMAR;
}

exit_critical_section();
}
Expand Down Expand Up @@ -226,7 +228,7 @@ void uart_init(USART_TypeDef *u, int baud) {
DMA2_Stream5->PAR = (uint32_t)&(USART1->DR);

// channel4, increment memory, periph -> memory, enable
DMA2_Stream5->CR = DMA_SxCR_CHSEL_2 | DMA_SxCR_MINC | DMA_SxCR_HTIE | DMA_SxCR_EN;
DMA2_Stream5->CR = DMA_SxCR_CHSEL_2 | DMA_SxCR_MINC | DMA_SxCR_HTIE | DMA_SxCR_TCIE | DMA_SxCR_EN;

// this one uses DMA receiver
u->CR3 = USART_CR3_DMAR;
Expand Down

0 comments on commit 8b7e849

Please sign in to comment.