stmhal: Factor out USRSW boot-up code and support boards with 1 LED.

Thanks to Dave Hylands for the patch.
This commit is contained in:
Damien George 2015-08-02 23:51:46 +01:00
parent 1934dca6de
commit 6f1c00869c
1 changed files with 87 additions and 32 deletions

View File

@ -244,6 +244,81 @@ void init_flash_fs(uint reset_mode) {
}
}
STATIC uint update_reset_mode(uint reset_mode) {
#if MICROPY_HW_HAS_SWITCH
if (switch_get()) {
// The original method used on the pyboard is appropriate if you have 2
// or more LEDs.
#if defined(MICROPY_HW_LED2)
for (uint i = 0; i < 3000; i++) {
if (!switch_get()) {
break;
}
HAL_Delay(20);
if (i % 30 == 29) {
if (++reset_mode > 3) {
reset_mode = 1;
}
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
}
}
// flash the selected reset mode
for (uint i = 0; i < 6; i++) {
led_state(2, 0);
led_state(3, 0);
led_state(4, 0);
HAL_Delay(50);
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
HAL_Delay(50);
}
HAL_Delay(400);
#elif defined(MICROPY_HW_LED1)
// For boards with only a single LED, we'll flash that LED the
// appropriate number of times, with a pause between each one
for (uint i = 0; i < 10; i++) {
led_state(1, 0);
for (uint j = 0; j < reset_mode; j++) {
if (!switch_get()) {
break;
}
led_state(1, 1);
HAL_Delay(100);
led_state(1, 0);
HAL_Delay(200);
}
HAL_Delay(400);
if (!switch_get()) {
break;
}
if (++reset_mode > 3) {
reset_mode = 1;
}
}
// Flash the selected reset mode
for (uint i = 0; i < 2; i++) {
for (uint j = 0; j < reset_mode; j++) {
led_state(1, 1);
HAL_Delay(100);
led_state(1, 0);
HAL_Delay(200);
}
HAL_Delay(400);
}
#else
#error Need a reset mode update method
#endif
}
#endif
return reset_mode;
}
int main(void) {
// TODO disable JTAG
@ -324,42 +399,16 @@ int main(void) {
soft_reset:
// check if user switch held to select the reset mode
#if defined(MICROPY_HW_LED2)
led_state(1, 0);
led_state(2, 1);
#else
led_state(1, 1);
led_state(2, 0);
#endif
led_state(3, 0);
led_state(4, 0);
uint reset_mode = 1;
#if MICROPY_HW_HAS_SWITCH
if (switch_get()) {
for (uint i = 0; i < 3000; i++) {
if (!switch_get()) {
break;
}
HAL_Delay(20);
if (i % 30 == 29) {
if (++reset_mode > 3) {
reset_mode = 1;
}
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
}
}
// flash the selected reset mode
for (uint i = 0; i < 6; i++) {
led_state(2, 0);
led_state(3, 0);
led_state(4, 0);
HAL_Delay(50);
led_state(2, reset_mode & 1);
led_state(3, reset_mode & 2);
led_state(4, reset_mode & 4);
HAL_Delay(50);
}
HAL_Delay(400);
}
#endif
uint reset_mode = update_reset_mode(1);
#if MICROPY_HW_ENABLE_RTC
if (first_soft_reset) {
@ -482,6 +531,12 @@ soft_reset:
}
// turn boot-up LEDs off
#if !defined(MICROPY_HW_LED2)
// If there is only one LED on the board then it's used to signal boot-up
// and so we turn it off here. Otherwise LED(1) is used to indicate dirty
// flash cache and so we shouldn't change its state.
led_state(1, 0);
#endif
led_state(2, 0);
led_state(3, 0);
led_state(4, 0);