From 4c14e4f5f1c67ae0d139e4998058991a02fe4912 Mon Sep 17 00:00:00 2001 From: px4dev Date: Sat, 6 Oct 2012 16:08:07 -0700 Subject: Add a 'secret' subcommand to bl_update that manipulates the option bits to change the brown-out detector configuration. This is an experiment to see if we can improve the boot-time behavior when powered off noisy supplies. --- apps/systemcmds/bl_update/bl_update.c | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'apps/systemcmds') 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 -- cgit v1.2.3