Fixed a hardware version detection glitch.

If you try to read out the GPIO immediately after setting the weak pull
on the pin it is possible that you will not read the correct value on a
floating pin. We need to use a busy wait loop instead of the
platform_delay because the platform timing is not initialized yet. We
also can not initialize the platform_delay code yet because it requires
LED gpio to be configured. A busy wait seems to do the job and is easier
than refactoring the codebase to use the platform_delay function.
This commit is contained in:
Piotr Esden-Tempski 2016-04-06 19:20:43 -07:00
parent 4d6f691f48
commit f2650df731
1 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,7 @@ static void setup_vbus_irq(void);
/* Pins PB[7:5] are used to detect hardware revision. /* Pins PB[7:5] are used to detect hardware revision.
* 000 - Original production build. * 000 - Original production build.
* 001 - Mini production build. * 001 - Mini production build.
* 010 - Mini V2.0e and later.
*/ */
int platform_hwversion(void) int platform_hwversion(void)
{ {
@ -57,6 +58,10 @@ int platform_hwversion(void)
/* Enable the weak pull up. */ /* Enable the weak pull up. */
gpio_set(GPIOB, hwversion_pins); gpio_set(GPIOB, hwversion_pins);
/* Wait a little to make sure the pull up is in effect... */
for(int i = 0; i < 100; i++) asm("nop");
/* Get all pins that are pulled low in hardware. /* Get all pins that are pulled low in hardware.
* This also sets all the "unused" pins to 1. * This also sets all the "unused" pins to 1.
*/ */
@ -64,10 +69,13 @@ int platform_hwversion(void)
/* Enable the weak pull down. */ /* Enable the weak pull down. */
gpio_clear(GPIOB, hwversion_pins); gpio_clear(GPIOB, hwversion_pins);
/* Wait a little to make sure the pull down is in effect... */
for(int i = 0; i < 100; i++) asm("nop");
/* Get all the pins that are pulled high in hardware. */ /* Get all the pins that are pulled high in hardware. */
uint16_t pins_positive = gpio_get(GPIOB, hwversion_pins); uint16_t pins_positive = gpio_get(GPIOB, hwversion_pins);
/* Hardware version is the id defined by the pins that are /* Hardware version is the id defined by the pins that are
* asserted low or high by the hardware. This means that pins * asserted low or high by the hardware. This means that pins
* that are left floating are 0 and those that are either * that are left floating are 0 and those that are either