Compare commits
40 Commits
main
...
fix/newlib
Author | SHA1 | Date |
---|---|---|
dragonmux | af4025ef04 | 2 years ago |
dragonmux | 22f6a098df | 2 years ago |
dragonmux | 8028107178 | 2 years ago |
dragonmux | eb4c85b766 | 2 years ago |
dragonmux | 732567a41a | 2 years ago |
dragonmux | 6030872c53 | 2 years ago |
dragonmux | d5a1d5b909 | 2 years ago |
dragonmux | 9f72cbca04 | 2 years ago |
dragonmux | 7550d0c2c1 | 2 years ago |
dragonmux | 8b87546a01 | 2 years ago |
dragonmux | 43f8b397a1 | 2 years ago |
dragonmux | 5a25269333 | 2 years ago |
dragonmux | 2746bd7bcc | 2 years ago |
dragonmux | d4d0900fb9 | 2 years ago |
dragonmux | f053c2a219 | 2 years ago |
dragonmux | 811c643128 | 2 years ago |
dragonmux | 3282087db6 | 2 years ago |
dragonmux | 7497f1d441 | 2 years ago |
dragonmux | 1ac6de276e | 2 years ago |
dragonmux | 8936069244 | 2 years ago |
dragonmux | c9ba465549 | 2 years ago |
dragonmux | e7bd8135b9 | 2 years ago |
dragonmux | c132d08981 | 2 years ago |
dragonmux | 9b2eb0caad | 2 years ago |
dragonmux | f491aff745 | 2 years ago |
dragonmux | fe4e5fbbbb | 2 years ago |
dragonmux | 41c7760261 | 2 years ago |
dragonmux | 3d5018b1e2 | 2 years ago |
dragonmux | c492fa7948 | 2 years ago |
dragonmux | bf164edf43 | 2 years ago |
dragonmux | 3faf4221e3 | 2 years ago |
dragonmux | e07cde4302 | 2 years ago |
dragonmux | d6c1aee96a | 2 years ago |
dragonmux | 1b42438855 | 2 years ago |
dragonmux | a4ba390d2d | 2 years ago |
dragonmux | 3e1985e961 | 2 years ago |
dragonmux | 3c2683b6d9 | 2 years ago |
dragonmux | cefae28c27 | 2 years ago |
dragonmux | 038299db3c | 2 years ago |
dragonmux | e7ecda6faf | 2 years ago |
26 changed files with 546 additions and 444 deletions
@ -0,0 +1,142 @@ |
|||
/*
|
|||
* This file is part of the Black Magic Debug project. |
|||
* |
|||
* Copyright (C) 2022 1BitSquared <info@1bitsquared.com> |
|||
* Written by Rachel Mant <git@dragonmux.network> |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) |
|||
#include <libopencm3/stm32/usart.h> |
|||
#include <libopencm3/stm32/dma.h> |
|||
#elif defined(LM4F) |
|||
#include <libopencm3/lm4f/uart.h> |
|||
#else |
|||
#error "Unknown processor target" |
|||
#endif |
|||
#include <libopencm3/usb/usbd.h> |
|||
#include <libopencm3/usb/cdc.h> |
|||
|
|||
#include "general.h" |
|||
#include "usbuart.h" |
|||
#include "usb.h" |
|||
#include "aux_serial.h" |
|||
|
|||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) |
|||
static char aux_serial_transmit_buffer[2U][TX_BUF_SIZE]; |
|||
static uint8_t aux_serial_transmit_buffer_index; |
|||
extern uint8_t aux_serial_transmit_buffer_consumed; |
|||
#elif defined(LM4F) |
|||
static char aux_serial_transmit_buffer[FIFO_SIZE]; |
|||
#endif |
|||
|
|||
void aux_serial_set_encoding(struct usb_cdc_line_coding *coding) |
|||
{ |
|||
usart_set_baudrate(USBUSART, coding->dwDTERate); |
|||
|
|||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) |
|||
if (coding->bParityType) |
|||
usart_set_databits(USBUSART, (coding->bDataBits + 1 <= 8 ? 8 : 9)); |
|||
else |
|||
usart_set_databits(USBUSART, (coding->bDataBits <= 8 ? 8 : 9)); |
|||
#elif defined(LM4F) |
|||
uart_set_databits(USBUART, coding->bDataBits); |
|||
#endif |
|||
|
|||
switch(coding->bCharFormat) { |
|||
case 0: |
|||
usart_set_stopbits(USBUSART, USART_STOPBITS_1); |
|||
break; |
|||
case 1: |
|||
usart_set_stopbits(USBUSART, USART_STOPBITS_1_5); |
|||
break; |
|||
case 2: |
|||
default: |
|||
usart_set_stopbits(USBUSART, USART_STOPBITS_2); |
|||
break; |
|||
} |
|||
|
|||
switch(coding->bParityType) { |
|||
case 0: |
|||
usart_set_parity(USBUSART, USART_PARITY_NONE); |
|||
break; |
|||
case 1: |
|||
usart_set_parity(USBUSART, USART_PARITY_ODD); |
|||
break; |
|||
case 2: |
|||
default: |
|||
usart_set_parity(USBUSART, USART_PARITY_EVEN); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) |
|||
char *aux_serial_current_transmit_buffer(void) |
|||
{ |
|||
return aux_serial_transmit_buffer[aux_serial_transmit_buffer_index]; |
|||
} |
|||
|
|||
size_t aux_serial_transmit_buffer_fullness(void) |
|||
{ |
|||
return aux_serial_transmit_buffer_consumed; |
|||
} |
|||
|
|||
/*
|
|||
* Changes USBUSART TX buffer in which data is accumulated from USB. |
|||
* Filled buffer is submitted to DMA for transfer. |
|||
*/ |
|||
void aux_serial_switch_transmit_buffers(void) |
|||
{ |
|||
/* Make the buffer we've been filling the active DMA buffer, and swap to the other */ |
|||
dma_set_memory_address(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, (uintptr_t)aux_serial_current_transmit_buffer()); |
|||
dma_set_number_of_data(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, aux_serial_transmit_buffer_consumed); |
|||
dma_enable_channel(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN); |
|||
|
|||
/* Change active buffer */ |
|||
aux_serial_transmit_buffer_consumed = 0; |
|||
aux_serial_transmit_buffer_index ^= 1; |
|||
} |
|||
|
|||
void aux_serial_send(const size_t len) |
|||
{ |
|||
aux_serial_transmit_buffer_consumed += len; |
|||
|
|||
/* If DMA is idle, schedule new transfer */ |
|||
if (len && tx_trfr_cplt) |
|||
{ |
|||
tx_trfr_cplt = false; |
|||
aux_serial_switch_transmit_buffers(); |
|||
|
|||
/* Enable LED */ |
|||
usbuart_set_led_state(TX_LED_ACT, true); |
|||
} |
|||
} |
|||
#elif defined(LM4F) |
|||
char *aux_serial_current_transmit_buffer(void) |
|||
{ |
|||
return aux_serial_transmit_buffer; |
|||
} |
|||
|
|||
size_t aux_serial_transmit_buffer_fullness(void) |
|||
{ |
|||
return 0; |
|||
} |
|||
|
|||
void aux_serial_send(const size_t len) |
|||
{ |
|||
for(size_t i = 0; i < len; ++i) |
|||
uart_send_blocking(USBUART, aux_serial_transmit_buffer[i]); |
|||
} |
|||
#endif |
@ -0,0 +1,41 @@ |
|||
/*
|
|||
* This file is part of the Black Magic Debug project. |
|||
* |
|||
* Copyright (C) 2022 1BitSquared <info@1bitsquared.com> |
|||
* Written by Rachel Mant <git@dragonmux.network> |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
#ifndef AUX_SERIAL_H |
|||
#define AUX_SERIAL_H |
|||
|
|||
#include <stddef.h> |
|||
#include <libopencm3/usb/usbd.h> |
|||
#include <libopencm3/usb/cdc.h> |
|||
|
|||
void aux_serial_init(void); |
|||
void aux_serial_set_encoding(struct usb_cdc_line_coding *coding); |
|||
|
|||
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F4) |
|||
void aux_serial_switch_transmit_buffers(void); |
|||
#endif |
|||
|
|||
/* Get the current transmit buffer to stage data into */ |
|||
char *aux_serial_current_transmit_buffer(void); |
|||
/* Get how full the current transmit buffer is */ |
|||
size_t aux_serial_transmit_buffer_fullness(void); |
|||
/* Send a number of bytes staged into the current transmit bufer */ |
|||
void aux_serial_send(size_t len); |
|||
|
|||
#endif /*AUX_SERIAL_H*/ |
Loading…
Reference in new issue