2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
24 #include "build/build_config.h"
26 #include "drivers/system.h"
27 #include "drivers/bus_spi.h"
28 #include "drivers/io.h"
29 #include "drivers/flash_m25p16.h"
30 #include "hardware_revision.h"
32 uint8_t hardwareRevision
= UNKNOWN
;
34 void detectHardwareRevision(void)
36 IO_t pin1
= IOGetByTag(IO_TAG(PB12
));
37 IOInit(pin1
, OWNER_SYSTEM
, 1);
38 IOConfigGPIO(pin1
, IOCFG_IPU
);
40 // Check hardware revision
41 delayMicroseconds(10); // allow configuration to settle
44 if both PB12 and 13 are tied to GND then it is Rev3A (mini)
45 if only PB12 is tied to GND then it is a Rev3 (full size)
48 hardwareRevision
= BJF4_REV3
;
50 IO_t pin2
= IOGetByTag(IO_TAG(PB13
));
51 IOInit(pin2
, OWNER_SYSTEM
, 2);
52 IOConfigGPIO(pin2
, IOCFG_IPU
);
55 hardwareRevision
= BJF4_REV4
;
58 IO_t pin2
= IOGetByTag(IO_TAG(PB13
));
59 IOInit(pin2
, OWNER_SYSTEM
, 2);
60 IOConfigGPIO(pin2
, IOCFG_OUT_PP
);
65 hardwareRevision
= BJF4_MINI_REV3A
;
69 if (hardwareRevision
== UNKNOWN
) {
70 hardwareRevision
= BJF4_REV2
;
75 void updateHardwareRevision(void)
77 if (hardwareRevision
!= BJF4_REV2
) {
82 if flash exists on PB3 then Rev1
84 flashConfig_t flashConfig
= { .csTag
= IO_TAG(PB3
) };
85 if (m25p16_init(&flashConfig
)) {
86 hardwareRevision
= BJF4_REV1
;
88 IOInit(IOGetByTag(IO_TAG(PB3
)), OWNER_FREE
, 0);