fix(pa01): SD storage hangs after copy a large file (#6783)
Co-authored-by: 3djc <3djc@gh.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
bool boardBLStartCondition()
|
bool boardBLStartCondition()
|
||||||
{
|
{
|
||||||
// Trims combo activated
|
// Trims combo activated
|
||||||
|
pollKeys();
|
||||||
bool result = (readTrims() == BOOTLOADER_KEYS);
|
bool result = (readTrims() == BOOTLOADER_KEYS);
|
||||||
#if defined(SECONDARY_BOOTLOADER_KEYS)
|
#if defined(SECONDARY_BOOTLOADER_KEYS)
|
||||||
result |= (readTrims() == SECONDARY_BOOTLOADER_KEYS);
|
result |= (readTrims() == SECONDARY_BOOTLOADER_KEYS);
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ __weak void keysInit()
|
|||||||
_init_trims();
|
_init_trims();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__weak void pollKeys()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
__weak uint32_t readKeys()
|
__weak uint32_t readKeys()
|
||||||
{
|
{
|
||||||
return _read_keys();
|
return _read_keys();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
|
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
|
||||||
|
extern bool suspendI2CTasks;
|
||||||
|
|
||||||
struct bsp_io_expander {
|
struct bsp_io_expander {
|
||||||
pca95xx_t exp;
|
pca95xx_t exp;
|
||||||
@@ -108,6 +109,9 @@ static void _poll_switches(void *param1, uint32_t trigger_source)
|
|||||||
timer_reset(&_poll_timer);
|
timer_reset(&_poll_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suspend hardware reads when required
|
||||||
|
if (suspendI2CTasks) return;
|
||||||
|
|
||||||
_read_io_expander(&_io_switches);
|
_read_io_expander(&_io_switches);
|
||||||
_read_io_expander(&_io_fs_switches);
|
_read_io_expander(&_io_fs_switches);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
|
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool suspendI2CTasks = false;
|
||||||
|
|
||||||
void pollInputs()
|
void pollInputs()
|
||||||
{
|
{
|
||||||
keysPollingCycle();
|
keysPollingCycle();
|
||||||
@@ -109,6 +111,7 @@ void bootloaderMenu()
|
|||||||
if (usbPlugged()) {
|
if (usbPlugged()) {
|
||||||
state = ST_USB;
|
state = ST_USB;
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
|
suspendI2CTasks = true;
|
||||||
usbStart();
|
usbStart();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -119,6 +122,7 @@ void bootloaderMenu()
|
|||||||
vpos = 0;
|
vpos = 0;
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
usbStop();
|
usbStop();
|
||||||
|
suspendI2CTasks = false;
|
||||||
#endif
|
#endif
|
||||||
state = ST_START;
|
state = ST_START;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#define FRAME_INTERVAL_MS 20
|
#define FRAME_INTERVAL_MS 20
|
||||||
|
|
||||||
|
bool suspendI2CTasks = false;
|
||||||
|
|
||||||
void bootloaderUF2()
|
void bootloaderUF2()
|
||||||
{
|
{
|
||||||
BootloaderState state = ST_START;
|
BootloaderState state = ST_START;
|
||||||
@@ -71,6 +73,7 @@ void bootloaderUF2()
|
|||||||
if (usbPlugged()) {
|
if (usbPlugged()) {
|
||||||
state = ST_USB;
|
state = ST_USB;
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
|
suspendI2CTasks = true;
|
||||||
usbStart();
|
usbStart();
|
||||||
#endif
|
#endif
|
||||||
} else if (pwrOffPressed()) {
|
} else if (pwrOffPressed()) {
|
||||||
@@ -83,6 +86,8 @@ void bootloaderUF2()
|
|||||||
if (usbPlugged() == 0) {
|
if (usbPlugged() == 0) {
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
usbStop();
|
usbStop();
|
||||||
|
suspendI2CTasks = false;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
state = (state == ST_FLASH_DONE) ? ST_REBOOT : ST_START;
|
state = (state == ST_FLASH_DONE) ? ST_REBOOT : ST_START;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ uint8_t latencyToggleSwitch = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile uint8_t rtc_count = 0;
|
volatile uint8_t rtc_count = 0;
|
||||||
|
bool suspendI2CTasks = false;
|
||||||
|
|
||||||
#if defined(DEBUG_LATENCY)
|
#if defined(DEBUG_LATENCY)
|
||||||
void toggleLatencySwitch()
|
void toggleLatencySwitch()
|
||||||
@@ -1089,6 +1090,7 @@ void edgeTxClose(uint8_t shutdown)
|
|||||||
TRACE("edgeTxClose");
|
TRACE("edgeTxClose");
|
||||||
|
|
||||||
watchdogSuspend(2000/*20s*/);
|
watchdogSuspend(2000/*20s*/);
|
||||||
|
suspendI2CTasks = true;
|
||||||
|
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
pulsesStop();
|
pulsesStop();
|
||||||
@@ -1140,6 +1142,7 @@ void edgeTxResume()
|
|||||||
{
|
{
|
||||||
TRACE("edgeTxResume");
|
TRACE("edgeTxResume");
|
||||||
|
|
||||||
|
suspendI2CTasks = false;
|
||||||
if (!sdMounted()) sdInit();
|
if (!sdMounted()) sdInit();
|
||||||
|
|
||||||
luaInitMainState();
|
luaInitMainState();
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ enum EnumKeys {
|
|||||||
MAX_KEYS
|
MAX_KEYS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// When port entender is used, readKeys should only return the cached key values
|
||||||
|
// read key from port extender will only come from pollKeys
|
||||||
|
// Which is called by the timer task
|
||||||
|
void pollKeys();
|
||||||
|
|
||||||
// returns a bit field with each key set as (1 << KEY_xxx)
|
// returns a bit field with each key set as (1 << KEY_xxx)
|
||||||
uint32_t readKeys();
|
uint32_t readKeys();
|
||||||
|
|
||||||
|
|||||||
@@ -476,6 +476,7 @@ uint16_t keyMapping(uint16_t event)
|
|||||||
bool keysPollingCycle()
|
bool keysPollingCycle()
|
||||||
{
|
{
|
||||||
uint32_t trims_input;
|
uint32_t trims_input;
|
||||||
|
pollKeys();
|
||||||
uint32_t keys_input = readKeys();
|
uint32_t keys_input = readKeys();
|
||||||
|
|
||||||
#if defined(USE_HATS_AS_KEYS)
|
#if defined(USE_HATS_AS_KEYS)
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ typedef struct {
|
|||||||
} CSD_ALERT;
|
} CSD_ALERT;
|
||||||
/*CSD ALERT Configuration struct*/
|
/*CSD ALERT Configuration struct*/
|
||||||
|
|
||||||
|
extern bool suspendI2CTasks;
|
||||||
|
|
||||||
void CSD203_Init(CSD_CONFIG *CSD203_CFG); // Initialise CSD203 config
|
void CSD203_Init(CSD_CONFIG *CSD203_CFG); // Initialise CSD203 config
|
||||||
uint16_t CSD203_ReadVbus(CSD_CONFIG *CSD203_CFG); // Read Vbus Voltage
|
uint16_t CSD203_ReadVbus(CSD_CONFIG *CSD203_CFG); // Read Vbus Voltage
|
||||||
uint16_t CSD203_ReadRshunt(CSD_CONFIG *CSD203_CFG); // Read Rshunt
|
uint16_t CSD203_ReadRshunt(CSD_CONFIG *CSD203_CFG); // Read Rshunt
|
||||||
@@ -410,6 +412,8 @@ void readCSD203(void)
|
|||||||
{ // 5ms
|
{ // 5ms
|
||||||
static uint16_t GetSenSorStep = 0;
|
static uint16_t GetSenSorStep = 0;
|
||||||
|
|
||||||
|
if (suspendI2CTasks) return;
|
||||||
|
|
||||||
if (IICReadStatusFlag == true) return;
|
if (IICReadStatusFlag == true) return;
|
||||||
|
|
||||||
IICReadStatusFlag = true;
|
IICReadStatusFlag = true;
|
||||||
|
|||||||
@@ -56,10 +56,14 @@ bool bsp_get_shouldReadKeys()
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static volatile bool errorOccurs = false;
|
||||||
static void bsp_input_read()
|
static void bsp_input_read()
|
||||||
{
|
{
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
if (aw9523b_read(&i2c_exp, BSP_IN_MASK, &value) < 0) return;
|
if (aw9523b_read(&i2c_exp, BSP_IN_MASK, &value) < 0) {
|
||||||
|
errorOccurs = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
inputState = value;
|
inputState = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,13 +68,15 @@ enum PhysicalKeys
|
|||||||
ENT = 16
|
ENT = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern bool suspendI2CTasks;
|
||||||
|
|
||||||
static bool fct_state[4] = {false, false, false, false};
|
static bool fct_state[4] = {false, false, false, false};
|
||||||
static uint32_t keyState = 0;
|
static uint32_t keyState = 0;
|
||||||
#if !defined(BOOT)
|
#if !defined(BOOT)
|
||||||
static uint32_t nonReadCount = 0;
|
static uint32_t nonReadCount = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint32_t _readKeyMatrix()
|
void pollKeys()
|
||||||
{
|
{
|
||||||
#if !defined(BOOT)
|
#if !defined(BOOT)
|
||||||
if(!bsp_get_shouldReadKeys() && nonReadCount < 10)
|
if(!bsp_get_shouldReadKeys() && nonReadCount < 10)
|
||||||
@@ -83,10 +85,12 @@ static uint32_t _readKeyMatrix()
|
|||||||
keyState |= 1<<ENT;
|
keyState |= 1<<ENT;
|
||||||
|
|
||||||
nonReadCount++;
|
nonReadCount++;
|
||||||
return keyState;
|
|
||||||
}
|
}
|
||||||
nonReadCount = 0;
|
nonReadCount = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (suspendI2CTasks) return;
|
||||||
|
|
||||||
// This function avoids concurrent matrix agitation
|
// This function avoids concurrent matrix agitation
|
||||||
|
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
@@ -98,13 +102,17 @@ static uint32_t _readKeyMatrix()
|
|||||||
uint8_t ui8ReadInProgress = 0;
|
uint8_t ui8ReadInProgress = 0;
|
||||||
} syncelem;
|
} syncelem;
|
||||||
|
|
||||||
if (syncelem.ui8ReadInProgress != 0) return syncelem.oldResult;
|
if (syncelem.ui8ReadInProgress != 0) {
|
||||||
|
keyState = syncelem.oldResult;
|
||||||
|
}
|
||||||
|
|
||||||
// ui8ReadInProgress was 0, increment it
|
// ui8ReadInProgress was 0, increment it
|
||||||
syncelem.ui8ReadInProgress++;
|
syncelem.ui8ReadInProgress++;
|
||||||
// Double check before continuing, as non-atomic, non-blocking so far
|
// Double check before continuing, as non-atomic, non-blocking so far
|
||||||
// If ui8ReadInProgress is above 1, then there was concurrent task calling it, exit
|
// If ui8ReadInProgress is above 1, then there was concurrent task calling it, exit
|
||||||
if (syncelem.ui8ReadInProgress > 1) return syncelem.oldResult;
|
if (syncelem.ui8ReadInProgress > 1) {
|
||||||
|
keyState = syncelem.oldResult;
|
||||||
|
}
|
||||||
|
|
||||||
// If we land here, we have exclusive access to Matrix
|
// If we land here, we have exclusive access to Matrix
|
||||||
bsp_output_set(BSP_KEY_OUT_MASK, ~BSP_KEY_OUT1);
|
bsp_output_set(BSP_KEY_OUT_MASK, ~BSP_KEY_OUT1);
|
||||||
@@ -170,8 +178,6 @@ static uint32_t _readKeyMatrix()
|
|||||||
fct_state[3] = (result & 1<<KEY4)?true:false;
|
fct_state[3] = (result & 1<<KEY4)?true:false;
|
||||||
|
|
||||||
keyState = result;
|
keyState = result;
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void keysInit()
|
void keysInit()
|
||||||
@@ -183,7 +189,7 @@ uint32_t readKeys()
|
|||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
uint32_t mkeys = _readKeyMatrix();
|
uint32_t mkeys = keyState;
|
||||||
if (mkeys & (1 << PGUP)) result |= 1 << KEY_PAGEUP;
|
if (mkeys & (1 << PGUP)) result |= 1 << KEY_PAGEUP;
|
||||||
if (mkeys & (1 << PGDN)) result |= 1 << KEY_PAGEDN;
|
if (mkeys & (1 << PGDN)) result |= 1 << KEY_PAGEDN;
|
||||||
if (mkeys & (1 << RTN)) result |= 1 << KEY_EXIT;
|
if (mkeys & (1 << RTN)) result |= 1 << KEY_EXIT;
|
||||||
@@ -195,7 +201,7 @@ uint32_t readKeys()
|
|||||||
|
|
||||||
uint32_t readTrims()
|
uint32_t readTrims()
|
||||||
{
|
{
|
||||||
uint32_t mkeys = _readKeyMatrix();
|
uint32_t mkeys = keyState;
|
||||||
|
|
||||||
return mkeys & 0xff; // Mask only the trims output
|
return mkeys & 0xff; // Mask only the trims output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ bool getHatsAsKeys()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void pollKeys()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t readKeys()
|
uint32_t readKeys()
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|||||||
@@ -58,9 +58,14 @@ enum PhysicalTrims {
|
|||||||
TR4R
|
TR4R
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern bool suspendI2CTasks;
|
||||||
|
|
||||||
uint32_t readTrims()
|
uint32_t readTrims()
|
||||||
{
|
{
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
|
if (suspendI2CTasks) return result;
|
||||||
|
|
||||||
uint16_t keys = bsp_input_get();
|
uint16_t keys = bsp_input_get();
|
||||||
|
|
||||||
#define _TRIM(t) \
|
#define _TRIM(t) \
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#define IO_RESET_GPIO GPIO_PIN(GPIOE, 15)
|
#define IO_RESET_GPIO GPIO_PIN(GPIOE, 15)
|
||||||
|
|
||||||
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
|
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
|
||||||
|
extern bool suspendI2CTasks;
|
||||||
|
|
||||||
struct bsp_io_expander {
|
struct bsp_io_expander {
|
||||||
pca95xx_t exp;
|
pca95xx_t exp;
|
||||||
@@ -84,6 +85,9 @@ static void _poll_switches(void *param1, uint32_t trigger_source)
|
|||||||
timer_reset(&_poll_timer);
|
timer_reset(&_poll_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suspend hardware reads when required
|
||||||
|
if (suspendI2CTasks) return;
|
||||||
|
|
||||||
_read_io_expander(&_io_switches);
|
_read_io_expander(&_io_switches);
|
||||||
_read_io_expander(&_io_fs_switches);
|
_read_io_expander(&_io_fs_switches);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user