Merge pull request #115 from esden/bmpm2

[native] Check for hardware version by pull-up and -down. Print HW Ve…
This commit is contained in:
Gareth McMullin 2016-03-09 10:26:43 +13:00
commit 4e23c95c53
5 changed files with 43 additions and 4 deletions

View File

@ -108,7 +108,7 @@ int command_process(target *t, char *cmd)
bool cmd_version(void)
{
gdb_out("Black Magic Probe (Firmware " FIRMWARE_VERSION ")\n");
gdb_outf("Black Magic Probe (Firmware " FIRMWARE_VERSION ") (Hardware Version %d)\n", platform_hwversion());
gdb_out("Copyright (C) 2015 Black Sphere Technologies Ltd.\n");
gdb_out("License GPLv3+: GNU GPL version 3 or later "
"<http://gnu.org/licenses/gpl.html>\n\n");

View File

@ -116,4 +116,9 @@ inline static uint8_t gpio_get(uint32_t port, uint8_t pin) {
#define disconnect_usb() do { usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0)
static inline int platform_hwversion(void)
{
return 0;
}
#endif

View File

@ -42,5 +42,10 @@ void platform_buffer_flush(void);
int platform_buffer_write(const uint8_t *data, int size);
int platform_buffer_read(uint8_t *data, int size);
static inline int platform_hwversion(void)
{
return 0;
}
#endif

View File

@ -45,13 +45,37 @@ static void setup_vbus_irq(void);
int platform_hwversion(void)
{
static int hwversion = -1;
uint16_t hwversion_pins = GPIO7 | GPIO6 | GPIO5;
uint16_t unused_pins = hwversion_pins ^ 0xFFFF;
/* Only check for version if this is the first time. */
if (hwversion == -1) {
/* Configure the hardware version pins as input pull-up/down */
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
GPIO_CNF_INPUT_PULL_UPDOWN,
GPIO7 | GPIO6 | GPIO5);
gpio_clear(GPIOB, GPIO7 | GPIO6 | GPIO5);
hwversion = gpio_get(GPIOB, GPIO7 | GPIO6 | GPIO5) >> 5;
hwversion_pins);
/* Enable the weak pull up. */
gpio_set(GPIOB, hwversion_pins);
/* Get all pins that are pulled low in hardware.
* This also sets all the "unused" pins to 1.
*/
uint16_t pins_negative = gpio_get(GPIOB, hwversion_pins) | unused_pins;
/* Enable the weak pull down. */
gpio_clear(GPIOB, hwversion_pins);
/* Get all the pins that are pulled high in hardware. */
uint16_t pins_positive = gpio_get(GPIOB, hwversion_pins);
/* Hardware version is the id defined by the pins that are
* asserted low or high by the hardware. This means that pins
* that are left floating are 0 and those that are either
* pulled high or low are 1.
*/
hwversion = (((pins_positive ^ pins_negative) ^ 0xFFFF) & hwversion_pins) >> 5;
}
return hwversion;
}

View File

@ -127,6 +127,11 @@
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);}
#define SET_ERROR_STATE(x)
static inline int platform_hwversion(void)
{
return 0;
}
/* Use newlib provided integer only stdio functions */
#define sscanf siscanf
#define sprintf siprintf