diff options
| author | James McKenzie <git@madingley.org> | 2014-11-16 11:12:25 +0000 | 
|---|---|---|
| committer | James McKenzie <git@madingley.org> | 2014-11-16 11:12:25 +0000 | 
| commit | 500561f54adabc9aaf5b3548744b5bc8b4381c89 (patch) | |
| tree | 89d1157b5b2260bc91a59a8ff00f5036edbccea4 | |
| parent | 5950acfb05fb3e172fa5710f1cda6ab347f51f2f (diff) | |
| download | stm32_usb_kvm-500561f54adabc9aaf5b3548744b5bc8b4381c89.tar.gz stm32_usb_kvm-500561f54adabc9aaf5b3548744b5bc8b4381c89.tar.bz2 stm32_usb_kvm-500561f54adabc9aaf5b3548744b5bc8b4381c89.zip | |
tidy up
| -rw-r--r-- | app/kvm.c | 6 | ||||
| -rw-r--r-- | app/led.c | 9 | ||||
| -rw-r--r-- | app/main.c | 43 | ||||
| -rw-r--r-- | app/project.h | 1 | ||||
| -rw-r--r-- | app/prototypes.h | 13 | ||||
| -rw-r--r-- | app/usart.c | 156 | ||||
| -rw-r--r-- | docs/rm0008.pdf | bin | 0 -> 13016697 bytes | |||
| -rw-r--r-- | id.h | 7 | 
8 files changed, 180 insertions, 55 deletions
| @@ -43,13 +43,15 @@ kvm_recv (uint8_t d)    if (state == STATE_ADDR)      {        addr = d; -      usart_queue (d - 1); +      usart2_queue (d - 1); +      usart3_queue (d - 3);        state = STATE_ENDPOINT;        return;      }    else      { -      usart_queue (d); +      usart2_queue (d); +      usart3_queue (d);      } @@ -3,6 +3,15 @@  static int led=0; +void led_init(void ) +{ +gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, +                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); +  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, +                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO9); +} + +  void led_clear(void)  {        gpio_set(GPIOB,GPIO8); @@ -6,7 +6,10 @@ sys_tick_handler (void)  {  uint8_t d; -while (!ring_read_byte(&rx_ring,&d)) +while (!ring_read_byte(&rx1_ring,&d))  +	kvm_recv(d); + +while (!ring_read_byte(&rx2_ring,&d))  	kvm_recv(d);  led_tick(); @@ -15,58 +18,62 @@ led_tick();  int  main (void)  { -  int i;  //  rcc_clock_setup_in_hsi_out_48mhz ();    //nvic_set_priority_grouping(NVIC_PriorityGroup_4); +  /*set up pll*/    rcc_clock_setup_in_hse_8mhz_out_72mhz(); +  /*turn on clocks to periferals*/    rcc_periph_clock_enable (RCC_GPIOA);    rcc_periph_clock_enable (RCC_GPIOB);    rcc_periph_clock_enable (RCC_GPIOC); -  rcc_periph_clock_enable (RCC_AFIO);    rcc_periph_clock_enable (RCC_USART1); +  rcc_periph_clock_enable (RCC_USART2); +  rcc_periph_clock_enable (RCC_USART3); +  rcc_periph_clock_enable (RCC_AFIO); - +  led_init();    usart_init (); -    usb_init (); +  /*Start periodic timer*/ +    systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8);    /* 48MHz / 8 = > 6Mhz */    systick_set_reload (6000);    /* 6MHz / 6000 => 1kHz */ -    systick_interrupt_enable ();    systick_counter_enable (); +  /*Adjust interrupt priorities so that uarts trump timer*/    nvic_set_priority(NVIC_USART1_IRQ, 0x40); +  nvic_set_priority(NVIC_USART2_IRQ, 0x40); +  nvic_set_priority(NVIC_USART3_IRQ, 0x40);    nvic_set_priority(NVIC_SYSTICK_IRQ, 0xff); -  //nvic_set_priority(SysTick_IRQn, NVIC_EncodePriority(4,0,0)); -  //nvic_set_priority(USART1_IRQn, NVIC_EncodePriority(4,1,0)); - +  led_clear(); +#if 0 +  /*GPIO C11 was used to determine if we should enter dfu */ +  /*now we use a ramdom address in ram*/    gpio_set (GPIOC, GPIO11);    gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ,                   GPIO_CNF_OUTPUT_PUSHPULL, GPIO11); +  -  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, -                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); -  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ, -                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO9); - -  led_clear(); - - +  { +  int i;    for (i = 0; i < 0x80000; i++)      __asm__ ("nop"); +  }    gpio_clear (GPIOC, GPIO11); +#endif -  printf ("Hello world main=%p\r\n", main); +  printf ("stm32_usb_kvm:\r\n");    printf ("dfu_flag=%08lx\r\n", dfu_flag);    usb_run (); diff --git a/app/project.h b/app/project.h index 27b793f..a1849df 100644 --- a/app/project.h +++ b/app/project.h @@ -6,6 +6,7 @@  #include <libopencm3/cm3/nvic.h>  #include <libopencm3/usb/usbd.h>  #include <libopencm3/usb/hid.h> +#include <libopencm3/cm3/cortex.h>  #define INCLUDE_DFU_INTERFACE diff --git a/app/prototypes.h b/app/prototypes.h index cbfcf78..f110e64 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -29,11 +29,17 @@ extern const struct usb_interface_descriptor tablet_iface;  extern void tablet_get_descriptor(uint8_t **buf, uint16_t *len);  extern void tablet_test(void);  /* usart.c */ -extern ring_t rx_ring; -extern ring_t tx_ring; +extern ring_t rx1_ring; +extern ring_t tx1_ring; +extern ring_t rx2_ring; +extern ring_t tx2_ring; +extern ring_t tx3_ring;  extern void usart1_isr(void); +extern void usart2_isr(void); +extern void usart3_isr(void);  extern int _write(int file, char *ptr, int len); -extern void usart_queue(uint8_t d); +extern void usart2_queue(uint8_t d); +extern void usart3_queue(uint8_t d);  extern void usart_init(void);  /* kvm.c */  extern void kvm_dispatch(void); @@ -44,6 +50,7 @@ extern int ring_write_byte(ring_t *r, uint8_t c);  extern int ring_read_byte(ring_t *r, uint8_t *c);  extern int ring_write(ring_t *r, uint8_t *buf, size_t len);  /* led.c */ +extern void led_init(void);  extern void led_clear(void);  extern void led_set(uint32_t v);  extern void led_tick(void); diff --git a/app/usart.c b/app/usart.c index 273c3bc..4061076 100644 --- a/app/usart.c +++ b/app/usart.c @@ -2,11 +2,20 @@  #define BUFFER_SIZE 256 -ring_t rx_ring; -static uint8_t rx_ring_buf[BUFFER_SIZE]; +ring_t rx1_ring; +static uint8_t rx1_ring_buf[BUFFER_SIZE]; -ring_t tx_ring; -static uint8_t tx_ring_buf[BUFFER_SIZE]; +ring_t tx1_ring; +static uint8_t tx1_ring_buf[BUFFER_SIZE]; + +ring_t rx2_ring; +static uint8_t rx2_ring_buf[BUFFER_SIZE]; + +ring_t tx2_ring; +static uint8_t tx2_ring_buf[BUFFER_SIZE]; + +ring_t tx3_ring; +static uint8_t tx3_ring_buf[BUFFER_SIZE];  void  usart1_isr (void) @@ -21,7 +30,8 @@ usart1_isr (void)        /* Retrieve the data from the peripheral. */        data = usart_recv (USART1); -      ring_write_byte(&rx_ring,data); + +      ring_write_byte(&rx1_ring,data);      }    /* Check if we were called because of TXE. */ @@ -29,7 +39,7 @@ usart1_isr (void)        ((USART_SR (USART1) & USART_SR_TXE) != 0))      { -      if (ring_read_byte (&tx_ring, &data)) +      if (ring_read_byte (&tx1_ring, &data))          {            /*No more data, Disable the TXE interrupt, it's no longer needed. */            USART_CR1 (USART1) &= ~USART_CR1_TXEIE; @@ -42,6 +52,64 @@ usart1_isr (void)  } +void +usart2_isr (void) +{ +  uint8_t data; + +  /* Check if we were called because of RXNE. */ +  if (((USART_CR1 (USART2) & USART_CR1_RXNEIE) != 0) && +      ((USART_SR (USART2) & USART_SR_RXNE) != 0)) +    { + +      /* Retrieve the data from the peripheral. */ +      data = usart_recv (USART2); + +      ring_write_byte(&rx2_ring,data); +    } + +  /* Check if we were called because of TXE. */ +  if (((USART_CR1 (USART2) & USART_CR1_TXEIE) != 0) && +      ((USART_SR (USART2) & USART_SR_TXE) != 0)) +    { + +      if (ring_read_byte (&tx2_ring, &data)) +        { +          /*No more data, Disable the TXE interrupt, it's no longer needed. */ +          USART_CR1 (USART2) &= ~USART_CR1_TXEIE; +        } +      else +        { +          usart_send_blocking (USART2, data); +        } +    } + +} + +void +usart3_isr (void) +{ +  uint8_t data; + +  /* Check if we were called because of TXE. */ +  if (((USART_CR1 (USART3) & USART_CR1_TXEIE) != 0) && +      ((USART_SR (USART3) & USART_SR_TXE) != 0)) +    { + +      if (ring_read_byte (&tx3_ring, &data)) +        { +          /*No more data, Disable the TXE interrupt, it's no longer needed. */ +          USART_CR1 (USART3) &= ~USART_CR1_TXEIE; +        } +      else +        { +          usart_send (USART3, data); +        } +    } + +} + +  int  _write (int file, char *ptr, int len)  { @@ -49,7 +117,7 @@ _write (int file, char *ptr, int len)    if (file == 1)      { -      ret = ring_write (&tx_ring, (uint8_t *) ptr, len); +      ret = ring_write (&tx1_ring, (uint8_t *) ptr, len);        if (ret < 0)          ret = -ret; @@ -63,37 +131,53 @@ _write (int file, char *ptr, int len)  }  void -usart_queue (uint8_t d) +usart2_queue (uint8_t d)  { +  ring_write_byte (&tx2_ring, d); +  USART_CR1 (USART2) |= USART_CR1_TXEIE; +} -  ring_write_byte (&tx_ring, d); -  USART_CR1 (USART1) |= USART_CR1_TXEIE; -#if 0 -  printf ("0x%02x ", d); -  fflush (stdout); -#endif +void +usart3_queue (uint8_t d) +{ +  ring_write_byte (&tx3_ring, d); +  USART_CR1 (USART3) |= USART_CR1_TXEIE;  }  void  usart_init (void)  { -  ring_init (&tx_ring, tx_ring_buf, sizeof (tx_ring_buf)); -  ring_init (&rx_ring, rx_ring_buf, sizeof (rx_ring_buf)); +  ring_init (&rx1_ring, rx1_ring_buf, sizeof (rx1_ring_buf)); +  ring_init (&tx1_ring, tx1_ring_buf, sizeof (tx1_ring_buf)); + +  ring_init (&rx2_ring, rx2_ring_buf, sizeof (rx2_ring_buf)); +  ring_init (&tx2_ring, tx2_ring_buf, sizeof (tx2_ring_buf)); + +  ring_init (&tx3_ring, tx3_ring_buf, sizeof (tx3_ring_buf)); -  /* Enable the USART1 interrupt. */ + +  /* Enable the USART1,2,3 interrupt. */    nvic_enable_irq (NVIC_USART1_IRQ); +  nvic_enable_irq (NVIC_USART2_IRQ); +  nvic_enable_irq (NVIC_USART3_IRQ); + +  /* Map pins, and set usarts2 and 3 to have pull ups*/ +  gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); +  gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); + +  gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART2_TX); +  gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_USART2_RX); +  gpio_set(GPIOA, GPIO_USART2_RX); + +  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART3_TX); +  gpio_set_mode (GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_USART3_RX); +  gpio_set(GPIOB, GPIO_USART3_RX); -  /* Setup GPIO pin GPIO_USART1_RE_TX on GPIO port B for transmit. */ -  gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_50_MHZ, -                 GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); -  /* Setup GPIO pin GPIO_USART1_RE_RX on GPIO port B for receive. */ -  gpio_set_mode (GPIOA, GPIO_MODE_INPUT, -                 GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); -  /* Setup UART parameters. */ +  /* Setup UART1 parameters. */    usart_set_baudrate (USART1, 38400);    usart_set_databits (USART1, 8);    usart_set_stopbits (USART1, USART_STOPBITS_1); @@ -101,9 +185,29 @@ usart_init (void)    usart_set_flow_control (USART1, USART_FLOWCONTROL_NONE);    usart_set_mode (USART1, USART_MODE_TX_RX); -  /* Enable USART1 Receive interrupt. */ +  /* Setup UART2 parameters. */ +  usart_set_baudrate (USART2, 38400); +  usart_set_databits (USART2, 8); +  usart_set_stopbits (USART2, USART_STOPBITS_1); +  usart_set_parity (USART2, USART_PARITY_NONE); +  usart_set_flow_control (USART2, USART_FLOWCONTROL_NONE); +  usart_set_mode (USART2, USART_MODE_TX_RX); + + +  /* Setup UART3 parameters. */ +  usart_set_baudrate (USART3, 38400); +  usart_set_databits (USART3, 8); +  usart_set_stopbits (USART3, USART_STOPBITS_1); +  usart_set_parity (USART3, USART_PARITY_NONE); +  usart_set_flow_control (USART3, USART_FLOWCONTROL_NONE); +  usart_set_mode (USART3, USART_MODE_TX_RX); + +  /* Enable USART1,2 Receive interrupt. */    USART_CR1 (USART1) |= USART_CR1_RXNEIE; +  USART_CR1 (USART2) |= USART_CR1_RXNEIE; -  /* Finally enable the USART. */ +  /* Finally enable the USARTs. */    usart_enable (USART1); +  usart_enable (USART2); +  usart_enable (USART3);  } diff --git a/docs/rm0008.pdf b/docs/rm0008.pdfBinary files differ new file mode 100644 index 0000000..8f3d0e1 --- /dev/null +++ b/docs/rm0008.pdf @@ -1,10 +1,5 @@ -#if 0 -#define ID_PRODUCT 0xee3 +#define ID_PRODUCT 0xee5  #define BUS_ID	   0x0 -#else -#define ID_PRODUCT 0xee4 -#define BUS_ID	   0x1 -#endif | 
