diff --git a/src/drivers/opencm3_naze32_common/drv_flash.c b/src/drivers/opencm3_naze32_common/drv_flash.c index e497210..d791390 100644 --- a/src/drivers/opencm3_naze32_common/drv_flash.c +++ b/src/drivers/opencm3_naze32_common/drv_flash.c @@ -6,6 +6,17 @@ #include +#include "mavlink_system.h" +#include "params.h" + +#include "drivers/drv_system.h" +#include "fix16.h" +#include "fixextra.h" + +#include "robin_itoa.h" +#include + + #define ASSERT_CONCAT_( a, b ) a##b #define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b ) #define ct_assert( e ) \ @@ -109,26 +120,65 @@ bool drv_flash_write( void ) { // XXX: Could try multiple times for the rest + flash_wait_for_last_operation(); + flash_clear_status_flags(); + flash_erase_page(FLASH_OPERATION_ADDRESS); flash_status = flash_get_status_flags(); + bool keep_going = true; - //XXX: Could return full status here for better handling - if(flash_status != FLASH_SR_EOP) - return false; //flash_status + //Flash is either busy or in error state + if(flash_status != FLASH_SR_EOP) { + char text[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN] = "[FLASH] Invalid write-start status: 0x"; + char numtext[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN]; + robin_itoa(numtext, MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN, flash_status, 16); + strncat(text,numtext,MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN-1); + mavlink_queue_broadcast_debug( text ); - // programming flash memory - for(uint16_t i=0; i