Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 0beba95

Browse files
committed
Merge pull request #208 from cw2/issue-174-stm32f4disco-bootloader-button
User button can enter bootloader during startup (STM32F4DISCOVERY)
2 parents 44ece91 + 71760c2 commit 0beba95

File tree

3 files changed

+21
-46
lines changed

3 files changed

+21
-46
lines changed

Solutions/STM32F4DISCOVERY/TinyBooter/TinyBooter.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@
115115
<RequiredProjects Include="$(SPOCLIENT)\DeviceCode\PAL\BlockStorage\dotNetMF.proj" />
116116
</ItemGroup>
117117
<ItemGroup>
118-
<DriverLibs Include="Buttons_pal.$(LIB_EXT)" />
119-
<RequiredProjects Include="$(SPOCLIENT)\DeviceCode\PAL\Buttons\dotNetMF.proj" />
118+
<DriverLibs Include="Buttons_pal_stubs.$(LIB_EXT)" />
119+
<RequiredProjects Include="$(SPOCLIENT)\DeviceCode\PAL\Buttons\stubs\dotNetMF.proj" />
120120
</ItemGroup>
121121
<ItemGroup>
122122
<DriverLibs Include="COM_pal.$(LIB_EXT)" />

Solutions/STM32F4DISCOVERY/TinyBooter/TinyBooterEntry.cpp

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include <tinyhal.h>
1515
#include <TinyBooterEntry.h>
1616

17-
#define BUTTON_ENTR BUTTON_B4
18-
#define BUTTON_USER_IDX BUTTON_B5_BITIDX
19-
2017
// boot loader doesn't use the CMSIS-RTOS kernel, so sleep goes direct
2118
// to the low level support
2219
extern void HAL_CPU_Sleep( SLEEP_LEVEL level, UINT64 wakeEvents );
@@ -90,24 +87,24 @@ void Tinybooter_PrepareForDecompressedLaunch()
9087
bool WaitForTinyBooterUpload( INT32 &timeout_ms )
9188
{
9289
bool enterBooterMode = false;
93-
GPIO_BUTTON_CONFIG * ButtonConfig = &g_GPIO_BUTTON_Config;
9490

95-
// wait forever when using RAM build
9691
#if defined(TARGETLOCATION_RAM)
92+
// Wait forever when using RAM build
9793
enterBooterMode = true;
9894
timeout_ms = -1;
99-
#else
100-
//// User override (button held)
101-
//if(ButtonConfig->Mapping[BUTTON_USER_IDX].m_HW != GPIO_PIN_NONE)
102-
//{
103-
// Events_WaitForEvents(0,100); // wait for buttons to init
104-
// if(CPU_GPIO_GetPinState(ButtonConfig->Mapping[BUTTON_USER_IDX].m_HW))
105-
// {
106-
// // user override, so lets stay forever
107-
// timeout_ms = -1;
108-
// enterBooterMode = true;
109-
// }
110-
//}
95+
#elif defined(TINYBOOTER_ENTRY_GPIO_PIN)
96+
97+
if(!CPU_GPIO_EnableInputPin(TINYBOOTER_ENTRY_GPIO_PIN, FALSE, NULL, GPIO_INT_NONE, TINYBOOTER_ENTRY_GPIO_RESISTOR))
98+
{
99+
ASSERT(FALSE);
100+
}
101+
if(CPU_GPIO_GetPinState(TINYBOOTER_ENTRY_GPIO_PIN) == TINYBOOTER_ENTRY_GPIO_STATE)
102+
{
103+
// User override, so let's stay forever
104+
enterBooterMode = true;
105+
timeout_ms = -1;
106+
}
107+
111108
#endif
112109
return enterBooterMode;
113110
}
@@ -139,25 +136,6 @@ void TinyBooter_OnStateChange( TinyBooterState state, void* data, void ** retDat
139136
// The data parameter is a pointer to the timeout value for the booter mode.
140137
////////////////////////////////////////////////////////////////////////////////////
141138
case State_ButtonPress:
142-
if(NULL != data)
143-
{
144-
UINT32 down, up;
145-
INT32* timeout_ms = (INT32*)data;
146-
147-
// wait forever if a button was pressed
148-
*timeout_ms = -1;
149-
150-
// process buttons
151-
while(Buttons_GetNextStateChange(down, up))
152-
{
153-
// leave a way to exit boot mode incase it was accidentally entered
154-
if(0 != (down & BUTTON_ENTR))
155-
{
156-
// force an enumerate and launch
157-
*timeout_ms = 0;
158-
}
159-
}
160-
}
161139
break;
162140

163141
////////////////////////////////////////////////////////////////////////////////////

Solutions/STM32F4DISCOVERY/platform_selector.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,17 @@
120120
#define STM32F4_UART_CTS_PINS {(BYTE)GPIO_PIN_NONE, 51, 59} // GPIO_PIN_NONE, D3, D11
121121
#define STM32F4_UART_RTS_PINS {(BYTE)GPIO_PIN_NONE, 52, 60} // GPIO_PIN_NONE, D4, D12
122122

123-
#define DRIVER_PAL_BUTTON_MAPPING \
124-
{ 0, BUTTON_NONE }, /* Up */ \
125-
{ 0, BUTTON_NONE }, /* Down */ \
126-
{ 0, BUTTON_NONE }, /* Left */ \
127-
{ 0, BUTTON_NONE }, /* Right */ \
128-
{ 0, BUTTON_NONE }, /* Enter */ \
129-
{ PORT_PIN(GPIO_PORTA, 0), BUTTON_B5 }, // User
130-
131123
// User LEDs
132124
#define LED3 PORT_PIN(GPIO_PORTD, 13) // PD.13 (orange)
133125
#define LED4 PORT_PIN(GPIO_PORTD, 12) // PD.12 (green)
134126
#define LED5 PORT_PIN(GPIO_PORTD, 14) // PD.14 (red)
135127
#define LED6 PORT_PIN(GPIO_PORTD, 15) // PD.15 (blue)
136128

129+
// TinyBooter entry using GPIO
130+
#define TINYBOOTER_ENTRY_GPIO_PIN PORT_PIN(GPIO_PORTA, 0) // 'User' button
131+
#define TINYBOOTER_ENTRY_GPIO_STATE TRUE // Active high
132+
#define TINYBOOTER_ENTRY_GPIO_RESISTOR RESISTOR_DISABLED // No internal resistor, there is external pull-down (R39)
133+
137134
//
138135
// constants
139136
/////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)