diff --git a/src/board.h b/src/board.h index 401d8f24e4..fa2962220c 100755 --- a/src/board.h +++ b/src/board.h @@ -239,6 +239,7 @@ typedef struct baro_t #define LED1 #define SENSORS_SET (SENSOR_ACC | SENSOR_BARO | SENSOR_MAG) +// #define PROD_DEBUG #endif #endif diff --git a/src/main.c b/src/main.c index 6e3294c0f0..c66a1d6476 100755 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,7 @@ int main(void) serialPort_t* loopbackPort1 = NULL; serialPort_t* loopbackPort2 = NULL; #endif + checkFirstTime(false); readEEPROM(); systemInit(mcfg.emf_avoidance); @@ -54,12 +55,25 @@ int main(void) } adcInit(&adc_params); + // Check battery type/voltage + if (feature(FEATURE_VBAT)) + batteryInit(); initBoardAlignment(); // We have these sensors; SENSORS_SET defined in board.h depending on hardware platform sensorsSet(SENSORS_SET); - + // drop out any sensors that don't seem to work, init all the others. halt if gyro is dead. + sensorsAutodetect(); + imuInit(); // Mag is initialized inside imuInit mixerInit(); // this will set core.useServo var depending on mixer type + + // production debug output +#ifdef PROD_DEBUG + productionDebug(); +#endif + + serialInit(mcfg.serial_baudrate); + // when using airplane/wing mixer, servo/motor outputs are remapped if (mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_FLYING_WING) pwm_params.airplane = true; @@ -129,29 +143,6 @@ int main(void) } #endif - LED1_ON; - LED0_OFF; - for (i = 0; i < 10; i++) { - LED1_TOGGLE; - LED0_TOGGLE; - delay(25); - BEEP_ON; - delay(25); - BEEP_OFF; - } - LED0_OFF; - LED1_OFF; - - // drop out any sensors that don't seem to work, init all the others. halt if gyro is dead. - sensorsAutodetect(); - imuInit(); // Mag is initialized inside imuInit - - // Check battery type/voltage - if (feature(FEATURE_VBAT)) - batteryInit(); - - serialInit(mcfg.serial_baudrate); - if (feature(FEATURE_SOFTSERIAL)) { //mcfg.softserial_baudrate = 19200; // Uncomment to override config value @@ -178,6 +169,19 @@ int main(void) calibratingB = CALIBRATING_BARO_CYCLES; // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles f.SMALL_ANGLE = 1; + LED1_ON; + LED0_OFF; + for (i = 0; i < 10; i++) { + LED1_TOGGLE; + LED0_TOGGLE; + delay(25); + BEEP_ON; + delay(25); + BEEP_OFF; + } + LED0_OFF; + LED1_OFF; + // loopy while (1) { loop(); diff --git a/src/utils.c b/src/utils.c index f174069dc3..b5e5bdf99e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -119,3 +119,24 @@ void alignSensors(int16_t *src, int16_t *dest, uint8_t rotation) if (!standardBoardAlignment) alignBoard(dest); } + +#ifdef PROD_DEBUG +void productionDebug(void) +{ + gpio_config_t gpio; + + // remap PB6 to USART1_TX + gpio.pin = Pin_6; + gpio.mode = Mode_AF_PP; + gpio.speed = Speed_2MHz; + gpioInit(GPIOB, &gpio); + gpioPinRemapConfig(AFIO_MAPR_USART1_REMAP, true); + serialInit(mcfg.serial_baudrate); + delay(25); + serialPrint(core.mainport, "DBG "); + printf("%08x%08x%08x OK\n", U_ID_0, U_ID_1, U_ID_2); + serialPrint(core.mainport, "EOF"); + delay(25); + gpioPinRemapConfig(AFIO_MAPR_USART1_REMAP, false); +} +#endif diff --git a/src/utils.h b/src/utils.h index c6ef6b8cbb..589c122cb9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,3 +4,4 @@ int constrain(int amt, int low, int high); // sensor orientation void alignSensors(int16_t *src, int16_t *dest, uint8_t rotation); void initBoardAlignment(void); +void productionDebug(void);