void CommHandler(void) //UART4 Interrupt handler implementation { int c = GetChar(); if (c >= 0) { LEDon(); switch (c) { case 'a': debugAutoPan ^= 1; print("Autopan messages %s\r\n", debugAutoPan ? "on" : "off"); break; case 'b': print("rebooting into boot loader ...\r\n"); Delay_ms(1000); bootloader(); break; case 'c': debugCnt ^= 1; print("counter messages %s\r\n", debugCnt ? "on" : "off"); break; case 'd': debugPrint ^= 1; print("debug messages %s\r\n", debugPrint ? "on" : "off"); break; case 'g': Delay_ms(100); PutChar('x'); for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = configData[i]; PutChar(data); } break; case 'G': printConfig(); break; #if 0 case 'H': if (CharAvailable() >= CONFIGDATASIZE) { for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = GetChar(); if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); } else { UnGetChar(c); // try again in next loop } break; #endif case 'h': for (int i = 0; i < CONFIGDATASIZE; i++) { int data; while ((data = GetChar()) < 0) ; if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); break; case 'i': ConfigMode = 1; break; case 'j': ConfigMode = 0; break; case 'o': debugOrient ^= 1; print("Orientation messages %s\r\n", debugOrient ? "on" : "off"); break; case 'O': debugGravityVector ^= 1; print("GVector messages %s\r\n", debugGravityVector ? "on" : "off"); break; case 'S': debugSetpoints ^= 1; print("Setpoints messages %s\r\n", debugSetpoints ? "on" : "off"); break; case 'p': debugPerf ^= 1; print("performance messages %s\r\n", debugPerf ? "on" : "off"); break; case 'r': debugRC ^= 1; print("RC messages %s\r\n", debugRC ? "on" : "off"); break; case 'R': print("rebooting...\r\n"); Delay_ms(1000); reboot(); break; case 's': debugSense ^= 1; print("Sensor messages %s\r\n", debugSense ? "on" : "off"); break; case 'u': { extern int bDeviceState; printUSART("\r\nYY bDeviceState %3d VCPConnectMode %d\r\n", bDeviceState, GetVCPConnectMode()); break; } case 'v': print("Version: %s\r\n", __EV_VERSION); break; case '+': testPhase += 0.1; print("test phase output %5.1f\r\n", testPhase); break; case '-': testPhase -= 0.1; print("test phase output %5.1f\r\n", testPhase); break; /* case '?': print("CLI documentation\r\n"); // print("\t'+' test phase output increase (now %5.1f)\r\n", testPhase); //print("\t'-' test phase output decrease (now %5.1f)\r\n", testPhase); print("\t'a' autopan messages display (now %s)\r\n", debugAutoPan ? "on" : "off"); print("\t'b' reboot into bootloader\r\n"); print("\t'c' counter messages display (now %s)\r\n", debugCnt ? "on" : "off"); print("\t'd' debug messages display (now %s)\r\n", debugPrint ? "on" : "off"); print("\t'g' dump configuration (binary)\r\n"); print("\t'G' dump configuration (hexadecimal)\r\n"); // print("\t'h' write and save config array\r\n"); print("\t'i' enter config mode (now %s)\r\n", ConfigMode ? "on" : "off"); print("\t'j' leave config mode (now %s)\r\n", ConfigMode ? "on" : "off"); print("\t'o' orientation messages display (now %s)\r\n", debugOrient ? "on" : "off"); print("\t'p' performance messages display (now %s)\r\n", debugPerf ? "on" : "off"); print("\t'r' RC messages display (now %s)\r\n", debugRC ? "on" : "off"); print("\t'R' reboot\r\n"); print("\t's' toggle sensor messages display (now %s)\r\n", debugSense ? "on" : "off"); print("\t'u' print USB state (bDeviceState %3d VCPConnectMode %d)\r\n", bDeviceState, GetVCPConnectMode()); print("\t'v' print version (%s)\r\n", __EV_VERSION); break; */ default: // TODO break; } } }
void systemInit(void) { RCC_ClocksTypeDef rccClocks; /////////////////////////////////// // Init cycle counter cycleCounterInit(); // SysTick SysTick_Config(SystemCoreClock / 1000); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM8 | RCC_APB2Periph_ADC1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_TIM5 | RCC_APB1Periph_TIM6 | RCC_APB1Periph_I2C2, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); #ifdef _DTIMING timingSetup(); #endif /////////////////////////////////////////////////////////////////////////// checkFirstTime(false); readEEPROM(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2 bits for pre-emption priority, 2 bits for subpriority pwmMotorDriverInit(); cliInit(); gpioInit(); adcInit(); LED2_ON; delay(10000); // 10 seconds of 20 second delay for sensor stabilization if (GetVCPConnectMode() != eVCPConnectReset) { cliPrintF("\r\nUSB startup delay...\r\n"); delay(3000); if (GetVCPConnectMode() == eVCPConnectData) { cliPrintF("\r\nBGC32 firmware starting up, USB connected...\r\n"); } } else { cliPrintF("\r\nDelaying for usb/serial driver to settle\r\n"); delay(3000); cliPrintF("\r\nBGC32 firmware starting up, serial active...\r\n"); } #ifdef __VERSION__ cliPrintF("\ngcc version " __VERSION__ "\n"); #endif cliPrintF("BGC32 Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __BGC32_VERSION); if ((RCC->CR & RCC_CR_HSERDY) != RESET) { cliPrintF("\nRunning on external HSE clock....\n"); } else { cliPrintF("\nERROR: Running on internal HSI clock....\n"); } RCC_GetClocksFreq(&rccClocks); cliPrintF("\nADCCLK-> %2d MHz\n", rccClocks.ADCCLK_Frequency / 1000000); cliPrintF( "HCLK-> %2d MHz\n", rccClocks.HCLK_Frequency / 1000000); cliPrintF( "PCLK1-> %2d MHz\n", rccClocks.PCLK1_Frequency / 1000000); cliPrintF( "PCLK2-> %2d MHz\n", rccClocks.PCLK2_Frequency / 1000000); cliPrintF( "SYSCLK-> %2d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000); delay(10000); // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough.. LED1_ON; i2cInit(I2C2); rcInit(); timingFunctionsInit(); BKPInit(); initFirstOrderFilter(); initPID(); initSinArray(); orientIMU(); initMPU6050(); // initMag(); }
void CommHandler(void) //UART4 Interrupt handler implementation { int c = GetChar(); if (c >= 0) { //ConfigMode = 1; LEDon(); //print("got char %02X\r\n", c); switch (c) { case 'b': print("rebooting into boot loader ...\r\n"); Delay_ms(1000); bootloader(); break; case 'c': debugCnt ^= 1; print("counter messages %s\r\n", debugCnt ? "on" : "off"); break; case 'd': debugPrint ^= 1; print("debug messages %s\r\n", debugPrint ? "on" : "off"); break; case 'g': Delay_ms(100); PutChar('x'); for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = configData[i]; PutChar(data); } break; case 'G': printConfig(); break; #if 0 case 'H': if (CharAvailable() >= CONFIGDATASIZE) { for (int i = 0; i < CONFIGDATASIZE; i++) { uint8_t data = GetChar(); if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); } else { UnGetChar(c); // try again in next loop } break; #endif case 'h': for (int i = 0; i < CONFIGDATASIZE; i++) { int data; while ((data = GetChar()) < 0) ; if (data <= LARGEST_CONFIGDATA) { configData[i] = data; } } configSave(); break; case 'i': ConfigMode = 1; break; case 'j': ConfigMode = 0; break; case 'o': debugOrient ^= 1; print("Orientation messages %s\r\n", debugOrient ? "on" : "off"); break; case 'p': debugPerf ^= 1; print("performance messages %s\r\n", debugPerf ? "on" : "off"); break; case 'r': debugRC ^= 1; print("RC messages %s\r\n", debugRC ? "on" : "off"); break; case 'R': print("rebooting...\r\n"); Delay_ms(1000); reboot(); break; case 's': debugSense ^= 1; print("Sensor messages %s\r\n", debugSense ? "on" : "off"); break; case 'u': { extern int bDeviceState; printUSART("\r\nYY bDeviceState %3d VCPConnectMode %d\r\n", bDeviceState, GetVCPConnectMode()); break; } case '+': testPhase += 0.1; print("test phase output %5.1f\r\n", testPhase); break; case '-': testPhase -= 0.1; print("test phase output %5.1f\r\n", testPhase); break; default: // TODO break; } } }