aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Bonnes2013-01-12 20:44:43 +0100
committerUwe Bonnes2013-01-21 11:02:43 +0100
commit35d6adc236f54e94231b1959eb2d16b785c7733a (patch)
tree3236deebb77ede4fee4ee78244030cc656567e97
parent16b9c1e83f5887b8572ad7f4955e586e1fc2ae9d (diff)
native/usbuart: Move platform dependant parts to platform.h
-rw-r--r--src/Makefile1
-rw-r--r--src/platforms/native/Makefile.inc4
-rw-r--r--src/platforms/native/platform.c2
-rw-r--r--src/platforms/native/platform.h13
-rw-r--r--src/platforms/native/usbuart.c64
-rw-r--r--src/platforms/stm32/usbuart.h (renamed from src/platforms/native/usbuart.h)1
6 files changed, 50 insertions, 35 deletions
diff --git a/src/Makefile b/src/Makefile
index 6699191..d9f3e9e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -47,6 +47,7 @@ blackmagic: $(OBJ)
clean: host_clean
$(RM) *.o *.d *~ blackmagic $(HOSTFILES)
+ $(RM) platforms/*/*.o platforms/*/*.d mapfile
-include *.d
diff --git a/src/platforms/native/Makefile.inc b/src/platforms/native/Makefile.inc
index dc0e743..585c50d 100644
--- a/src/platforms/native/Makefile.inc
+++ b/src/platforms/native/Makefile.inc
@@ -3,7 +3,9 @@ CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
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 \
-Wl,-T,platforms/stm32/blackmagic.ld -nostartfiles -lc -lnosys \
-Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c
index 5b90976..0f8b78a 100644
--- a/src/platforms/native/platform.c
+++ b/src/platforms/native/platform.c
@@ -32,7 +32,7 @@
#include "platform.h"
#include "jtag_scan.h"
-#include "usbuart.h"
+#include <usbuart.h>
#include <ctype.h>
diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h
index 17841ea..30f063d 100644
--- a/src/platforms/native/platform.h
+++ b/src/platforms/native/platform.h
@@ -90,6 +90,7 @@ extern usbd_device *usbdev;
#define USB_VBUS_IRQ NVIC_EXTI15_10_IRQ
#define LED_PORT GPIOB
+#define LED_PORT_UART GPIOB
#define LED_UART GPIO2
#define LED_IDLE_RUN GPIO10
#define LED_ERROR GPIO11
@@ -99,10 +100,19 @@ extern usbd_device *usbdev;
* TIM3 is used for traceswo capture and must be highest priority.
*/
#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_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(...)
extern uint8_t running_status;
@@ -174,4 +184,3 @@ static inline u16 _gpio_get(u32 gpioport, u16 gpios)
#endif
#endif
-
diff --git a/src/platforms/native/usbuart.c b/src/platforms/native/usbuart.c
index 35a7d7d..3d07b33 100644
--- a/src/platforms/native/usbuart.c
+++ b/src/platforms/native/usbuart.c
@@ -26,62 +26,64 @@
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/cdc.h>
-#include "platform.h"
+#include <platform.h>
void usbuart_init(void)
{
+#if defined(BLACKMAGIC)
/* On mini hardware, UART and SWD share connector pins.
* Don't enable UART if we're being debugged. */
if ((platform_hwversion() == 1) && (SCS_DEMCR & SCS_DEMCR_TRCENA))
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' */
- gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO9);
+ /* UART TX to 'alternate function output push-pull' */
+ gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN);
/* Setup UART parameters. */
- usart_set_baudrate(USART1, 38400);
- usart_set_databits(USART1, 8);
- usart_set_stopbits(USART1, USART_STOPBITS_1);
- usart_set_mode(USART1, USART_MODE_TX_RX);
- usart_set_parity(USART1, USART_PARITY_NONE);
- usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
+ usart_set_baudrate(USBUSART, 38400);
+ usart_set_databits(USBUSART, 8);
+ usart_set_stopbits(USBUSART, USART_STOPBITS_1);
+ usart_set_mode(USBUSART, USART_MODE_TX_RX);
+ usart_set_parity(USBUSART, USART_PARITY_NONE);
+ usart_set_flow_control(USBUSART, USART_FLOWCONTROL_NONE);
/* Finally enable the USART. */
- usart_enable(USART1);
+ usart_enable(USBUSART);
/* Enable interrupts */
- USART1_CR1 |= USART_CR1_RXNEIE;
- nvic_set_priority(NVIC_USART1_IRQ, IRQ_PRI_USART1);
- nvic_enable_irq(NVIC_USART1_IRQ);
+ USBUSART_CR1 |= USART_CR1_RXNEIE;
+ nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART);
+ nvic_enable_irq(USBUSART_IRQ);
}
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
{
- usart_set_baudrate(USART1, coding->dwDTERate);
- usart_set_databits(USART1, coding->bDataBits);
+ usart_set_baudrate(USBUSART, coding->dwDTERate);
+ usart_set_databits(USBUSART, coding->bDataBits);
switch(coding->bCharFormat) {
case 0:
- usart_set_stopbits(USART1, USART_STOPBITS_1);
+ usart_set_stopbits(USBUSART, USART_STOPBITS_1);
break;
case 1:
- usart_set_stopbits(USART1, USART_STOPBITS_1_5);
+ usart_set_stopbits(USBUSART, USART_STOPBITS_1_5);
break;
case 2:
- usart_set_stopbits(USART1, USART_STOPBITS_2);
+ usart_set_stopbits(USBUSART, USART_STOPBITS_2);
break;
}
switch(coding->bParityType) {
case 0:
- usart_set_parity(USART1, USART_PARITY_NONE);
+ usart_set_parity(USBUSART, USART_PARITY_NONE);
break;
case 1:
- usart_set_parity(USART1, USART_PARITY_ODD);
+ usart_set_parity(USBUSART, USART_PARITY_ODD);
break;
case 2:
- usart_set_parity(USART1, USART_PARITY_EVEN);
+ usart_set_parity(USBUSART, USART_PARITY_EVEN);
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,
buf, CDCACM_PACKET_SIZE);
+#if defined(BLACKMAGIC)
/* Don't bother if uart is disabled.
* This will be the case on mini while we're being debugged.
*/
if(!(RCC_APB2ENR & RCC_APB2ENR_USART1EN))
return;
+#endif
- gpio_set(LED_PORT, LED_UART);
+ gpio_set(LED_PORT_UART, LED_UART);
for(int i = 0; i < len; i++)
- usart_send_blocking(USART1, buf[i]);
- gpio_clear(LED_PORT, LED_UART);
+ usart_send_blocking(USBUSART, buf[i]);
+ gpio_clear(LED_PORT_UART, LED_UART);
}
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)
{
if (!uart_usb_buf_size) {
- gpio_clear(LED_PORT, LED_UART);
+ gpio_clear(LED_PORT_UART, LED_UART);
return;
}
@@ -120,11 +124,11 @@ void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep)
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 */
if (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, &c, 1) == 1)
diff --git a/src/platforms/native/usbuart.h b/src/platforms/stm32/usbuart.h
index 10cb60e..39f7dcd 100644
--- a/src/platforms/native/usbuart.h
+++ b/src/platforms/stm32/usbuart.h
@@ -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);
#endif
-