boards/px4/fmu-v3/src/init.c
static int determin_hw_version(int *version, int *revision)
{
	*revision = 0; /* default revision */
	int rv = 0;
	int pos = 0;
	stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB4 & ~GPIO_PUPD_MASK));
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;
	stm32_configgpio(HW_VER_PB4);
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;

	int votes = 16;
	int ones[2] = {0, 0};
	int zeros[2] = {0, 0};

	while (votes--) {
		stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB12 & ~GPIO_PUPD_MASK));
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[0]++ : zeros[0]++;
		stm32_configgpio(HW_VER_PB12);
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[1]++ : zeros[1]++;
	}

	if (ones[0] > zeros[0]) {
		rv |= 1 << pos;
	}

	pos++;

	if (ones[1] > zeros[1]) {
		rv |= 1 << pos;
	}

	stm32_configgpio(HW_VER_PB4_INIT);
	stm32_configgpio(HW_VER_PB12_INIT);
	*version = rv;
	return OK;
}
/************************************************************************************
  * Name: determin_hw_version
 *
 * Description:
 *
 * This function looks at HW deltas to determine what the
 * build is running on using the following criteria:
 *
 * MSN  PB12   FMUv2                Cube             MINI
 * CAN2_RX       CONECTOR             MX30521          NC
 * PU.PD         1,0                   1,1             1,0
 *
 * LSN  PB4    FMUv2                Cube             MINI
 *               ACCEL_DRDY LSM303D    NC              NC
 * PU.PD         0,0                   1,0             1,0

 *  PB12:PB4
 *  ud   ud
 *  10   00 - 0x8 FMUv2
 *  11   10 - 0xE Cube AKA V2.0
 *  10   10 - 0xA PixhawkMini
 *  10   11 - 0xB FMUv2 questionable hardware (should be treated like regular FMUv2)
 *
 *  This will return OK on success and -1 on not supported
 *
 *  hw_type Initial state is {'V','2',0, 0}
 *   V 2    - FMUv2
 *   V 3 0  - FMUv3 2.0
 *   V 3 1  - FMUv3 2.1 - not differentiateable,
 *   V 2 M  - FMUv2 Mini
 *
 ************************************************************************************/


This function looks at HW deltas to determine what the
build is running on using the following criteria.





PB4
ud   ud
10   00 - 0x8 FMUv2
11   10 - 0xE Cube AKA V2.0
10   10 - 0xA PixhawkMini
10   11 - 0xB FMUv2 questionable hardware (should be treated like regular FMUv2)

This will return OK on success and -1 on not supported


This function looks at HW deltas to determine what the build is running on using the following criteria . PB4 ud ud 10 00 - 0x8 FMUv2 11 10 - 0xE Cube AKA V2 . 0 10 10 - 0xA PixhawkMini 10 11 - 0xB FMUv2 questionable hardware ( should be treated like regular FMUv2 ) This will return OK on success and - 1 on not supported
static int determin_hw_version(int *version, int *revision)
{
	*revision = 0; 
	int rv = 0;
	int pos = 0;
	stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB4 & ~GPIO_PUPD_MASK));
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;
	stm32_configgpio(HW_VER_PB4);
	up_udelay(10);
	rv |= stm32_gpioread(HW_VER_PB4) << pos++;
	int votes = 16;
	int ones[2] = {0, 0};
	int zeros[2] = {0, 0};
	while (votes--) {
		stm32_configgpio(GPIO_PULLDOWN | (HW_VER_PB12 & ~GPIO_PUPD_MASK));
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[0]++ : zeros[0]++;
		stm32_configgpio(HW_VER_PB12);
		up_udelay(10);
		stm32_gpioread(HW_VER_PB12) ? ones[1]++ : zeros[1]++;
	}
	if (ones[0] > zeros[0]) {
		rv |= 1 << pos;
	}
	pos++;
	if (ones[1] > zeros[1]) {
		rv |= 1 << pos;
	}
	stm32_configgpio(HW_VER_PB4_INIT);
	stm32_configgpio(HW_VER_PB12_INIT);
	*version = rv;
	return OK;
}
static int determin_hw_version ( int * version , int * revision ) { * revision = 0 ; int rv = 0 ; int pos = 0 ; stm32_configgpio ( GPIO_PULLDOWN | ( HW_VER_PB4 & ~ GPIO_PUPD_MASK ) ) ; up_udelay ( 10 ) ; rv |= stm32_gpioread ( HW_VER_PB4 ) << pos ++ ; stm32_configgpio ( HW_VER_PB4 ) ; up_udelay ( 10 ) ; rv |= stm32_gpioread ( HW_VER_PB4 ) << pos ++ ; int votes = 16 ; int ones [ 2 ] = { 0 , 0 } ; int zeros [ 2 ] = { 0 , 0 } ; while ( votes -- ) { stm32_configgpio ( GPIO_PULLDOWN | ( HW_VER_PB12 & ~ GPIO_PUPD_MASK ) ) ; up_udelay ( 10 ) ; stm32_gpioread ( HW_VER_PB12 ) ? ones [ 0 ] ++ : zeros [ 0 ] ++ ; stm32_configgpio ( HW_VER_PB12 ) ; up_udelay ( 10 ) ; stm32_gpioread ( HW_VER_PB12 ) ? ones [ 1 ] ++ : zeros [ 1 ] ++ ; } if ( ones [ 0 ] > zeros [ 0 ] ) { rv |= 1 << pos ; } pos ++ ; if ( ones [ 1 ] > zeros [ 1 ] ) { rv |= 1 << pos ; } stm32_configgpio ( HW_VER_PB4_INIT ) ; stm32_configgpio ( HW_VER_PB12_INIT ) ; * version = rv ; return OK ; }
Name: determin_hw_version
 Description:
Name : determin_hw_version Description :
/* default revision */