samd voltage detection and line coding
This commit is contained in:
parent
bd71ca2a3c
commit
f828fc1ac1
@ -61,6 +61,9 @@ static bool cmd_traceswo(void);
|
|||||||
#ifdef PLATFORM_HAS_DEBUG
|
#ifdef PLATFORM_HAS_DEBUG
|
||||||
static bool cmd_debug_bmp(target *t, int argc, const char **argv);
|
static bool cmd_debug_bmp(target *t, int argc, const char **argv);
|
||||||
#endif
|
#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[] = {
|
const struct command_s cmd_list[] = {
|
||||||
{"version", (cmd_handler)cmd_version, "Display firmware version info"},
|
{"version", (cmd_handler)cmd_version, "Display firmware version info"},
|
||||||
@ -79,6 +82,9 @@ const struct command_s cmd_list[] = {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef PLATFORM_HAS_DEBUG
|
#ifdef PLATFORM_HAS_DEBUG
|
||||||
{"debug_bmp", (cmd_handler)cmd_debug_bmp, "Output BMP \"debug\" strings to the second vcom: (enable|disable)"},
|
{"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
|
#endif
|
||||||
{NULL, NULL, NULL}
|
{NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
@ -298,3 +304,15 @@ static bool cmd_debug_bmp(target *t, int argc, const char **argv)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
||||||
|
@ -27,13 +27,16 @@
|
|||||||
#include <libopencm3/sam/d/port.h>
|
#include <libopencm3/sam/d/port.h>
|
||||||
#include <libopencm3/sam/d/gclk.h>
|
#include <libopencm3/sam/d/gclk.h>
|
||||||
#include <libopencm3/sam/d/pm.h>
|
#include <libopencm3/sam/d/pm.h>
|
||||||
|
#include <libopencm3/sam/d/uart.h>
|
||||||
|
#include <libopencm3/sam/d/adc.h>
|
||||||
|
|
||||||
#include <libopencm3/cm3/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencm3/cm3/scb.h>
|
#include <libopencm3/cm3/scb.h>
|
||||||
|
|
||||||
static struct gclk_hw clock = {
|
static struct gclk_hw clock = {
|
||||||
.gclk0 = SRC_DFLL48M,
|
.gclk0 = SRC_DFLL48M,
|
||||||
.gclk1 = SRC_DFLL48M,
|
.gclk1 = SRC_OSC8M,
|
||||||
|
.gclk1_div = 30, /* divide clock for ADC */
|
||||||
.gclk2 = SRC_DFLL48M,
|
.gclk2 = SRC_DFLL48M,
|
||||||
.gclk3 = SRC_DFLL48M,
|
.gclk3 = SRC_DFLL48M,
|
||||||
.gclk4 = SRC_DFLL48M,
|
.gclk4 = SRC_DFLL48M,
|
||||||
@ -88,12 +91,28 @@ static uint32_t timing_init(void)
|
|||||||
return cal;
|
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)
|
void platform_init(void)
|
||||||
{
|
{
|
||||||
gclk_init(&clock);
|
gclk_init(&clock);
|
||||||
|
|
||||||
usb_setup();
|
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(LED_PORT, LED_IDLE_RUN, 0);
|
||||||
gpio_config_output(TMS_PORT, TMS_PIN, 0);
|
gpio_config_output(TMS_PORT, TMS_PIN, 0);
|
||||||
gpio_config_output(TCK_PORT, TCK_PIN, 0);
|
gpio_config_output(TCK_PORT, TCK_PIN, 0);
|
||||||
@ -119,6 +138,7 @@ void platform_init(void)
|
|||||||
timing_init();
|
timing_init();
|
||||||
usbuart_init();
|
usbuart_init();
|
||||||
cdcacm_init();
|
cdcacm_init();
|
||||||
|
adc_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void platform_srst_set_val(bool assert)
|
void platform_srst_set_val(bool assert)
|
||||||
@ -146,7 +166,19 @@ void platform_delay(uint32_t ms)
|
|||||||
|
|
||||||
const char *platform_target_voltage(void)
|
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)
|
char *serialno_read(char *s)
|
||||||
@ -173,3 +205,23 @@ char *serialno_read(char *s)
|
|||||||
void platform_request_boot(void)
|
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
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
//#define PLATFORM_HAS_DEBUG
|
//#define PLATFORM_HAS_DEBUG
|
||||||
//#define USBUART_DEBUG
|
//#define USBUART_DEBUG
|
||||||
|
#define PLATFORM_HAS_UART_WHEN_SWDP
|
||||||
|
|
||||||
#define BOARD_IDENT "Black Magic Probe (SAMD), (Firmware " FIRMWARE_VERSION ")"
|
#define BOARD_IDENT "Black Magic Probe (SAMD), (Firmware " FIRMWARE_VERSION ")"
|
||||||
#define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (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_RX_PIN GPIO5
|
||||||
#define UART_PERIPH SOC_GPIO_PERIPH_D
|
#define UART_PERIPH SOC_GPIO_PERIPH_D
|
||||||
|
|
||||||
|
#define ADC_PORT PORTA
|
||||||
|
#define ADC_REF_PIN GPIO3
|
||||||
|
#define ADC_POS_PIN GPIO8
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Hardware definitions... */
|
/* Hardware definitions... */
|
||||||
@ -85,8 +90,8 @@ extern uint8_t running_status;
|
|||||||
#define TCK_PORT JTAG_PORT
|
#define TCK_PORT JTAG_PORT
|
||||||
#define TDO_PORT JTAG_PORT
|
#define TDO_PORT JTAG_PORT
|
||||||
#define TMS_DIR_PIN GPIO15
|
#define TMS_DIR_PIN GPIO15
|
||||||
#define TMS_PIN GPIO31
|
#define TMS_PIN GPIO0
|
||||||
#define TCK_PIN GPIO30
|
#define TCK_PIN GPIO1
|
||||||
#define TDI_PIN GPIO5
|
#define TDI_PIN GPIO5
|
||||||
#define TDO_PIN GPIO4
|
#define TDO_PIN GPIO4
|
||||||
|
|
||||||
@ -95,7 +100,7 @@ extern uint8_t running_status;
|
|||||||
#define SWCLK_PORT JTAG_PORT
|
#define SWCLK_PORT JTAG_PORT
|
||||||
#define SWDIO_DIR_PIN TMS_DIR_PIN
|
#define SWDIO_DIR_PIN TMS_DIR_PIN
|
||||||
#define SWDIO_PIN TMS_PIN
|
#define SWDIO_PIN TMS_PIN
|
||||||
#define SWDIO_PIN_NUM 31
|
#define SWDIO_PIN_NUM 0
|
||||||
#define SWCLK_PIN TCK_PIN
|
#define SWCLK_PIN TCK_PIN
|
||||||
|
|
||||||
#define TRST_PORT PORTA
|
#define TRST_PORT PORTA
|
||||||
@ -113,6 +118,7 @@ extern uint8_t running_status;
|
|||||||
#define LED_0 GPIO10
|
#define LED_0 GPIO10
|
||||||
#define LED_1 GPIO11
|
#define LED_1 GPIO11
|
||||||
#define LED_2 GPIO14
|
#define LED_2 GPIO14
|
||||||
|
//#define LED_2 GPIO13
|
||||||
#define LED_UART LED_1 /* Orange */
|
#define LED_UART LED_1 /* Orange */
|
||||||
#define LED_IDLE_RUN LED_0 /* Yellow */
|
#define LED_IDLE_RUN LED_0 /* Yellow */
|
||||||
#define LED_ERROR LED_2 /* Red */
|
#define LED_ERROR LED_2 /* Red */
|
||||||
@ -124,6 +130,10 @@ extern uint8_t running_status;
|
|||||||
#define SWO_PORT JTAG_PORT
|
#define SWO_PORT JTAG_PORT
|
||||||
#define SWO_PIN SWD_PIN
|
#define SWO_PIN SWD_PIN
|
||||||
|
|
||||||
|
#define ADC_PORT PORTA
|
||||||
|
#define ADC_REF_PIN GPIO3
|
||||||
|
#define ADC_POS_PIN TRGT_SENSE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TMS_SET_MODE() { \
|
#define TMS_SET_MODE() { \
|
||||||
@ -186,4 +196,5 @@ static inline int platform_hwversion(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void uart_pop(void);
|
void uart_pop(void);
|
||||||
|
void platform_convert_tdio(void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
/* Define memory regions. */
|
/* Define memory regions. */
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K
|
/* rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K */
|
||||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
/* 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. */
|
/* Include the common ld script from libopenstm32. */
|
||||||
|
@ -87,8 +87,18 @@ void usbuart_init(void)
|
|||||||
|
|
||||||
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
|
void usbuart_set_line_coding(struct usb_cdc_line_coding *coding)
|
||||||
{
|
{
|
||||||
/* Not supported yet, only 115200 8bits/etc */
|
uint8_t sbmode = (coding->bCharFormat == 2) ? 1 : 0;
|
||||||
(void) coding;
|
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)
|
void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user