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
@@ -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);
}