Browse Source

integrated tommie's eeprom sanity check. much less chances of new firmware screwing up due to old config version.

fixed pwm init for airplane mode mistakenly deleting motors from the mix. flyingwing should really work now.
removed led debug from althold


git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@223 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
master
timecop@gmail.com 12 years ago
parent
commit
1dea2b3b3b
  1. 5776
      obj/baseflight.hex
  2. 63
      src/config.c
  3. 6
      src/drv_pwm.c
  4. 1
      src/imu.c
  5. 2
      src/main.c
  6. 4
      src/mw.h
  7. 2
      src/serial.c

5776
obj/baseflight.hex
File diff suppressed because it is too large
View File

63
src/config.c

@ -12,8 +12,9 @@
config_t cfg;
const char rcChannelLetters[] = "AERT1234";
static uint8_t EEPROM_CONF_VERSION = 32;
static uint32_t enabledSensors = 0;
uint8_t checkNewConf = 31;
static void resetConf(void);
void parseRcChannels(const char *input)
{
@ -26,6 +27,32 @@ void parseRcChannels(const char *input)
}
}
static uint8_t validEEPROM(void)
{
const config_t *temp = (const config_t *)FLASH_WRITE_ADDR;
const uint8_t *p;
uint8_t chk = 0;
// check version number
if (EEPROM_CONF_VERSION != temp->version)
return 0;
// check size and magic numbers
if (temp->size != sizeof(config_t) || temp->magic_be != 0xBE || temp->magic_ef != 0xEF)
return 0;
// verify integrity of temporary copy
for (p = (const uint8_t *)temp; p < ((const uint8_t *)temp + sizeof(config_t)); p++)
chk ^= *p;
// checksum failed
if (chk != 0)
return 0;
// looks good, let's roll!
return 1;
}
void readEEPROM(void)
{
uint8_t i;
@ -54,9 +81,21 @@ void writeParams(uint8_t b)
{
FLASH_Status status;
uint32_t i;
uint8_t chk = 0;
const uint8_t *p;
cfg.version = EEPROM_CONF_VERSION;
cfg.size = sizeof(config_t);
cfg.magic_be = 0xBE;
cfg.magic_ef = 0xEF;
cfg.chk = 0;
// recalculate checksum before writing
for (p = (const uint8_t *)&cfg; p < ((const uint8_t *)&cfg + sizeof(config_t)); p++)
chk ^= *p;
cfg.chk = chk;
// write it
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE) {
@ -66,7 +105,6 @@ void writeParams(uint8_t b)
break; // TODO: fail
}
}
FLASH_Lock();
readEEPROM();
@ -76,15 +114,18 @@ void writeParams(uint8_t b)
void checkFirstTime(bool reset)
{
uint8_t test_val, i;
test_val = *(uint8_t *) FLASH_WRITE_ADDR;
// check the EEPROM integrity before resetting values
if (!validEEPROM() || reset)
resetConf();
}
if (!reset && test_val == checkNewConf)
return;
// Default settings
static void resetConf(void)
{
int i;
memset(&cfg, 0, sizeof(config_t));
// Default settings
cfg.version = checkNewConf;
cfg.version = EEPROM_CONF_VERSION;
cfg.mixerConfiguration = MULTITYPE_QUADX;
featureClearAll();
featureSet(FEATURE_VBAT);

6
src/drv_pwm.c

@ -485,13 +485,13 @@ bool pwmInit(drv_pwm_config_t *init)
if (mask & (TYPE_IP | TYPE_IW) && !init->enableInput)
mask = 0;
if (init->useServos) {
// remap PWM9+10 as servos
if (init->useServos && !init->airplane) {
// remap PWM9+10 as servos (but not in airplane mode LOL)
if (port == PWM9 || port == PWM10)
mask = TYPE_S;
}
if (init->extraServos) {
if (init->extraServos && !init->airplane) {
// remap PWM5..8 as servos when used in extended servo mode
if (port >= PWM5 && port <= PWM8)
mask = TYPE_S;

1
src/imu.c

@ -319,7 +319,6 @@ void getEstimatedAltitude(void)
return;
dTime = currentTime - deadLine;
deadLine = currentTime;
LED0_TOGGLE;
// **** Alt. Set Point stabilization PID ****
baroHistTab[baroHistIdx] = BaroAlt / 10;

2
src/main.c

@ -43,8 +43,8 @@ int main(void)
systemInit();
init_printf(NULL, _putc);
readEEPROM();
checkFirstTime(false);
readEEPROM();
serialInit(cfg.serial_baudrate);

4
src/mw.h

@ -115,6 +115,8 @@ typedef struct mixer_t {
typedef struct config_t {
uint8_t version;
uint16_t size;
uint8_t magic_be; // magic number, should be 0xBE
uint8_t mixerConfiguration;
uint32_t enabledFeatures;
@ -224,6 +226,8 @@ typedef struct config_t {
uint32_t serial_baudrate;
motorMixer_t customMixer[MAX_MOTORS]; // custom mixtable
uint8_t magic_ef; // magic number, should be 0xEF
uint8_t chk; // XOR checksum
} config_t;
typedef struct flags_t {

2
src/serial.c

@ -38,7 +38,7 @@
#define MSP_EEPROM_WRITE 250 //in message no param
#define MSP_DEBUGMSG 253 //out message debug string buffer
#define MSP_DEBUGMSG 253 //out message debug string buffer
#define MSP_DEBUG 254 //out message debug1,debug2,debug3,debug4
#define INBUF_SIZE 64

Loading…
Cancel
Save