Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libopencm3/stm32/f3/flash.h3
-rw-r--r--lib/stm32/f3/flash.c46
2 files changed, 48 insertions, 1 deletions
diff --git a/include/libopencm3/stm32/f3/flash.h b/include/libopencm3/stm32/f3/flash.h
index ca561efb..a978ebf7 100644
--- a/include/libopencm3/stm32/f3/flash.h
+++ b/include/libopencm3/stm32/f3/flash.h
@@ -99,6 +99,9 @@ BEGIN_DECLS
void flash_clear_pgerr_flag(void);
void flash_clear_wrprterr_flag(void);
+void flash_program_half_word(uint32_t address, uint16_t data);
+void flash_erase_page(uint32_t page_address);
+void flash_erase_all_pages(void);
END_DECLS
diff --git a/lib/stm32/f3/flash.c b/lib/stm32/f3/flash.c
index ffd03c30..da8dfb68 100644
--- a/lib/stm32/f3/flash.c
+++ b/lib/stm32/f3/flash.c
@@ -46,6 +46,11 @@
#include <libopencm3/stm32/flash.h>
+void flash_wait_for_last_operation(void)
+{
+ while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
+}
+
void flash_clear_pgerr_flag(void)
{
FLASH_SR |= FLASH_SR_PGERR;
@@ -57,10 +62,11 @@ void flash_clear_wrprterr_flag(void)
}
/*---------------------------------------------------------------------------*/
+
/** @brief Clear All Status Flags
Clears program error, end of operation, busy flags.
-*/
+ */
void flash_clear_status_flags(void)
{
@@ -69,5 +75,43 @@ void flash_clear_status_flags(void)
flash_clear_eop_flag();
}
+void flash_program_half_word(uint32_t address, uint16_t data)
+{
+ flash_wait_for_last_operation();
+
+ FLASH_CR |= FLASH_CR_PG;
+
+ MMIO16(address) = data;
+
+ flash_wait_for_last_operation();
+
+ FLASH_CR &= ~FLASH_CR_PG;
+}
+
+void flash_erase_page(uint32_t page_address)
+{
+ flash_wait_for_last_operation();
+
+ FLASH_CR |= FLASH_CR_PER;
+ FLASH_AR = page_address;
+ FLASH_CR |= FLASH_CR_STRT;
+
+ flash_wait_for_last_operation();
+
+ FLASH_CR &= ~FLASH_CR_PER;
+}
+
+void flash_erase_all_pages(void)
+{
+ flash_wait_for_last_operation();
+
+ FLASH_CR |= FLASH_CR_MER;
+ FLASH_CR |= FLASH_CR_STRT;
+
+ flash_wait_for_last_operation();
+ FLASH_CR &= ~FLASH_CR_MER;
+}
+
+
/**@}*/