aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/util.c
diff options
context:
space:
mode:
authorPerry Hung <iperry@gmail.com>2010-09-17 03:49:14 -0400
committerPerry Hung <iperry@gmail.com>2010-09-17 03:49:14 -0400
commit2e79aafb7081a5305ee875277d26734779ca6d2f (patch)
tree9ae02b8733ecd75f9e783a81cd7d46fa7e505b9a /libmaple/util.c
parentbdb85a454917a6e875c77ae12f9fd67961aebfae (diff)
downloadlibrambutan-2e79aafb7081a5305ee875277d26734779ca6d2f.tar.gz
librambutan-2e79aafb7081a5305ee875277d26734779ca6d2f.zip
Enable USB auto-reset in a hard fault.
Redirect thread-mode execution to a fail routine which throbs the LED to indicate a hard fault. Because the fail routine runs in thread mode with interrupts on, USB auto-reset should now work. Test by executing some bogus instruction (e.g. *(volatile int*)0xf34fdaa = 0;) and check that the auto-reset continues to work.
Diffstat (limited to 'libmaple/util.c')
-rw-r--r--libmaple/util.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/libmaple/util.c b/libmaple/util.c
index a747948..3325d2b 100644
--- a/libmaple/util.c
+++ b/libmaple/util.c
@@ -68,7 +68,7 @@ void _fail(const char* file, int line, const char* exp) {
usart_putudec(ERROR_USART_NUM, line);
usart_putc(ERROR_USART_NUM, '\n');
usart_putc(ERROR_USART_NUM, '\r');
-
+
/* Turn on the error LED */
gpio_set_mode(ERROR_LED_PORT, ERROR_LED_PIN, GPIO_MODE_OUTPUT_PP);
@@ -77,24 +77,35 @@ void _fail(const char* file, int line, const char* exp) {
nvic_irq_enable(NVIC_INT_USBLP);
/* Error fade */
- while (1) {
- if (CC == TOP_CNT) {
- slope = -1;
- } else if (CC == 0) {
- slope = 1;
- }
-
- if (i == TOP_CNT) {
- CC += slope;
- i = 0;
- }
-
- if (i < CC) {
- gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 1);
- } else {
- gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 0);
- }
- i++;
- }
+ throb();
+}
+
+void throb(void) {
+ int32 slope = 1;
+ uint32 CC = 0x0000;
+ uint32 TOP_CNT = 0x0200;
+ uint32 i = 0;
+
+ gpio_set_mode(ERROR_LED_PORT, ERROR_LED_PIN, GPIO_MODE_OUTPUT_PP);
+ /* Error fade */
+ while (1) {
+ if (CC == TOP_CNT) {
+ slope = -1;
+ } else if (CC == 0) {
+ slope = 1;
+ }
+
+ if (i == TOP_CNT) {
+ CC += slope;
+ i = 0;
+ }
+
+ if (i < CC) {
+ gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 1);
+ } else {
+ gpio_write_bit(ERROR_LED_PORT, ERROR_LED_PIN, 0);
+ }
+ i++;
+ }
}