added support for BLHeli32

This commit is contained in:
4712 2017-05-05 23:56:45 +02:00
parent e1c4b5cc2d
commit 746040d6cd
4 changed files with 95 additions and 19 deletions

View File

@ -69,11 +69,11 @@
#define SERIAL_4WAY_INTERFACE_NAME_STR "m4wFCIntf"
// *** change to adapt Revision
#define SERIAL_4WAY_VER_MAIN 14
#define SERIAL_4WAY_VER_SUB_1 (uint8_t) 4
#define SERIAL_4WAY_VER_SUB_2 (uint8_t) 04
#define SERIAL_4WAY_VER_MAIN 20
#define SERIAL_4WAY_VER_SUB_1 (uint8_t) 0
#define SERIAL_4WAY_VER_SUB_2 (uint8_t) 00
#define SERIAL_4WAY_PROTOCOL_VER 106
#define SERIAL_4WAY_PROTOCOL_VER 107
// *** end
#if (SERIAL_4WAY_VER_MAIN > 24)
@ -254,6 +254,13 @@ void esc4wayRelease(void)
// PARAM: uint8_t Mode
// RETURN: ACK or ACK_I_INVALID_CHANNEL
//Write to Buffer for Verify Device Memory of connected Device //Buffer Len is Max 256 Bytes
//BuffLen = 0 means 256 Bytes
#define cmd_DeviceVerify 0x40 //'@' write
//PARAM: uint8_t ADRESS_Hi + ADRESS_Lo + BUffLen + Buffer[0..255]
//RETURN: ACK
// responses
#define ACK_OK 0x00
// #define ACK_I_UNKNOWN_ERROR 0x01
@ -323,13 +330,16 @@ uint16_t _crc_xmodem_update (uint16_t crc, uint8_t data) {
(pDeviceInfo->words[0] == 0xF850) || (pDeviceInfo->words[0] == 0xE8B1) || \
(pDeviceInfo->words[0] == 0xE8B2))
#define ARM_DEVICE_MATCH ((pDeviceInfo->words[0] == 0x9307) || (pDeviceInfo->words[0] == 0x930A) || \
(pDeviceInfo->words[0] == 0x3306) || (pDeviceInfo->words[0] == 0x3406))
static uint8_t CurrentInterfaceMode;
static uint8_t Connect(uint8_32_u *pDeviceInfo)
{
for (uint8_t I = 0; I < 3; ++I) {
#if (defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) && defined(USE_SERIAL_4WAY_SK_BOOTLOADER))
if (Stk_ConnectEx(pDeviceInfo) && ATMEL_DEVICE_MATCH) {
if ((CurrentInterfaceMode != imARM_BLB) && Stk_ConnectEx(pDeviceInfo) && ATMEL_DEVICE_MATCH) {
CurrentInterfaceMode = imSK;
return 1;
} else {
@ -340,6 +350,9 @@ static uint8_t Connect(uint8_32_u *pDeviceInfo)
} else if ATMEL_DEVICE_MATCH {
CurrentInterfaceMode = imATM_BLB;
return 1;
} else if ARM_DEVICE_MATCH {
CurrentInterfaceMode = imARM_BLB;
return 1;
}
}
}
@ -351,6 +364,9 @@ static uint8_t Connect(uint8_32_u *pDeviceInfo)
} else if ATMEL_DEVICE_MATCH {
CurrentInterfaceMode = imATM_BLB;
return 1;
} else if ARM_DEVICE_MATCH {
CurrentInterfaceMode = imARM_BLB;
return 1;
}
}
#elif defined(USE_SERIAL_4WAY_SK_BOOTLOADER)
@ -470,6 +486,7 @@ void esc4wayProcess(serialPort_t *mspPort)
#ifdef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
case imATM_BLB:
case imSIL_BLB:
case imARM_BLB:
{
if (!BL_SendCMDKeepAlive()) { // SetStateDisconnected() included
ACK_OUT = ACK_D_GENERAL_ERROR;
@ -526,9 +543,9 @@ void esc4wayProcess(serialPort_t *mspPort)
case cmd_InterfaceSetMode:
{
#if defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) && defined(USE_SERIAL_4WAY_SK_BOOTLOADER)
if ((ParamBuf[0] <= imSK) && (ParamBuf[0] >= imSIL_BLB)) {
if ((ParamBuf[0] <= imARM_BLB) && (ParamBuf[0] >= imSIL_BLB)) {
#elif defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER)
if ((ParamBuf[0] <= imATM_BLB) && (ParamBuf[0] >= imSIL_BLB)) {
if (((ParamBuf[0] <= imATM_BLB)||(ParamBuf[0] == imARM_BLB)) && (ParamBuf[0] >= imSIL_BLB)) {
#elif defined(USE_SERIAL_4WAY_SK_BOOTLOADER)
if (ParamBuf[0] == imSK) {
#endif
@ -554,6 +571,7 @@ void esc4wayProcess(serialPort_t *mspPort)
case imSIL_BLB:
#ifdef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
case imATM_BLB:
case imARM_BLB:
{
BL_SendCMDRunRestartBootloader(&DeviceInfo);
break;
@ -614,10 +632,16 @@ void esc4wayProcess(serialPort_t *mspPort)
switch (CurrentInterfaceMode)
{
case imSIL_BLB:
case imARM_BLB:
{
Dummy.bytes[0] = ParamBuf[0];
if (CurrentInterfaceMode == imARM_BLB) {
// Address =Page * 1024
ioMem.D_FLASH_ADDR_H = (Dummy.bytes[0] << 2);
} else {
// Address =Page * 512
ioMem.D_FLASH_ADDR_H = (Dummy.bytes[0] << 1);
}
ioMem.D_FLASH_ADDR_L = 0;
if (!BL_PageErase(&ioMem)) ACK_OUT = ACK_D_GENERAL_ERROR;
break;
@ -643,6 +667,7 @@ void esc4wayProcess(serialPort_t *mspPort)
#ifdef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
case imSIL_BLB:
case imATM_BLB:
case imARM_BLB:
{
if(!BL_ReadFlash(CurrentInterfaceMode, &ioMem))
{
@ -727,6 +752,7 @@ void esc4wayProcess(serialPort_t *mspPort)
#ifdef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
case imSIL_BLB:
case imATM_BLB:
case imARM_BLB:
{
if (!BL_WriteFlash(&ioMem)) {
ACK_OUT = ACK_D_GENERAL_ERROR;
@ -787,6 +813,44 @@ void esc4wayProcess(serialPort_t *mspPort)
}
break;
}
//*** Device Memory Verify Ops ***
#ifdef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
case cmd_DeviceVerify:
{
switch (CurrentInterfaceMode)
{
case imARM_BLB:
{
ioMem.D_NUM_BYTES = I_PARAM_LEN;
/*
wtf.D_FLASH_ADDR_H=Adress_H;
wtf.D_FLASH_ADDR_L=Adress_L;
wtf.D_PTR_I = BUF_I;
*/
ACK_OUT = BL_VerifyFlash(&ioMem);
switch (ACK_OUT) {
case brSUCCESS:
ACK_OUT = ACK_OK;
break;
case brERRORVERIFY:
ACK_OUT = ACK_I_VERIFY_ERROR;
break;
default:
ACK_OUT = ACK_D_GENERAL_ERROR;
break;
}
break;
}
default:
{
ACK_OUT = ACK_I_INVALID_CMD;
break;
}
}
break;
}
#endif
default:
{
ACK_OUT = ACK_I_INVALID_CMD;

View File

@ -27,6 +27,7 @@
#define imSIL_BLB 1
#define imATM_BLB 2
#define imSK 3
#define imARM_BLB 4
extern uint8_t selected_esc;

View File

@ -48,6 +48,7 @@
#define CMD_ERASE_FLASH 0x02
#define CMD_READ_FLASH_SIL 0x03
#define CMD_VERIFY_FLASH 0x03
#define CMD_VERIFY_FLASH_ARM 0x04
#define CMD_READ_EEPROM 0x04
#define CMD_PROG_EEPROM 0x05
#define CMD_READ_SRAM 0x06
@ -59,14 +60,6 @@
#define CMD_BOOTINIT 0x07
#define CMD_BOOTSIGN 0x08
// Bootloader result codes
#define brSUCCESS 0x30
#define brERRORCOMMAND 0xC1
#define brERRORCRC 0xC2
#define brNONE 0xFF
#define START_BIT_TIMEOUT_MS 2
#define BIT_TIME (52) // 52uS
@ -318,7 +311,7 @@ uint8_t BL_PageErase(ioMem_t *pMem)
if (BL_SendCMDSetAddress(pMem)) {
uint8_t sCMD[] = {CMD_ERASE_FLASH, 0x01};
BL_SendBuf(sCMD, 2);
return (BL_GetACK((40 / START_BIT_TIMEOUT_MS)) == brSUCCESS);
return (BL_GetACK((1000 / START_BIT_TIMEOUT_MS)) == brSUCCESS);
}
return 0;
}
@ -333,6 +326,17 @@ uint8_t BL_WriteFlash(ioMem_t *pMem)
return BL_WriteA(CMD_PROG_FLASH, pMem, (40 / START_BIT_TIMEOUT_MS));
}
uint8_t BL_VerifyFlash(ioMem_t *pMem)
{
if (BL_SendCMDSetAddress(pMem)) {
if (!BL_SendCMDSetBuffer(pMem)) return 0;
uint8_t sCMD[] = {CMD_VERIFY_FLASH_ARM, 0x01};
BL_SendBuf(sCMD, 2);
return (BL_GetACK(40 / START_BIT_TIMEOUT_MS));
}
return 0;
}
#endif
#if defined(USE_SERIAL_4WAY_BLHELI_BOOTLOADER) && defined(USE_FAKE_ESC)

View File

@ -19,6 +19,12 @@
*/
#pragma once
// Bootloader result codes
#define brSUCCESS 0x30
#define brERRORVERIFY 0xC0
#define brERRORCOMMAND 0xC1
#define brERRORCRC 0xC2
#define brNONE 0xFF
void BL_SendBootInit(void);
uint8_t BL_ConnectEx(uint8_32_u *pDeviceInfo);
@ -28,4 +34,5 @@ uint8_t BL_ReadEEprom(ioMem_t *pMem);
uint8_t BL_WriteEEprom(ioMem_t *pMem);
uint8_t BL_WriteFlash(ioMem_t *pMem);
uint8_t BL_ReadFlash(uint8_t interface_mode, ioMem_t *pMem);
uint8_t BL_VerifyFlash(ioMem_t *pMem);
void BL_SendCMDRunRestartBootloader(uint8_32_u *pDeviceInfo);