native/usbuart: Move platform dependant parts to platform.h
This commit is contained in:
parent
16b9c1e83f
commit
35d6adc236
@ -47,6 +47,7 @@ blackmagic: $(OBJ)
|
|||||||
|
|
||||||
clean: host_clean
|
clean: host_clean
|
||||||
$(RM) *.o *.d *~ blackmagic $(HOSTFILES)
|
$(RM) *.o *.d *~ blackmagic $(HOSTFILES)
|
||||||
|
$(RM) platforms/*/*.o platforms/*/*.d mapfile
|
||||||
|
|
||||||
-include *.d
|
-include *.d
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ CC = $(CROSS_COMPILE)gcc
|
|||||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||||
|
|
||||||
CFLAGS += -Istm32/include -mcpu=cortex-m3 -mthumb \
|
CFLAGS += -Istm32/include -mcpu=cortex-m3 -mthumb \
|
||||||
-DSTM32F1 -I../libopencm3/include
|
-DSTM32F1 -DBLACKMAGIC -I../libopencm3/include -Iplatforms/native \
|
||||||
|
-Iplatforms/stm32
|
||||||
|
|
||||||
LDFLAGS_BOOT = -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
|
LDFLAGS_BOOT = -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
|
||||||
-Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc -lnosys \
|
-Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc -lnosys \
|
||||||
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
|
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "jtag_scan.h"
|
#include "jtag_scan.h"
|
||||||
#include "usbuart.h"
|
#include <usbuart.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ extern usbd_device *usbdev;
|
|||||||
#define USB_VBUS_IRQ NVIC_EXTI15_10_IRQ
|
#define USB_VBUS_IRQ NVIC_EXTI15_10_IRQ
|
||||||
|
|
||||||
#define LED_PORT GPIOB
|
#define LED_PORT GPIOB
|
||||||
|
#define LED_PORT_UART GPIOB
|
||||||
#define LED_UART GPIO2
|
#define LED_UART GPIO2
|
||||||
#define LED_IDLE_RUN GPIO10
|
#define LED_IDLE_RUN GPIO10
|
||||||
#define LED_ERROR GPIO11
|
#define LED_ERROR GPIO11
|
||||||
@ -99,10 +100,19 @@ extern usbd_device *usbdev;
|
|||||||
* TIM3 is used for traceswo capture and must be highest priority.
|
* TIM3 is used for traceswo capture and must be highest priority.
|
||||||
*/
|
*/
|
||||||
#define IRQ_PRI_USB (2 << 4)
|
#define IRQ_PRI_USB (2 << 4)
|
||||||
#define IRQ_PRI_USART1 (1 << 4)
|
#define IRQ_PRI_USBUSART (1 << 4)
|
||||||
#define IRQ_PRI_USB_VBUS (14 << 4)
|
#define IRQ_PRI_USB_VBUS (14 << 4)
|
||||||
#define IRQ_PRI_TIM3 (0 << 4)
|
#define IRQ_PRI_TIM3 (0 << 4)
|
||||||
|
|
||||||
|
#define USBUSART USART1
|
||||||
|
#define USBUSART_CR1 USART1_CR1
|
||||||
|
#define USBUSART_IRQ NVIC_USART1_IRQ
|
||||||
|
#define USBUSART_APB_ENR RCC_APB2ENR
|
||||||
|
#define USBUSART_CLK_ENABLE RCC_APB2ENR_USART1EN
|
||||||
|
#define USBUSART_PORT GPIOA
|
||||||
|
#define USBUSART_TX_PIN GPIO9
|
||||||
|
#define USBUSART_ISR usart1_isr
|
||||||
|
|
||||||
#define DEBUG(...)
|
#define DEBUG(...)
|
||||||
|
|
||||||
extern uint8_t running_status;
|
extern uint8_t running_status;
|
||||||
@ -174,4 +184,3 @@ static inline u16 _gpio_get(u32 gpioport, u16 gpios)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -26,62 +26,64 @@
|
|||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/cdc.h>
|
#include <libopencm3/usb/cdc.h>
|
||||||
|
|
||||||
#include "platform.h"
|
#include <platform.h>
|
||||||
|
|
||||||
void usbuart_init(void)
|
void usbuart_init(void)
|
||||||
{
|
{
|
||||||
|
#if defined(BLACKMAGIC)
|
||||||
/* On mini hardware, UART and SWD share connector pins.
|
/* On mini hardware, UART and SWD share connector pins.
|
||||||
* Don't enable UART if we're being debugged. */
|
* Don't enable UART if we're being debugged. */
|
||||||
if ((platform_hwversion() == 1) && (SCS_DEMCR & SCS_DEMCR_TRCENA))
|
if ((platform_hwversion() == 1) && (SCS_DEMCR & SCS_DEMCR_TRCENA))
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_USART1EN);
|
rcc_peripheral_enable_clock(&USBUSART_APB_ENR, USBUSART_CLK_ENABLE);
|
||||||
|
|
||||||
/* UART1 TX to 'alternate function output push-pull' */
|
/* UART TX to 'alternate function output push-pull' */
|
||||||
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
|
gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ,
|
||||||
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO9);
|
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN);
|
||||||
|
|
||||||
/* Setup UART parameters. */
|
/* Setup UART parameters. */
|
||||||
usart_set_baudrate(USART1, 38400);
|
usart_set_baudrate(USBUSART, 38400);
|
||||||
usart_set_databits(USART1, 8);
|
usart_set_databits(USBUSART, 8);
|
||||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
usart_set_stopbits(USBUSART, USART_STOPBITS_1);
|
||||||
usart_set_mode(USART1, USART_MODE_TX_RX);
|
usart_set_mode(USBUSART, USART_MODE_TX_RX);
|
||||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
usart_set_parity(USBUSART, USART_PARITY_NONE);
|
||||||
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
usart_set_flow_control(USBUSART, USART_FLOWCONTROL_NONE);
|
||||||
|
|
||||||
/* Finally enable the USART. */
|
/* Finally enable the USART. */
|
||||||
usart_enable(USART1);
|
usart_enable(USBUSART);
|
||||||
|
|
||||||
/* Enable interrupts */
|
/* Enable interrupts */
|
||||||
USART1_CR1 |= USART_CR1_RXNEIE;
|
USBUSART_CR1 |= USART_CR1_RXNEIE;
|
||||||
nvic_set_priority(NVIC_USART1_IRQ, IRQ_PRI_USART1);
|
nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART);
|
||||||
nvic_enable_irq(NVIC_USART1_IRQ);
|
nvic_enable_irq(USBUSART_IRQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
|
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
|
||||||
{
|
{
|
||||||
usart_set_baudrate(USART1, coding->dwDTERate);
|
usart_set_baudrate(USBUSART, coding->dwDTERate);
|
||||||
usart_set_databits(USART1, coding->bDataBits);
|
usart_set_databits(USBUSART, coding->bDataBits);
|
||||||
switch(coding->bCharFormat) {
|
switch(coding->bCharFormat) {
|
||||||
case 0:
|
case 0:
|
||||||
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
usart_set_stopbits(USBUSART, USART_STOPBITS_1);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
usart_set_stopbits(USART1, USART_STOPBITS_1_5);
|
usart_set_stopbits(USBUSART, USART_STOPBITS_1_5);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
usart_set_stopbits(USART1, USART_STOPBITS_2);
|
usart_set_stopbits(USBUSART, USART_STOPBITS_2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch(coding->bParityType) {
|
switch(coding->bParityType) {
|
||||||
case 0:
|
case 0:
|
||||||
usart_set_parity(USART1, USART_PARITY_NONE);
|
usart_set_parity(USBUSART, USART_PARITY_NONE);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
usart_set_parity(USART1, USART_PARITY_ODD);
|
usart_set_parity(USBUSART, USART_PARITY_ODD);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
usart_set_parity(USART1, USART_PARITY_EVEN);
|
usart_set_parity(USBUSART, USART_PARITY_EVEN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,16 +96,18 @@ void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
|||||||
int len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT,
|
int len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT,
|
||||||
buf, CDCACM_PACKET_SIZE);
|
buf, CDCACM_PACKET_SIZE);
|
||||||
|
|
||||||
|
#if defined(BLACKMAGIC)
|
||||||
/* Don't bother if uart is disabled.
|
/* Don't bother if uart is disabled.
|
||||||
* This will be the case on mini while we're being debugged.
|
* This will be the case on mini while we're being debugged.
|
||||||
*/
|
*/
|
||||||
if(!(RCC_APB2ENR & RCC_APB2ENR_USART1EN))
|
if(!(RCC_APB2ENR & RCC_APB2ENR_USART1EN))
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
gpio_set(LED_PORT, LED_UART);
|
gpio_set(LED_PORT_UART, LED_UART);
|
||||||
for(int i = 0; i < len; i++)
|
for(int i = 0; i < len; i++)
|
||||||
usart_send_blocking(USART1, buf[i]);
|
usart_send_blocking(USBUSART, buf[i]);
|
||||||
gpio_clear(LED_PORT, LED_UART);
|
gpio_clear(LED_PORT_UART, LED_UART);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t uart_usb_buf[CDCACM_PACKET_SIZE];
|
static uint8_t uart_usb_buf[CDCACM_PACKET_SIZE];
|
||||||
@ -112,7 +116,7 @@ static uint8_t uart_usb_buf_size;
|
|||||||
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
|
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
|
||||||
{
|
{
|
||||||
if (!uart_usb_buf_size) {
|
if (!uart_usb_buf_size) {
|
||||||
gpio_clear(LED_PORT, LED_UART);
|
gpio_clear(LED_PORT_UART, LED_UART);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,11 +124,11 @@ void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
|
|||||||
uart_usb_buf_size = 0;
|
uart_usb_buf_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usart1_isr(void)
|
void USBUSART_ISR(void)
|
||||||
{
|
{
|
||||||
char c = usart_recv(USART1);
|
char c = usart_recv(USBUSART);
|
||||||
|
|
||||||
gpio_set(LED_PORT, LED_UART);
|
gpio_set(LED_PORT_UART, LED_UART);
|
||||||
|
|
||||||
/* Try to send now */
|
/* Try to send now */
|
||||||
if (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, &c, 1) == 1)
|
if (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, &c, 1) == 1)
|
||||||
|
@ -31,4 +31,3 @@ void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep);
|
|||||||
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep);
|
void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user