diff --git a/src/command.c b/src/command.c index 9594c3a5..df88ee53 100644 --- a/src/command.c +++ b/src/command.c @@ -61,6 +61,9 @@ static bool cmd_traceswo(void); #ifdef PLATFORM_HAS_DEBUG static bool cmd_debug_bmp(target *t, int argc, const char **argv); #endif +#ifdef PLATFORM_HAS_UART_WHEN_SWDP +static bool cmd_convert_tdio(target *t, int argc, const char **argv); +#endif const struct command_s cmd_list[] = { {"version", (cmd_handler)cmd_version, "Display firmware version info"}, @@ -79,6 +82,9 @@ const struct command_s cmd_list[] = { #endif #ifdef PLATFORM_HAS_DEBUG {"debug_bmp", (cmd_handler)cmd_debug_bmp, "Output BMP \"debug\" strings to the second vcom: (enable|disable)"}, +#endif +#ifdef PLATFORM_HAS_UART_WHEN_SWDP + {"convert_tdio", (cmd_handler)cmd_convert_tdio,"Switch TDI/O pins to UART TX/RX functions"}, #endif {NULL, NULL, NULL} }; @@ -298,3 +304,15 @@ static bool cmd_debug_bmp(target *t, int argc, const char **argv) return true; } #endif + +#ifdef PLATFORM_HAS_UART_WHEN_SWDP +static bool cmd_convert_tdio(target *t, int argc, const char **argv) +{ + (void)t; + (void) argv; + (void) argc; + platform_convert_tdio(); + + return true; +} +#endif diff --git a/src/platforms/jeff/platform.c b/src/platforms/jeff/platform.c index 2171e2f6..cd1bdc96 100644 --- a/src/platforms/jeff/platform.c +++ b/src/platforms/jeff/platform.c @@ -27,13 +27,16 @@ #include #include #include +#include +#include #include #include static struct gclk_hw clock = { .gclk0 = SRC_DFLL48M, - .gclk1 = SRC_DFLL48M, + .gclk1 = SRC_OSC8M, + .gclk1_div = 30, /* divide clock for ADC */ .gclk2 = SRC_DFLL48M, .gclk3 = SRC_DFLL48M, .gclk4 = SRC_DFLL48M, @@ -88,12 +91,28 @@ static uint32_t timing_init(void) return cal; } +static void adc_init(void) +{ + gpio_config_special(ADC_PORT, ADC_POS_PIN, SOC_GPIO_PERIPH_B); /* +input */ + gpio_config_special(ADC_PORT, ADC_REF_PIN, SOC_GPIO_PERIPH_B); /* reference */ + //gpio_config_special(PORTA, GPIO6, SOC_GPIO_PERIPH_B); /* ground (-input) */ + + set_periph_clk(GCLK1, GCLK_ID_ADC); + periph_clk_en(GCLK_ID_ADC, 1); + + //adc_enable(ADC_REFCTRL_VREFA,0,ADC_INPUTCTRL_PIN6,ADC_INPUTCTRL_PIN16); + adc_enable(ADC_REFCTRL_VREFA,0,ADC_INPUTCTRL_GND,ADC_INPUTCTRL_PIN16); +} + void platform_init(void) { gclk_init(&clock); usb_setup(); + gpio_config_special(TCK_PORT, TCK_PIN, SOC_GPIO_NONE); + //gpio_config_special(TMS_PORT, TMS_PIN, SOC_GPIO_NONE); + gpio_config_output(LED_PORT, LED_IDLE_RUN, 0); gpio_config_output(TMS_PORT, TMS_PIN, 0); gpio_config_output(TCK_PORT, TCK_PIN, 0); @@ -119,6 +138,7 @@ void platform_init(void) timing_init(); usbuart_init(); cdcacm_init(); + adc_init(); } void platform_srst_set_val(bool assert) @@ -146,7 +166,19 @@ void platform_delay(uint32_t ms) const char *platform_target_voltage(void) { - return "not supported"; + uint32_t voltage; + static char out[] = "0.0V"; + + adc_start(); + + while (!(1&(ADC->intflag))); + voltage = ((330*adc_result())>>12); + + out[0] = '0' + (char)(voltage/100); + out[2] = '0' + (char)((voltage/10) % 10); + + return out; + //return "not supported"; } char *serialno_read(char *s) @@ -173,3 +205,23 @@ char *serialno_read(char *s) void platform_request_boot(void) { } + +void platform_convert_tdio(void) +{ +#if 0 + gpio_config_special(PORTA, GPIO16, SOC_GPIO_PERIPH_C); /* TX */ + gpio_config_special(PORTA, GPIO19, SOC_GPIO_PERIPH_C); /* RX */ + + /* Select and Enable system clock */ + set_periph_clk(GCLK0, GCLK_ID_SERCOM1_CORE); // TODO which GCLK#? + periph_clk_en(GCLK_ID_SERCOM1_CORE, 1); + + usart_enable(1, 115200); + + usart_enable_rx_interrupt(1); + usart_enable_tx_interrupt(1); +#else + //gpio_config_special(TMS_PORT, TMS_PIN, SOC_GPIO_PERIPH_G); + gpio_config_special(TCK_PORT, TCK_PIN, SOC_GPIO_PERIPH_G); +#endif +} diff --git a/src/platforms/jeff/platform.h b/src/platforms/jeff/platform.h index 114dacde..74066c58 100644 --- a/src/platforms/jeff/platform.h +++ b/src/platforms/jeff/platform.h @@ -29,6 +29,7 @@ //#define PLATFORM_HAS_DEBUG //#define USBUART_DEBUG +#define PLATFORM_HAS_UART_WHEN_SWDP #define BOARD_IDENT "Black Magic Probe (SAMD), (Firmware " FIRMWARE_VERSION ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (Firmware " FIRMWARE_VERSION ")" @@ -75,6 +76,10 @@ extern uint8_t running_status; #define UART_RX_PIN GPIO5 #define UART_PERIPH SOC_GPIO_PERIPH_D +#define ADC_PORT PORTA +#define ADC_REF_PIN GPIO3 +#define ADC_POS_PIN GPIO8 + #else /* Hardware definitions... */ @@ -85,8 +90,8 @@ extern uint8_t running_status; #define TCK_PORT JTAG_PORT #define TDO_PORT JTAG_PORT #define TMS_DIR_PIN GPIO15 -#define TMS_PIN GPIO31 -#define TCK_PIN GPIO30 +#define TMS_PIN GPIO0 +#define TCK_PIN GPIO1 #define TDI_PIN GPIO5 #define TDO_PIN GPIO4 @@ -95,7 +100,7 @@ extern uint8_t running_status; #define SWCLK_PORT JTAG_PORT #define SWDIO_DIR_PIN TMS_DIR_PIN #define SWDIO_PIN TMS_PIN -#define SWDIO_PIN_NUM 31 +#define SWDIO_PIN_NUM 0 #define SWCLK_PIN TCK_PIN #define TRST_PORT PORTA @@ -113,6 +118,7 @@ extern uint8_t running_status; #define LED_0 GPIO10 #define LED_1 GPIO11 #define LED_2 GPIO14 +//#define LED_2 GPIO13 #define LED_UART LED_1 /* Orange */ #define LED_IDLE_RUN LED_0 /* Yellow */ #define LED_ERROR LED_2 /* Red */ @@ -124,6 +130,10 @@ extern uint8_t running_status; #define SWO_PORT JTAG_PORT #define SWO_PIN SWD_PIN +#define ADC_PORT PORTA +#define ADC_REF_PIN GPIO3 +#define ADC_POS_PIN TRGT_SENSE + #endif #define TMS_SET_MODE() { \ @@ -186,4 +196,5 @@ static inline int platform_hwversion(void) } void uart_pop(void); +void platform_convert_tdio(void); #endif diff --git a/src/platforms/samd/samd.ld b/src/platforms/samd/samd.ld index 7d707b8f..ca6071a5 100644 --- a/src/platforms/samd/samd.ld +++ b/src/platforms/samd/samd.ld @@ -20,8 +20,10 @@ /* Define memory regions. */ MEMORY { - rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K + /* rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K */ + /* ram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K */ + rom (rx) : ORIGIN = 0x00000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K } /* Include the common ld script from libopenstm32. */ diff --git a/src/platforms/samd/usbuart.c b/src/platforms/samd/usbuart.c index 55bf5ca3..624f65c1 100644 --- a/src/platforms/samd/usbuart.c +++ b/src/platforms/samd/usbuart.c @@ -87,8 +87,18 @@ void usbuart_init(void) void usbuart_set_line_coding(struct usb_cdc_line_coding *coding) { - /* Not supported yet, only 115200 8bits/etc */ - (void) coding; + uint8_t sbmode = (coding->bCharFormat == 2) ? 1 : 0; + uint8_t parity = (coding->bParityType == 1) ? 0 : 1; + uint8_t form = (coding->bParityType) ? 1 : 0; + uint8_t chsize = (form) ? coding->bDataBits + 1 : coding->bDataBits; + + /* set baud rate */ + usart_set_baudrate(USART_NUM, coding->dwDTERate); + + /* set data size, stop mode, and parity */ + usart_set_chsize(USART_NUM, chsize); + usart_set_sbmode(USART_NUM, sbmode); + usart_set_parity(USART_NUM, parity, form); } void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)