mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-26 01:35:16 +03:00
Flash internal module
This commit is contained in:
parent
eb453293f5
commit
655966fba2
13 changed files with 422 additions and 361 deletions
|
@ -21,6 +21,8 @@
|
|||
#ifndef _DATACONSTANTS_H_
|
||||
#define _DATACONSTANTS_H_
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define NUM_STICKS 4
|
||||
|
||||
#if defined(EXPORT)
|
||||
|
|
|
@ -141,16 +141,19 @@ void onSdManagerMenu(const char * result)
|
|||
}
|
||||
else if (result == STR_FLASH_INTERNAL_MODULE) {
|
||||
getSelectionFullPath(lfn);
|
||||
sportFlashDevice(INTERNAL_MODULE, lfn);
|
||||
DeviceFirmwareUpdate device(INTERNAL_MODULE);
|
||||
device.flashFile(lfn);
|
||||
}
|
||||
else if (result == STR_FLASH_EXTERNAL_MODULE) {
|
||||
// needed on X-Lite (as the R9M needs 2S while the external device flashing port only provides 5V)
|
||||
getSelectionFullPath(lfn);
|
||||
sportFlashDevice(EXTERNAL_MODULE, lfn);
|
||||
DeviceFirmwareUpdate device(EXTERNAL_MODULE);
|
||||
device.flashFile(lfn);
|
||||
}
|
||||
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
|
||||
getSelectionFullPath(lfn);
|
||||
sportFlashDevice(FLASHING_MODULE, lfn);
|
||||
DeviceFirmwareUpdate device(FLASHING_MODULE);
|
||||
device.flashFile(lfn);
|
||||
}
|
||||
#endif
|
||||
#if defined(LUA)
|
||||
|
|
320
radio/src/io/frsky_device_firmware_update.cpp
Normal file
320
radio/src/io/frsky_device_firmware_update.cpp
Normal file
|
@ -0,0 +1,320 @@
|
|||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define PRIM_REQ_POWERUP 0
|
||||
#define PRIM_REQ_VERSION 1
|
||||
#define PRIM_CMD_DOWNLOAD 3
|
||||
#define PRIM_DATA_WORD 4
|
||||
#define PRIM_DATA_EOF 5
|
||||
|
||||
#define PRIM_ACK_POWERUP 0x80
|
||||
#define PRIM_ACK_VERSION 0x81
|
||||
#define PRIM_REQ_DATA_ADDR 0x82
|
||||
#define PRIM_END_DOWNLOAD 0x83
|
||||
#define PRIM_DATA_CRC_ERR 0x84
|
||||
|
||||
void DeviceFirmwareUpdate::processFrame()
|
||||
{
|
||||
if (frame[1] == 0x5E && frame[2] == 0x50) {
|
||||
switch (frame[3]) {
|
||||
case PRIM_ACK_POWERUP :
|
||||
if (state == SPORT_POWERUP_REQ) {
|
||||
state = SPORT_POWERUP_ACK;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_ACK_VERSION:
|
||||
if (state == SPORT_VERSION_REQ) {
|
||||
state = SPORT_VERSION_ACK;
|
||||
// here we could display the version
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_REQ_DATA_ADDR:
|
||||
if (state == SPORT_DATA_TRANSFER) {
|
||||
address = *((uint32_t *)(&frame[4]));
|
||||
state = SPORT_DATA_REQ;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_END_DOWNLOAD :
|
||||
state = SPORT_COMPLETE ;
|
||||
break;
|
||||
|
||||
case PRIM_DATA_CRC_ERR :
|
||||
state = SPORT_FAIL ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceFirmwareUpdate::startup()
|
||||
{
|
||||
switch(module) {
|
||||
case INTERNAL_MODULE:
|
||||
#if defined(INTMODULE_USART)
|
||||
return intmoduleSerialStart(57600);
|
||||
#endif
|
||||
|
||||
default:
|
||||
return telemetryInit(PROTOCOL_TELEMETRY_FRSKY_SPORT);
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
if (module == INTERNAL_MODULE)
|
||||
INTERNAL_MODULE_ON();
|
||||
else if (module == EXTERNAL_MODULE)
|
||||
EXTERNAL_MODULE_ON();
|
||||
else
|
||||
SPORT_UPDATE_POWER_ON();
|
||||
#endif
|
||||
|
||||
watchdogSuspend(50);
|
||||
RTOS_WAIT_MS(50);
|
||||
}
|
||||
|
||||
bool DeviceFirmwareUpdate::readByte(uint8_t & byte)
|
||||
{
|
||||
switch(module) {
|
||||
case INTERNAL_MODULE:
|
||||
#if defined(INTMODULE_USART)
|
||||
return intmoduleFifo.pop(byte);
|
||||
#endif
|
||||
|
||||
default:
|
||||
return telemetryGetByte(&byte);
|
||||
}
|
||||
}
|
||||
|
||||
bool DeviceFirmwareUpdate::waitState(State state, uint32_t timeout)
|
||||
{
|
||||
#if defined(SIMU)
|
||||
UNUSED(state);
|
||||
UNUSED(timeout);
|
||||
return true;
|
||||
#else
|
||||
watchdogSuspend(timeout / 10);
|
||||
|
||||
uint8_t len = 0;
|
||||
while (len < 10) {
|
||||
uint32_t elapsed = 0;
|
||||
while (!intmoduleFifo.pop(frame[len])) {
|
||||
RTOS_WAIT_MS(1);
|
||||
if (elapsed++ >= timeout) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (len > 0 || frame[len] == 0x7E) {
|
||||
++len;
|
||||
}
|
||||
}
|
||||
|
||||
processFrame();
|
||||
|
||||
return state == state;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DeviceFirmwareUpdate::startFrame(uint8_t command)
|
||||
{
|
||||
frame[0] = 0x50;
|
||||
frame[1] = command;
|
||||
memset(&frame[2], 0, 6);
|
||||
}
|
||||
|
||||
// TODO merge this function
|
||||
void DeviceFirmwareUpdate::sendFrame()
|
||||
{
|
||||
uint8_t * ptr = outputTelemetryBuffer;
|
||||
*ptr++ = 0x7E;
|
||||
*ptr++ = 0xFF;
|
||||
frame[7] = crc16(frame, 7);
|
||||
for (int i=0; i<8; i++) {
|
||||
if (frame[i] == 0x7E || frame[i] == 0x7D) {
|
||||
*ptr++ = 0x7D;
|
||||
*ptr++ = 0x20 ^ frame[i];
|
||||
}
|
||||
else {
|
||||
*ptr++ = frame[i];
|
||||
}
|
||||
}
|
||||
|
||||
switch(module) {
|
||||
case INTERNAL_MODULE:
|
||||
#if defined(INTMODULE_USART)
|
||||
return intmoduleSendBuffer(outputTelemetryBuffer, ptr-outputTelemetryBuffer);
|
||||
#endif
|
||||
|
||||
default:
|
||||
return sportSendBuffer(outputTelemetryBuffer, ptr-outputTelemetryBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
const char * DeviceFirmwareUpdate::sendPowerOn()
|
||||
{
|
||||
waitState(SPORT_IDLE, 20); // Clear the fifo
|
||||
state = SPORT_POWERUP_REQ;
|
||||
for (int i=0; i<10; i++) {
|
||||
// max 10 attempts
|
||||
startFrame(PRIM_REQ_POWERUP);
|
||||
sendFrame();
|
||||
if (waitState(SPORT_POWERUP_ACK, 100))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (telemetryProtocol != PROTOCOL_TELEMETRY_FRSKY_SPORT) {
|
||||
return TR("Not responding", "Not S.Port 1");
|
||||
}
|
||||
|
||||
if (!IS_FRSKY_SPORT_PROTOCOL()) {
|
||||
return TR("Not responding", "Not S.Port 2");
|
||||
}
|
||||
#if defined(PCBX7)
|
||||
if (IS_PCBREV_40()) {
|
||||
return TR("Bottom pin no resp", "Bottom pin not responding");
|
||||
}
|
||||
else {
|
||||
return TR("Module pin no resp", "Module pin not responding");
|
||||
}
|
||||
#else
|
||||
return TR("Not responding", "Module not responding");
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * DeviceFirmwareUpdate::sendReqVersion()
|
||||
{
|
||||
waitState(SPORT_IDLE, 20); // Clear the fifo
|
||||
state = SPORT_VERSION_REQ;
|
||||
for (int i=0; i<10; i++) {
|
||||
// max 10 attempts
|
||||
startFrame(PRIM_REQ_VERSION) ;
|
||||
sendFrame();
|
||||
if (waitState(SPORT_VERSION_ACK, 100))
|
||||
return nullptr;
|
||||
}
|
||||
return "Version request failed";
|
||||
}
|
||||
|
||||
const char * DeviceFirmwareUpdate::uploadFile(const char *filename)
|
||||
{
|
||||
FIL file;
|
||||
uint32_t buffer[1024 / sizeof(uint32_t)];
|
||||
UINT count;
|
||||
|
||||
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
||||
return "Error opening file";
|
||||
}
|
||||
|
||||
waitState(SPORT_IDLE, 200); // Clear the fifo
|
||||
state = SPORT_DATA_TRANSFER;
|
||||
startFrame(PRIM_CMD_DOWNLOAD);
|
||||
sendFrame();
|
||||
|
||||
while (1) {
|
||||
if (f_read(&file, buffer, 1024, &count) != FR_OK) {
|
||||
f_close(&file);
|
||||
return "Error reading file";
|
||||
}
|
||||
|
||||
count >>= 2;
|
||||
|
||||
for (UINT i=0; i<count; i++) {
|
||||
if (!waitState(SPORT_DATA_REQ, 2000)) {
|
||||
return "Module refused data";
|
||||
}
|
||||
startFrame(PRIM_DATA_WORD) ;
|
||||
uint32_t offset = (address & 1023) >> 2; // 32 bit word offset into buffer
|
||||
*((uint32_t *)(frame + 2)) = buffer[offset];
|
||||
frame[6] = address & 0x000000FF;
|
||||
state = SPORT_DATA_TRANSFER,
|
||||
sendFrame();
|
||||
if (i == 0) {
|
||||
drawProgressBar(STR_WRITING, file.fptr, file.obj.objsize);
|
||||
}
|
||||
}
|
||||
|
||||
if (count < 256) {
|
||||
f_close(&file);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char * DeviceFirmwareUpdate::endTransfer()
|
||||
{
|
||||
if (!waitState(SPORT_DATA_REQ, 2000))
|
||||
return "Module refused data";
|
||||
startFrame(PRIM_DATA_EOF);
|
||||
sendFrame();
|
||||
if (!waitState(SPORT_COMPLETE, 2000)) {
|
||||
return "Module rejected firmware";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DeviceFirmwareUpdate::flashFile(const char * filename)
|
||||
{
|
||||
pausePulses();
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
uint8_t intPwr = IS_INTERNAL_MODULE_ON();
|
||||
uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
|
||||
INTERNAL_MODULE_OFF();
|
||||
EXTERNAL_MODULE_OFF();
|
||||
SPORT_UPDATE_POWER_OFF();
|
||||
|
||||
/* wait 2s off */
|
||||
watchdogSuspend(2000);
|
||||
RTOS_WAIT_MS(2000);
|
||||
#endif
|
||||
|
||||
startup();
|
||||
|
||||
const char * result = sendPowerOn();
|
||||
if (!result) result = sendReqVersion();
|
||||
if (!result) result = uploadFile(filename);
|
||||
if (!result) result = endTransfer();
|
||||
|
||||
if (result) {
|
||||
POPUP_WARNING(STR_FIRMWARE_UPDATE_ERROR);
|
||||
SET_WARNING_INFO(result, strlen(result), 0);
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
INTERNAL_MODULE_OFF();
|
||||
EXTERNAL_MODULE_OFF();
|
||||
SPORT_UPDATE_POWER_OFF();
|
||||
#endif
|
||||
|
||||
waitState(SPORT_IDLE, 500); // Clear the fifo
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
if (intPwr)
|
||||
INTERNAL_MODULE_ON();
|
||||
if (extPwr)
|
||||
EXTERNAL_MODULE_ON();
|
||||
#endif
|
||||
|
||||
state = SPORT_IDLE;
|
||||
|
||||
resumePulses();
|
||||
}
|
|
@ -20,33 +20,10 @@
|
|||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(STM32)
|
||||
#define PRIM_REQ_POWERUP (0)
|
||||
#define PRIM_REQ_VERSION (1)
|
||||
#define PRIM_CMD_DOWNLOAD (3)
|
||||
#define PRIM_DATA_WORD (4)
|
||||
#define PRIM_DATA_EOF (5)
|
||||
|
||||
#define PRIM_ACK_POWERUP (0x80)
|
||||
#define PRIM_ACK_VERSION (0x81)
|
||||
#define PRIM_REQ_DATA_ADDR (0x82)
|
||||
#define PRIM_END_DOWNLOAD (0x83)
|
||||
#define PRIM_DATA_CRC_ERR (0x84)
|
||||
|
||||
enum SportUpdateState {
|
||||
SPORT_IDLE,
|
||||
SPORT_POWERUP_REQ,
|
||||
SPORT_POWERUP_ACK,
|
||||
SPORT_VERSION_REQ,
|
||||
SPORT_VERSION_ACK,
|
||||
SPORT_DATA_TRANSFER,
|
||||
SPORT_DATA_REQ,
|
||||
SPORT_COMPLETE,
|
||||
SPORT_FAIL
|
||||
};
|
||||
|
||||
uint8_t sportUpdateState = SPORT_IDLE;
|
||||
uint32_t sportUpdateAddr = 0;
|
||||
bool isSportOutputBufferAvailable()
|
||||
{
|
||||
return (outputTelemetryBufferSize == 0 && outputTelemetryBufferTrigger == 0x7E);
|
||||
}
|
||||
|
||||
void sportOutputPushByte(uint8_t byte)
|
||||
{
|
||||
|
@ -59,11 +36,6 @@ void sportOutputPushByte(uint8_t byte)
|
|||
}
|
||||
}
|
||||
|
||||
bool isSportOutputBufferAvailable()
|
||||
{
|
||||
return (outputTelemetryBufferSize == 0 && outputTelemetryBufferTrigger == 0x7E);
|
||||
}
|
||||
|
||||
// TODO merge it with S.PORT update function when finished
|
||||
void sportOutputPushPacket(SportTelemetryPacket * packet)
|
||||
{
|
||||
|
@ -80,282 +52,3 @@ void sportOutputPushPacket(SportTelemetryPacket * packet)
|
|||
telemetryOutputPushByte(0xFF-crc);
|
||||
telemetryOutputSetTrigger(packet->raw[0]); // physicalId
|
||||
}
|
||||
|
||||
void sportProcessUpdatePacket(uint8_t * packet)
|
||||
{
|
||||
if (packet[0]==0x5E && packet[1]==0x50) {
|
||||
switch (packet[2]) {
|
||||
case PRIM_ACK_POWERUP :
|
||||
if (sportUpdateState == SPORT_POWERUP_REQ) {
|
||||
sportUpdateState = SPORT_POWERUP_ACK;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_ACK_VERSION:
|
||||
if (sportUpdateState == SPORT_VERSION_REQ) {
|
||||
sportUpdateState = SPORT_VERSION_ACK;
|
||||
// SportVersion[0] = packet[3] ;
|
||||
// SportVersion[1] = packet[4] ;
|
||||
// SportVersion[2] = packet[5] ;
|
||||
// SportVersion[3] = packet[6] ;
|
||||
// SportVerValid = 1 ;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_REQ_DATA_ADDR :
|
||||
if (sportUpdateState == SPORT_DATA_TRANSFER) {
|
||||
sportUpdateAddr = *((uint32_t *)(&packet[3]));
|
||||
sportUpdateState = SPORT_DATA_REQ;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRIM_END_DOWNLOAD :
|
||||
sportUpdateState = SPORT_COMPLETE ;
|
||||
break;
|
||||
|
||||
case PRIM_DATA_CRC_ERR :
|
||||
sportUpdateState = SPORT_FAIL ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool sportWaitState(SportUpdateState state, int timeout)
|
||||
{
|
||||
#if defined(SIMU)
|
||||
UNUSED(state);
|
||||
UNUSED(timeout);
|
||||
return true;
|
||||
#else
|
||||
watchdogSuspend(timeout / 10);
|
||||
for (int i=timeout/2; i>=0; i--) {
|
||||
uint8_t byte ;
|
||||
while (telemetryGetByte(&byte)) {
|
||||
processFrskyTelemetryData(byte);
|
||||
}
|
||||
if (sportUpdateState == state) {
|
||||
return true;
|
||||
}
|
||||
else if (sportUpdateState == SPORT_FAIL) {
|
||||
return false;
|
||||
}
|
||||
RTOS_WAIT_TICKS(1);
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void sportClearPacket(uint8_t * packet)
|
||||
{
|
||||
memset(packet+2, 0, 6);
|
||||
}
|
||||
|
||||
// TODO merge this function
|
||||
void sportWritePacket(uint8_t * packet)
|
||||
{
|
||||
uint8_t * ptr = outputTelemetryBuffer;
|
||||
*ptr++ = 0x7E;
|
||||
*ptr++ = 0xFF;
|
||||
packet[7] = crc16(packet, 7);
|
||||
for (int i=0; i<8; i++) {
|
||||
if (packet[i] == 0x7E || packet[i] == 0x7D) {
|
||||
*ptr++ = 0x7D;
|
||||
*ptr++ = 0x20 ^ packet[i];
|
||||
}
|
||||
else {
|
||||
*ptr++ = packet[i];
|
||||
}
|
||||
}
|
||||
sportSendBuffer(outputTelemetryBuffer, ptr-outputTelemetryBuffer);
|
||||
}
|
||||
|
||||
const char * sportUpdatePowerOn(ModuleIndex module)
|
||||
{
|
||||
uint8_t packet[8];
|
||||
|
||||
sportUpdateState = SPORT_POWERUP_REQ;
|
||||
sportWaitState(SPORT_IDLE, 500); // Clear the fifo
|
||||
|
||||
telemetryInit(PROTOCOL_TELEMETRY_FRSKY_SPORT);
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
if (module == INTERNAL_MODULE)
|
||||
INTERNAL_MODULE_ON();
|
||||
else if (module == EXTERNAL_MODULE)
|
||||
EXTERNAL_MODULE_ON();
|
||||
else
|
||||
SPORT_UPDATE_POWER_ON();
|
||||
#endif
|
||||
|
||||
sportWaitState(SPORT_IDLE, 50); // Clear the fifo
|
||||
|
||||
for (int i=0; i<10; i++) {
|
||||
// max 10 attempts
|
||||
sportClearPacket(packet);
|
||||
packet[0] = 0x50 ;
|
||||
packet[1] = PRIM_REQ_POWERUP;
|
||||
sportWritePacket(packet);
|
||||
if (sportWaitState(SPORT_POWERUP_ACK, 100))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (telemetryProtocol != PROTOCOL_TELEMETRY_FRSKY_SPORT) {
|
||||
return TR("Not responding", "Not S.Port 1");
|
||||
}
|
||||
|
||||
if (!IS_FRSKY_SPORT_PROTOCOL()) {
|
||||
return TR("Not responding", "Not S.Port 2");
|
||||
}
|
||||
#if defined(PCBX7)
|
||||
if (IS_PCBREV_40()) {
|
||||
return TR("Bottom pin no resp", "Bottom pin not responding");
|
||||
}
|
||||
else {
|
||||
return TR("Module pin no resp", "Module pin not responding");
|
||||
}
|
||||
#else
|
||||
return TR("Not responding", "Module not responding");
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * sportUpdateReqVersion()
|
||||
{
|
||||
uint8_t packet[8];
|
||||
sportWaitState(SPORT_IDLE, 20); // Clear the fifo
|
||||
sportUpdateState = SPORT_VERSION_REQ;
|
||||
for (int i=0; i<10; i++) {
|
||||
// max 10 attempts
|
||||
sportClearPacket(packet) ;
|
||||
packet[0] = 0x50 ;
|
||||
packet[1] = PRIM_REQ_VERSION ;
|
||||
sportWritePacket(packet);
|
||||
if (sportWaitState(SPORT_VERSION_ACK, 200))
|
||||
return NULL;
|
||||
}
|
||||
return "Version request failed";
|
||||
}
|
||||
|
||||
const char * sportUpdateUploadFile(const char *filename)
|
||||
{
|
||||
FIL file;
|
||||
uint32_t buffer[1024/4];
|
||||
UINT count;
|
||||
uint8_t packet[8];
|
||||
|
||||
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
||||
return "Error opening file";
|
||||
}
|
||||
|
||||
sportWaitState(SPORT_IDLE, 200); // Clear the fifo
|
||||
sportUpdateState = SPORT_DATA_TRANSFER;
|
||||
sportClearPacket(packet) ;
|
||||
packet[0] = 0x50 ;
|
||||
packet[1] = PRIM_CMD_DOWNLOAD ;
|
||||
// Stop here for testing
|
||||
sportWritePacket(packet);
|
||||
|
||||
while(1) {
|
||||
if (f_read(&file, buffer, 1024, &count) != FR_OK) {
|
||||
f_close(&file);
|
||||
return "Error reading file";
|
||||
}
|
||||
|
||||
count >>= 2;
|
||||
|
||||
for (UINT i=0; i<count; i++) {
|
||||
if (!sportWaitState(SPORT_DATA_REQ, 2000)) {
|
||||
return "Module refused data";
|
||||
}
|
||||
packet[0] = 0x50 ;
|
||||
packet[1] = PRIM_DATA_WORD ;
|
||||
packet[6] = sportUpdateAddr & 0x000000FF;
|
||||
uint32_t offset = ( sportUpdateAddr & 1023 ) >> 2; // 32 bit word offset into buffer
|
||||
uint32_t *data = (uint32_t *)(&packet[2]);
|
||||
*data = buffer[offset];
|
||||
sportUpdateState = SPORT_DATA_TRANSFER,
|
||||
sportWritePacket(packet);
|
||||
if (i==0) {
|
||||
drawProgressBar(STR_WRITING, file.fptr, file.obj.objsize);
|
||||
}
|
||||
}
|
||||
|
||||
if (count < 256) {
|
||||
f_close(&file);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char * sportUpdateEnd()
|
||||
{
|
||||
uint8_t packet[8];
|
||||
if (!sportWaitState(SPORT_DATA_REQ, 2000))
|
||||
return "Module refused data";
|
||||
sportClearPacket(packet);
|
||||
packet[0] = 0x50 ;
|
||||
packet[1] = PRIM_DATA_EOF;
|
||||
sportWritePacket(packet);
|
||||
if (!sportWaitState(SPORT_COMPLETE, 2000)) {
|
||||
return "Module rejected firmware";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void sportFlashDevice(ModuleIndex module, const char * filename)
|
||||
{
|
||||
pausePulses();
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
uint8_t intPwr = IS_INTERNAL_MODULE_ON();
|
||||
uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
|
||||
INTERNAL_MODULE_OFF();
|
||||
EXTERNAL_MODULE_OFF();
|
||||
SPORT_UPDATE_POWER_OFF();
|
||||
|
||||
/* wait 2s off */
|
||||
watchdogSuspend(2000);
|
||||
RTOS_WAIT_MS(2000);
|
||||
#endif
|
||||
|
||||
const char * result = sportUpdatePowerOn(module);
|
||||
if (!result) result = sportUpdateReqVersion();
|
||||
if (!result) result = sportUpdateUploadFile(filename);
|
||||
if (!result) result = sportUpdateEnd();
|
||||
|
||||
if (result) {
|
||||
POPUP_WARNING(STR_FIRMWARE_UPDATE_ERROR);
|
||||
SET_WARNING_INFO(result, strlen(result), 0);
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
INTERNAL_MODULE_OFF();
|
||||
EXTERNAL_MODULE_OFF();
|
||||
SPORT_UPDATE_POWER_OFF();
|
||||
#endif
|
||||
|
||||
sportWaitState(SPORT_IDLE, 500); // Clear the fifo
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
if (intPwr)
|
||||
INTERNAL_MODULE_ON();
|
||||
if (extPwr)
|
||||
EXTERNAL_MODULE_ON();
|
||||
#endif
|
||||
|
||||
sportUpdateState = SPORT_IDLE;
|
||||
|
||||
resumePulses();
|
||||
}
|
||||
#endif
|
||||
|
||||
void sportProcessPacket(uint8_t * packet)
|
||||
{
|
||||
#if defined(STM32)
|
||||
if (sportUpdateState != SPORT_IDLE) {
|
||||
sportProcessUpdatePacket(packet); // Uses different chksum
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
sportProcessTelemetryPacket(packet);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ PACK(union SportTelemetryPacket
|
|||
uint8_t raw[8];
|
||||
});
|
||||
|
||||
void sportProcessPacket(uint8_t * packet);
|
||||
bool isSportOutputBufferAvailable();
|
||||
void sportOutputPushPacket(SportTelemetryPacket * packet);
|
||||
void sportFlashDevice(ModuleIndex module, const char * filename);
|
||||
|
@ -45,5 +44,46 @@ void sportFlashDevice(ModuleIndex module, const char * filename);
|
|||
bool isBootloader(const char * filename);
|
||||
void bootloaderFlash(const char * filename);
|
||||
#endif
|
||||
|
||||
|
||||
class DeviceFirmwareUpdate {
|
||||
enum State {
|
||||
SPORT_IDLE,
|
||||
SPORT_POWERUP_REQ,
|
||||
SPORT_POWERUP_ACK,
|
||||
SPORT_VERSION_REQ,
|
||||
SPORT_VERSION_ACK,
|
||||
SPORT_DATA_TRANSFER,
|
||||
SPORT_DATA_REQ,
|
||||
SPORT_COMPLETE,
|
||||
SPORT_FAIL
|
||||
};
|
||||
|
||||
public:
|
||||
DeviceFirmwareUpdate(ModuleIndex module):
|
||||
module(module) {
|
||||
}
|
||||
|
||||
void flashFile(const char * filename);
|
||||
|
||||
protected:
|
||||
uint8_t state = SPORT_IDLE;
|
||||
uint32_t address = 0;
|
||||
ModuleIndex module;
|
||||
uint8_t frame[12];
|
||||
|
||||
void startup();
|
||||
|
||||
void startFrame(uint8_t command);
|
||||
void sendFrame();
|
||||
|
||||
bool readByte(uint8_t & byte);
|
||||
bool waitState(State state, uint32_t timeout);
|
||||
void processFrame();
|
||||
|
||||
const char * sendPowerOn();
|
||||
const char * sendReqVersion();
|
||||
const char * uploadFile(const char * filename);
|
||||
const char * endTransfer();
|
||||
};
|
||||
|
||||
#endif // _IO_ARM_H_
|
||||
|
|
|
@ -143,6 +143,7 @@ set(SRC
|
|||
tasks.cpp
|
||||
audio.cpp
|
||||
io/frsky_sport.cpp
|
||||
io/frsky_device_firmware_update.cpp
|
||||
telemetry/telemetry.cpp
|
||||
telemetry/telemetry_holders.cpp
|
||||
telemetry/telemetry_sensors.cpp
|
||||
|
|
|
@ -34,7 +34,7 @@ void intmodulePxxStart()
|
|||
// shouldn't be used anymore
|
||||
}
|
||||
|
||||
void intmodulePxx2Start()
|
||||
void intmoduleSerialStart(uint32_t baudrate)
|
||||
{
|
||||
INTERNAL_MODULE_ON();
|
||||
|
||||
|
@ -58,7 +58,7 @@ void intmodulePxx2Start()
|
|||
|
||||
USART_DeInit(INTMODULE_USART);
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
USART_InitStructure.USART_BaudRate = INTMODULE_USART_PXX_BAUDRATE;
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
|
@ -89,30 +89,35 @@ extern "C" void INTMODULE_USART_IRQHandler(void)
|
|||
}
|
||||
}
|
||||
|
||||
void intmoduleSendBuffer(const uint8_t * data, uint8_t size)
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
DMA_DeInit(INTMODULE_DMA_STREAM);
|
||||
DMA_InitStructure.DMA_Channel = INTMODULE_DMA_CHANNEL;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&INTMODULE_USART->DR);
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(data);
|
||||
DMA_InitStructure.DMA_BufferSize = size;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
|
||||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
DMA_Init(INTMODULE_DMA_STREAM, &DMA_InitStructure);
|
||||
DMA_Cmd(INTMODULE_DMA_STREAM, ENABLE);
|
||||
USART_DMACmd(INTMODULE_USART, USART_DMAReq_Tx, ENABLE);
|
||||
}
|
||||
|
||||
void intmoduleSendNextFrame()
|
||||
{
|
||||
#if defined(PXX2)
|
||||
if (moduleSettings[INTERNAL_MODULE].protocol == PROTOCOL_CHANNELS_PXX2) {
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
DMA_DeInit(INTMODULE_DMA_STREAM);
|
||||
DMA_InitStructure.DMA_Channel = INTMODULE_DMA_CHANNEL;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&INTMODULE_USART->DR);
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(intmodulePulsesData.pxx2.getData());
|
||||
DMA_InitStructure.DMA_BufferSize = intmodulePulsesData.pxx2.getSize();
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
|
||||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
DMA_Init(INTMODULE_DMA_STREAM, &DMA_InitStructure);
|
||||
DMA_Cmd(INTMODULE_DMA_STREAM, ENABLE);
|
||||
USART_DMACmd(INTMODULE_USART, USART_DMAReq_Tx, ENABLE);
|
||||
intmoduleSendBuffer(intmodulePulsesData.pxx2.getData(), intmodulePulsesData.pxx2.getSize());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
void intmoduleStop();
|
||||
void intmodulePxxStart();
|
||||
void intmodulePxx2Start();
|
||||
void intmoduleSerialStart(uint32_t baudrate);
|
||||
|
||||
void extmoduleStop();
|
||||
void extmodulePpmStart();
|
||||
|
@ -48,7 +48,7 @@ void disable_ppm(uint8_t module)
|
|||
void init_pxx2(uint8_t module)
|
||||
{
|
||||
if (module == INTERNAL_MODULE)
|
||||
intmodulePxx2Start();
|
||||
intmoduleSerialStart(INTMODULE_USART_PXX_BAUDRATE);
|
||||
else
|
||||
extmodulePxx2Start();
|
||||
}
|
||||
|
|
|
@ -172,14 +172,27 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
|
|||
|
||||
void init_ppm(uint8_t module);
|
||||
void disable_ppm(uint8_t module);
|
||||
void intmoduleSendNextFrame();
|
||||
void extmoduleSendNextFrame();
|
||||
void init_pxx2(uint8_t module);
|
||||
void disable_pxx2(uint8_t module);
|
||||
void init_pxx(uint8_t module);
|
||||
void disable_pxx(uint8_t module);
|
||||
void init_serial(uint8_t module, uint32_t baudrate, uint32_t period);
|
||||
void disable_serial(uint8_t module);
|
||||
void intmoduleStop();
|
||||
void intmodulePxxStart();
|
||||
void intmoduleSerialStart(uint32_t baudrate);
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
void intmodulePpmStart(void);
|
||||
#endif
|
||||
void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
|
||||
void intmoduleSendNextFrame();
|
||||
|
||||
void extmoduleStop();
|
||||
void extmodulePpmStart();
|
||||
void extmodulePxxStart();
|
||||
void extmodulePxx2Start();
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
|
||||
void extmoduleSendNextFrame();
|
||||
|
||||
// Trainer driver
|
||||
#define SLAVE_MODE() (g_model.trainerData.mode == TRAINER_MODE_SLAVE)
|
||||
|
|
|
@ -1165,8 +1165,6 @@
|
|||
#define I2CX_SCL_GPIO_PinSource GPIO_PinSource8
|
||||
#define I2CX_SDA_GPIO_PinSource GPIO_PinSource9
|
||||
#define I2CX_SPEED 400000
|
||||
#define I2CX_IMU_INT_GPIO GPIOC
|
||||
#define I2CX_IMU_INT_GPIO_PIN GPIO_Pin_8 // PC.08
|
||||
#endif
|
||||
|
||||
// SD - SPI2
|
||||
|
|
|
@ -65,7 +65,7 @@ void intmoduleSendNextFrame()
|
|||
}
|
||||
}
|
||||
|
||||
void intmodulePxx2Start()
|
||||
void intmoduleSerialStart(uint32_t baudrate)
|
||||
{
|
||||
// nothing, the pulses will be sent through telemetry port
|
||||
}
|
||||
|
|
|
@ -20,20 +20,6 @@
|
|||
|
||||
#include "opentx.h"
|
||||
|
||||
void intmoduleStop();
|
||||
void intmodulePxxStart();
|
||||
void intmodulePxx2Start();
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
void intmodulePpmStart(void);
|
||||
#endif
|
||||
|
||||
void extmoduleStop();
|
||||
void extmoduleTimerStart(uint32_t period, uint8_t state);
|
||||
void extmodulePpmStart();
|
||||
void extmodulePxxStart();
|
||||
void extmodulePxx2Start();
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
|
||||
|
||||
void init_pxx(uint8_t module)
|
||||
{
|
||||
if (module == INTERNAL_MODULE)
|
||||
|
@ -53,7 +39,7 @@ void disable_pxx(uint8_t module)
|
|||
void init_pxx2(uint8_t module)
|
||||
{
|
||||
if (module == INTERNAL_MODULE)
|
||||
intmodulePxx2Start();
|
||||
intmoduleSerialStart(INTMODULE_USART_PXX_BAUDRATE);
|
||||
else
|
||||
extmodulePxx2Start();
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ void processFrskyTelemetryData(uint8_t data)
|
|||
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
if (IS_FRSKY_SPORT_PROTOCOL() && telemetryRxBufferCount >= FRSKY_SPORT_PACKET_SIZE) {
|
||||
sportProcessPacket(telemetryRxBuffer);
|
||||
sportProcessTelemetryPacket(telemetryRxBuffer);
|
||||
dataState = STATE_DATA_IDLE;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue