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:
commit
4e23c95c53
|
@ -108,7 +108,7 @@ int command_process(target *t, char *cmd)
|
||||||
|
|
||||||
bool cmd_version(void)
|
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("Copyright (C) 2015 Black Sphere Technologies Ltd.\n");
|
||||||
gdb_out("License GPLv3+: GNU GPL version 3 or later "
|
gdb_out("License GPLv3+: GNU GPL version 3 or later "
|
||||||
"<http://gnu.org/licenses/gpl.html>\n\n");
|
"<http://gnu.org/licenses/gpl.html>\n\n");
|
||||||
|
|
|
@ -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)
|
#define disconnect_usb() do { usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0)
|
||||||
|
|
||||||
|
static inline int platform_hwversion(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,5 +42,10 @@ void platform_buffer_flush(void);
|
||||||
int platform_buffer_write(const uint8_t *data, int size);
|
int platform_buffer_write(const uint8_t *data, int size);
|
||||||
int platform_buffer_read(uint8_t *data, int size);
|
int platform_buffer_read(uint8_t *data, int size);
|
||||||
|
|
||||||
|
static inline int platform_hwversion(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,37 @@ static void setup_vbus_irq(void);
|
||||||
int platform_hwversion(void)
|
int platform_hwversion(void)
|
||||||
{
|
{
|
||||||
static int hwversion = -1;
|
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) {
|
if (hwversion == -1) {
|
||||||
|
/* Configure the hardware version pins as input pull-up/down */
|
||||||
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
|
||||||
GPIO_CNF_INPUT_PULL_UPDOWN,
|
GPIO_CNF_INPUT_PULL_UPDOWN,
|
||||||
GPIO7 | GPIO6 | GPIO5);
|
hwversion_pins);
|
||||||
gpio_clear(GPIOB, GPIO7 | GPIO6 | GPIO5);
|
|
||||||
hwversion = gpio_get(GPIOB, GPIO7 | GPIO6 | GPIO5) >> 5;
|
/* 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;
|
return hwversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,11 @@
|
||||||
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);}
|
#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);}
|
||||||
#define SET_ERROR_STATE(x)
|
#define SET_ERROR_STATE(x)
|
||||||
|
|
||||||
|
static inline int platform_hwversion(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Use newlib provided integer only stdio functions */
|
/* Use newlib provided integer only stdio functions */
|
||||||
#define sscanf siscanf
|
#define sscanf siscanf
|
||||||
#define sprintf siprintf
|
#define sprintf siprintf
|
||||||
|
|
Loading…
Reference in New Issue