Detect hardware version. Disable UART on mini h/w under debug.

This commit is contained in:
Gareth McMullin 2012-05-23 20:25:45 +12:00
parent 700f9e6ad1
commit 40bb74cc81
2 changed files with 30 additions and 1 deletions

View File

@ -499,6 +499,13 @@ static void cdcacm_data_rx_cb(u8 ep)
char buf[CDCACM_PACKET_SIZE];
int len = usbd_ep_read_packet(0x03, buf, CDCACM_PACKET_SIZE);
/* 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;
for(int i = 0; i < len; i++)
usart_send_blocking(USART1, buf[i]);
}

View File

@ -28,6 +28,7 @@
#include <libopencm3/stm32/nvic.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/usb/usbd.h>
#include <libopencm3/cm3/scs.h>
#include "platform.h"
#include "jtag_scan.h"
@ -46,6 +47,23 @@ static void morse_update(void);
static void uart_init(void);
#endif
/* Pins PB[7:5] are used to detect hardware revision.
* 000 - Original production build.
* 001 - Mini production build.
*/
int platform_hwversion(void)
{
static int hwversion = -1;
if (hwversion == -1) {
gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_INPUT_PULL_UPDOWN,
GPIO7 | GPIO6 | GPIO5);
gpio_clear(GPIOB, GPIO7 | GPIO6 | GPIO5);
hwversion = gpio_get(GPIOB, GPIO7 | GPIO6 | GPIO5) >> 5;
}
return hwversion;
}
int platform_init(void)
{
rcc_clock_setup_in_hse_8mhz_out_72mhz();
@ -84,7 +102,11 @@ int platform_init(void)
systick_counter_enable();
#ifdef INCLUDE_UART_INTERFACE
uart_init();
/* On mini hardware, UART and SWD share connector pins.
* Don't enable UART if we're being debugged. */
if ((platform_hwversion() == 0) ||
!(SCS_DEMCR & SCS_DEMCR_TRCENA))
uart_init();
#endif
SCB_VTOR = 0x2000; // Relocate interrupt vector table here