From 2cd8302e2cab382ab6596c09b4ede7cf70a805ed Mon Sep 17 00:00:00 2001 From: niekky Date: Thu, 26 Feb 2026 14:42:45 -0700 Subject: [PATCH 1/2] remove HAL_Delay(1) --- flash/flash.c | 1 - 1 file changed, 1 deletion(-) diff --git a/flash/flash.c b/flash/flash.c index bbb7aed..15ed6ba 100644 --- a/flash/flash.c +++ b/flash/flash.c @@ -820,7 +820,6 @@ for ( int i = 2; i < pflash_handle -> num_bytes; i += 2 ) else { timeout_ctr++; - HAL_Delay( 1 ); } } From 6c4801628090f7a3e68425c31074cd5b1b1a3d64 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 19:00:58 +0000 Subject: [PATCH 2/2] fix flash_write timeout: use HAL_GetTick elapsed time instead of iteration counter Agent-Logs-Url: https://github.com/SunDevilRocketry/mod/sessions/a9defb2b-8e1b-4a3a-b693-046530f214e4 Co-authored-by: niekky <80115619+niekky@users.noreply.github.com> --- flash/flash.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/flash/flash.c b/flash/flash.c index 15ed6ba..e18685b 100644 --- a/flash/flash.c +++ b/flash/flash.c @@ -731,8 +731,8 @@ FLASH_STATUS flash_write HAL_StatusTypeDef hal_status[3]; /* Status codes returned by HAL */ FLASH_STATUS flash_status; /* Status codes returned by flash API */ uint8_t flash_opcode; /* Opcode for flash instructions */ -uint32_t timeout; /* Timeout for flash write calls */ -uint32_t timeout_ctr; /* Counter to trigger timeout */ +uint32_t timeout; /* Timeout for flash write calls (ms) */ +uint32_t timeout_start; /* HAL tick at start of flash write */ uint8_t* pbuffer; /* Pointer to data in flash buffer */ uint8_t address_bytes[3]; /* Flash memory address in byte form */ @@ -743,7 +743,7 @@ uint8_t address_bytes[3]; /* Flash memory address in byte form */ flash_opcode = FLASH_OP_HW_AAI_PROGRAM; flash_status = FLASH_OK; timeout = pflash_handle -> num_bytes; /* 1 ms/byte timeout */ -timeout_ctr = 0; +timeout_start = HAL_GetTick(); pbuffer = pflash_handle -> pbuffer; address_to_bytes( pflash_handle -> address, &address_bytes[0] ); @@ -813,14 +813,10 @@ for ( int i = 2; i < pflash_handle -> num_bytes; i += 2 ) /* Wait for flash to be ready */ while( flash_is_flash_busy() == FLASH_BUSY ) { - if ( timeout_ctr >= timeout ) + if ( ( HAL_GetTick() - timeout_start ) >= timeout ) { return FLASH_TIMEOUT; } - else - { - timeout_ctr++; - } } /* SPI Transmission */