[native] Check for hardware version by pull-up and -down. Print HW Version in mon command.
Until now the native hardware was pulling PB5-7 down and checking if they were asserted high. BMPMV2b is pulling the pins down instead of high. The hardware version routine now determines the hardware version based on the fact if a pin is asserted at all. This means that if a pin is left floating, the version number bit will be 0, and if the pin is asserted either high or low the bit will be set to 1. While we were already at it the "monitor version" command in GDB will now also print the hardware version number.
This commit is contained in:
parent
ac9d87635c
commit
b7e5005679
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue