Added support for flashing AVR multi on horus targets (#6888)
* Added support for flashing AVR multi on horus targets taranis soft serial Added support for flashing AVR multi on horus targets taranis soft serial * Added support for multi V2 signature (hex code) * Check multi signature before flashing * small clean-up * Cosmetics * Fix v2 signature check * Cosmetics
This commit is contained in:
@@ -28,6 +28,17 @@ DMAFifo<TELEMETRY_FIFO_SIZE> telemetryDMAFifo __DMA (TELEMETRY_DMA_Stream_RX);
|
||||
uint8_t telemetryFifoMode;
|
||||
#endif
|
||||
|
||||
static void telemetryInitDirPin()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_DIR_GPIO_PIN;
|
||||
GPIO_Init(TELEMETRY_DIR_GPIO, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(TELEMETRY_DIR_GPIO, TELEMETRY_DIR_GPIO_PIN);
|
||||
}
|
||||
|
||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
{
|
||||
if (baudrate == 0) {
|
||||
@@ -55,11 +66,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_Init(TELEMETRY_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_DIR_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(TELEMETRY_DIR_GPIO, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(TELEMETRY_DIR_GPIO, TELEMETRY_DIR_GPIO_PIN);
|
||||
telemetryInitDirPin();
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
if (mode & TELEMETRY_SERIAL_8E2) {
|
||||
@@ -126,6 +133,95 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
|
||||
#endif
|
||||
}
|
||||
|
||||
// soft serial vars
|
||||
static uint8_t rxBitCount;
|
||||
static uint8_t rxByte;
|
||||
|
||||
void telemetryPortInvertedInit(uint32_t baudrate)
|
||||
{
|
||||
if (baudrate == 0) {
|
||||
NVIC_DisableIRQ(TELEMETRY_EXTI_IRQn);
|
||||
NVIC_DisableIRQ(TELEMETRY_TIMER_IRQn);
|
||||
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
EXTI_InitStructure.EXTI_Line = TELEMETRY_EXTI_LINE;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = TELEMETRY_EXTI_TRIGGER;
|
||||
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
return;
|
||||
}
|
||||
|
||||
rxBitCount = 0;
|
||||
|
||||
// configure bit sample timer
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
|
||||
TELEMETRY_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1; // 0.5uS
|
||||
TELEMETRY_TIMER->CCER = 0;
|
||||
TELEMETRY_TIMER->CCMR1 = 0;
|
||||
TELEMETRY_TIMER->CR1 = TIM_CR1_CEN;
|
||||
TELEMETRY_TIMER->DIER = TIM_DIER_UIE;
|
||||
|
||||
NVIC_SetPriority(TELEMETRY_TIMER_IRQn, 0);
|
||||
NVIC_EnableIRQ(TELEMETRY_TIMER_IRQn);
|
||||
|
||||
// init TELEMETRY_RX_GPIO_PIN
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_RX_GPIO_PIN;
|
||||
GPIO_Init(TELEMETRY_GPIO, &GPIO_InitStructure);
|
||||
|
||||
telemetryInitDirPin();
|
||||
|
||||
// Connect EXTI line to TELEMETRY RX pin
|
||||
SYSCFG_EXTILineConfig(TELEMETRY_EXTI_PortSource, TELEMETRY_EXTI_PinSource);
|
||||
|
||||
// Configure EXTI for raising edge (start bit)
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
EXTI_InitStructure.EXTI_Line = TELEMETRY_EXTI_LINE;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = TELEMETRY_EXTI_TRIGGER;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_SetPriority(TELEMETRY_EXTI_IRQn, 0);
|
||||
NVIC_EnableIRQ(TELEMETRY_EXTI_IRQn);
|
||||
}
|
||||
|
||||
void telemetryPortInvertedRxBit()
|
||||
{
|
||||
if (rxBitCount < 8) {
|
||||
if (rxBitCount == 0) {
|
||||
TELEMETRY_TIMER->ARR = 34;
|
||||
rxByte = 0;
|
||||
}
|
||||
else {
|
||||
rxByte >>= 1;
|
||||
}
|
||||
|
||||
if (GPIO_ReadInputDataBit(TELEMETRY_GPIO, TELEMETRY_RX_GPIO_PIN) == Bit_RESET)
|
||||
rxByte |= 0x80;
|
||||
|
||||
++rxBitCount;
|
||||
}
|
||||
else if (rxBitCount == 8) {
|
||||
|
||||
telemetryNoDMAFifo.push(rxByte);
|
||||
rxBitCount = 0;
|
||||
|
||||
// disable timer
|
||||
TELEMETRY_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
|
||||
// re-enable start bit interrupt
|
||||
EXTI->IMR |= EXTI_IMR_MR6;
|
||||
}
|
||||
}
|
||||
|
||||
void telemetryPortSetDirectionOutput()
|
||||
{
|
||||
TELEMETRY_DIR_GPIO->BSRRL = TELEMETRY_DIR_GPIO_PIN; // output enable
|
||||
@@ -253,6 +349,29 @@ extern "C" void TELEMETRY_USART_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void TELEMETRY_EXTI_IRQHandler(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(TELEMETRY_EXTI_LINE) != RESET) {
|
||||
|
||||
if (rxBitCount == 0) {
|
||||
|
||||
TELEMETRY_TIMER->ARR = 48; // 1,5 cycle from start at 57600bps
|
||||
TELEMETRY_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
// disable start bit interrupt
|
||||
EXTI->IMR &= ~EXTI_IMR_MR6;
|
||||
}
|
||||
|
||||
EXTI_ClearITPendingBit(TELEMETRY_EXTI_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void TELEMETRY_TIMER_IRQHandler()
|
||||
{
|
||||
TELEMETRY_TIMER->SR &= ~TIM_SR_UIF;
|
||||
telemetryPortInvertedRxBit();
|
||||
}
|
||||
|
||||
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
|
||||
bool telemetryGetByte(uint8_t * byte)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user