aboutsummaryrefslogtreecommitdiff
path: root/apps/systemcmds
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2012-10-06 16:08:07 -0700
committerpx4dev <px4@purgatory.org>2012-10-06 16:08:07 -0700
commit4c14e4f5f1c67ae0d139e4998058991a02fe4912 (patch)
tree655c85b81e17cbc339ceff939488d7cf07f2117a /apps/systemcmds
parent2fa0dec36954b0f3c99da0a443a9c51a7a0479c5 (diff)
downloadpx4-firmware-4c14e4f5f1c67ae0d139e4998058991a02fe4912.tar.gz
px4-firmware-4c14e4f5f1c67ae0d139e4998058991a02fe4912.tar.bz2
px4-firmware-4c14e4f5f1c67ae0d139e4998058991a02fe4912.zip
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.
Diffstat (limited to 'apps/systemcmds')
-rw-r--r--apps/systemcmds/bl_update/bl_update.c37
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