diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2012-10-08 18:00:00 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2012-10-08 18:00:00 +0200 |
commit | 0edd4063af950cc341a6c934e8467adc70951e12 (patch) | |
tree | 9373878d050086790a2dbb7f6c5627b7cb0457e3 | |
parent | dd50c88f073926a550f0f1f5b08f931116dd4f8f (diff) | |
parent | 4c14e4f5f1c67ae0d139e4998058991a02fe4912 (diff) | |
download | px4-firmware-0edd4063af950cc341a6c934e8467adc70951e12.tar.gz px4-firmware-0edd4063af950cc341a6c934e8467adc70951e12.tar.bz2 px4-firmware-0edd4063af950cc341a6c934e8467adc70951e12.zip |
Merge branch 'master' of github.com:PX4/Firmware into tobi
-rw-r--r-- | apps/systemcmds/bl_update/bl_update.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/apps/systemcmds/bl_update/bl_update.c b/apps/systemcmds/bl_update/bl_update.c index 8bfc29234..ac3e93be1 100644 --- a/apps/systemcmds/bl_update/bl_update.c +++ b/apps/systemcmds/bl_update/bl_update.c @@ -56,11 +56,16 @@ __EXPORT int bl_update_main(int argc, char *argv[]); +static void setopt(void); + int bl_update_main(int argc, char *argv[]) { if (argc != 2) - errx(1, "missing firmware filename"); + errx(1, "missing firmware filename or command"); + + if (!strcmp(argv[1], "setopt")) + setopt(); int fd = open(argv[1], O_RDONLY); if (fd < 0) @@ -172,3 +177,33 @@ flash_end: free(buf); exit(0); } + +static void +setopt(void) +{ + volatile uint32_t *optcr = (volatile uint32_t *)0x40023c14; + + const uint16_t opt_mask = (3 << 2); /* BOR_LEV bitmask */ + const uint16_t opt_bits = (0 << 2); /* BOR = 0, setting for 2.7-3.6V operation */ + + if ((*optcr & opt_mask) == opt_bits) + errx(0, "option bits are already set as required"); + + /* unlock the control register */ + volatile uint32_t *optkeyr = (volatile uint32_t *)0x40023c08; + *optkeyr = 0x08192a3bU; + *optkeyr = 0x4c5d6e7fU; + + if (*optcr & 1) + errx(1, "option control register unlock failed"); + + /* program the new option value */ + *optcr = (*optcr & ~opt_mask) | opt_bits | (1 << 1); + + usleep(1000); + + if ((*optcr & opt_mask) == opt_bits) + errx(0, "option bits set"); + errx(1, "option bits setting failed; readback 0x%04x", *optcr); + +}
\ No newline at end of file |