fix(pa01): SD storage hangs after copy a large file (#6783)

Co-authored-by: 3djc <3djc@gh.com>
This commit is contained in:
richardclli
2025-12-05 11:43:51 +10:00
committed by GitHub
co-authored by 3djc
parent 12801409da
commit 86b51fdd23
14 changed files with 63 additions and 9 deletions
@@ -6,6 +6,7 @@
bool boardBLStartCondition()
{
// Trims combo activated
pollKeys();
bool result = (readTrims() == BOOTLOADER_KEYS);
#if defined(SECONDARY_BOOTLOADER_KEYS)
result |= (readTrims() == SECONDARY_BOOTLOADER_KEYS);
@@ -34,6 +34,10 @@ __weak void keysInit()
_init_trims();
}
__weak void pollKeys()
{
}
__weak uint32_t readKeys()
{
return _read_keys();
+4
View File
@@ -38,6 +38,7 @@
#include "debug.h"
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
extern bool suspendI2CTasks;
struct bsp_io_expander {
pca95xx_t exp;
@@ -108,6 +109,9 @@ static void _poll_switches(void *param1, uint32_t trigger_source)
timer_reset(&_poll_timer);
}
// Suspend hardware reads when required
if (suspendI2CTasks) return;
_read_io_expander(&_io_switches);
_read_io_expander(&_io_fs_switches);
}
+4
View File
@@ -41,6 +41,8 @@
#define SEL_CLEAR_FLASH_STORAGE_MENU_LEN 2
#endif
bool suspendI2CTasks = false;
void pollInputs()
{
keysPollingCycle();
@@ -109,6 +111,7 @@ void bootloaderMenu()
if (usbPlugged()) {
state = ST_USB;
#if !defined(SIMU)
suspendI2CTasks = true;
usbStart();
#endif
}
@@ -119,6 +122,7 @@ void bootloaderMenu()
vpos = 0;
#if !defined(SIMU)
usbStop();
suspendI2CTasks = false;
#endif
state = ST_START;
}
+5
View File
@@ -34,6 +34,8 @@
#define FRAME_INTERVAL_MS 20
bool suspendI2CTasks = false;
void bootloaderUF2()
{
BootloaderState state = ST_START;
@@ -71,6 +73,7 @@ void bootloaderUF2()
if (usbPlugged()) {
state = ST_USB;
#if !defined(SIMU)
suspendI2CTasks = true;
usbStart();
#endif
} else if (pwrOffPressed()) {
@@ -83,6 +86,8 @@ void bootloaderUF2()
if (usbPlugged() == 0) {
#if !defined(SIMU)
usbStop();
suspendI2CTasks = false;
#endif
state = (state == ST_FLASH_DONE) ? ST_REBOOT : ST_START;
} else {
+3
View File
@@ -104,6 +104,7 @@ uint8_t latencyToggleSwitch = 0;
#endif
volatile uint8_t rtc_count = 0;
bool suspendI2CTasks = false;
#if defined(DEBUG_LATENCY)
void toggleLatencySwitch()
@@ -1089,6 +1090,7 @@ void edgeTxClose(uint8_t shutdown)
TRACE("edgeTxClose");
watchdogSuspend(2000/*20s*/);
suspendI2CTasks = true;
if (shutdown) {
pulsesStop();
@@ -1140,6 +1142,7 @@ void edgeTxResume()
{
TRACE("edgeTxResume");
suspendI2CTasks = false;
if (!sdMounted()) sdInit();
luaInitMainState();
+5
View File
@@ -51,6 +51,11 @@ enum EnumKeys {
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)
uint32_t readKeys();
+1
View File
@@ -476,6 +476,7 @@ uint16_t keyMapping(uint16_t event)
bool keysPollingCycle()
{
uint32_t trims_input;
pollKeys();
uint32_t keys_input = readKeys();
#if defined(USE_HATS_AS_KEYS)
@@ -171,6 +171,8 @@ typedef struct {
} CSD_ALERT;
/*CSD ALERT Configuration struct*/
extern bool suspendI2CTasks;
void CSD203_Init(CSD_CONFIG *CSD203_CFG); // Initialise CSD203 config
uint16_t CSD203_ReadVbus(CSD_CONFIG *CSD203_CFG); // Read Vbus Voltage
uint16_t CSD203_ReadRshunt(CSD_CONFIG *CSD203_CFG); // Read Rshunt
@@ -410,6 +412,8 @@ void readCSD203(void)
{ // 5ms
static uint16_t GetSenSorStep = 0;
if (suspendI2CTasks) return;
if (IICReadStatusFlag == true) return;
IICReadStatusFlag = true;
+5 -1
View File
@@ -56,10 +56,14 @@ bool bsp_get_shouldReadKeys()
return tmp;
}
static volatile bool errorOccurs = false;
static void bsp_input_read()
{
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;
}
+14 -8
View File
@@ -68,13 +68,15 @@ enum PhysicalKeys
ENT = 16
};
extern bool suspendI2CTasks;
static bool fct_state[4] = {false, false, false, false};
static uint32_t keyState = 0;
#if !defined(BOOT)
static uint32_t nonReadCount = 0;
#endif
static uint32_t _readKeyMatrix()
void pollKeys()
{
#if !defined(BOOT)
if(!bsp_get_shouldReadKeys() && nonReadCount < 10)
@@ -83,10 +85,12 @@ static uint32_t _readKeyMatrix()
keyState |= 1<<ENT;
nonReadCount++;
return keyState;
}
nonReadCount = 0;
#endif
if (suspendI2CTasks) return;
// This function avoids concurrent matrix agitation
uint32_t result = 0;
@@ -98,13 +102,17 @@ static uint32_t _readKeyMatrix()
uint8_t ui8ReadInProgress = 0;
} syncelem;
if (syncelem.ui8ReadInProgress != 0) return syncelem.oldResult;
if (syncelem.ui8ReadInProgress != 0) {
keyState = syncelem.oldResult;
}
// ui8ReadInProgress was 0, increment it
syncelem.ui8ReadInProgress++;
// 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 (syncelem.ui8ReadInProgress > 1) return syncelem.oldResult;
if (syncelem.ui8ReadInProgress > 1) {
keyState = syncelem.oldResult;
}
// If we land here, we have exclusive access to Matrix
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;
keyState = result;
return result;
}
void keysInit()
@@ -183,7 +189,7 @@ uint32_t readKeys()
{
uint32_t result = 0;
uint32_t mkeys = _readKeyMatrix();
uint32_t mkeys = keyState;
if (mkeys & (1 << PGUP)) result |= 1 << KEY_PAGEUP;
if (mkeys & (1 << PGDN)) result |= 1 << KEY_PAGEDN;
if (mkeys & (1 << RTN)) result |= 1 << KEY_EXIT;
@@ -195,7 +201,7 @@ uint32_t readKeys()
uint32_t readTrims()
{
uint32_t mkeys = _readKeyMatrix();
uint32_t mkeys = keyState;
return mkeys & 0xff; // Mask only the trims output
}
+4
View File
@@ -268,6 +268,10 @@ bool getHatsAsKeys()
}
#endif
void pollKeys()
{
}
uint32_t readKeys()
{
uint32_t result = 0;
+5
View File
@@ -58,9 +58,14 @@ enum PhysicalTrims {
TR4R
};
extern bool suspendI2CTasks;
uint32_t readTrims()
{
uint32_t result = 0;
if (suspendI2CTasks) return result;
uint16_t keys = bsp_input_get();
#define _TRIM(t) \
@@ -36,6 +36,7 @@
#define IO_RESET_GPIO GPIO_PIN(GPIOE, 15)
extern const stm32_switch_t* boardGetSwitchDef(uint8_t idx);
extern bool suspendI2CTasks;
struct bsp_io_expander {
pca95xx_t exp;
@@ -84,6 +85,9 @@ static void _poll_switches(void *param1, uint32_t trigger_source)
timer_reset(&_poll_timer);
}
// Suspend hardware reads when required
if (suspendI2CTasks) return;
_read_io_expander(&_io_switches);
_read_io_expander(&_io_fs_switches);
}