aboutsummaryrefslogtreecommitdiff
path: root/flashstub/stm32l05x-nvm-prog-erase.cc
diff options
context:
space:
mode:
authorMarc Singer2015-01-24 13:50:59 -0800
committerMarc Singer2015-03-08 16:25:22 -0700
commitbf1cb71eb7a3a679a6acf944283cd0f0ef53c077 (patch)
treefe0cb67833677720caec8bda1f23263b3d364b8e /flashstub/stm32l05x-nvm-prog-erase.cc
parente0a8ce5a887cb31f38077cd22271fd894070e0e9 (diff)
Revisions on Gareth's comments.
o Implemented byte writes to EEPROM now that the emulator has a byte-wide target write. o Added comment describing the reason that mass erase doesn't work. o Removed all unused code. o Changed to Linux kernel indent style. o Changed to Linux kernel function to parenthesis style. o Stub generation doesn't use Perl, switched to sed. Also, only including the instructions instead of the source and the instructions. o Handling unaligned destination writes.
Diffstat (limited to 'flashstub/stm32l05x-nvm-prog-erase.cc')
-rw-r--r--flashstub/stm32l05x-nvm-prog-erase.cc80
1 files changed, 40 insertions, 40 deletions
diff --git a/flashstub/stm32l05x-nvm-prog-erase.cc b/flashstub/stm32l05x-nvm-prog-erase.cc
index 28c11a3..58030e3 100644
--- a/flashstub/stm32l05x-nvm-prog-erase.cc
+++ b/flashstub/stm32l05x-nvm-prog-erase.cc
@@ -42,52 +42,52 @@
/* Erase a region of flash. In the event that the erase is misaligned
with respect to pages, it will erase the pages that contain the
requested range of bytes. */
-extern "C" void __attribute((naked)) stm32l05x_nvm_prog_erase () {
- // Leave room for INFO at second word of routine
- __asm volatile ("b 0f\n\t"
- ".align 2\n\t"
- ".word 0\n\t"
- ".word 0\n\t"
- ".word 0\n\t"
- ".word 0\n\t"
- ".word 0\n\t"
- "0:");
-
- auto& nvm = Nvm (Info.nvm);
-
- // Align to the start of the first page so that we make sure to erase
- // all of the target pages.
- auto remainder = reinterpret_cast<uint32_t> (Info.destination)
- & (Info.page_size - 1);
- Info.size += remainder;
- Info.destination -= remainder/sizeof (*Info.destination);
-
- if (!unlock (nvm))
- goto quit;
-
- nvm.sr = STM32Lx_NVM_SR_ERR_M; // Clear errors
-
- // Enable erasing
- nvm.pecr = STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE;
- if ((nvm.pecr & (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
- != (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
- goto quit;
-
- while (Info.size > 0) {
- *Info.destination = 0; // Initiate erase
-
- Info.destination += Info.page_size/sizeof (*Info.destination);
- Info.size -= Info.page_size;
- }
+extern "C" void __attribute((naked)) stm32l05x_nvm_prog_erase() {
+ // Leave room for INFO at second word of routine
+ __asm volatile ("b 0f\n\t"
+ ".align 2\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ ".word 0\n\t"
+ "0:");
+
+ auto& nvm = Nvm (Info.nvm);
+
+ // Align to the start of the first page so that we make sure to erase
+ // all of the target pages.
+ auto remainder = reinterpret_cast<uint32_t> (Info.destination)
+ & (Info.page_size - 1);
+ Info.size += remainder;
+ Info.destination -= remainder/sizeof (*Info.destination);
+
+ if (!unlock(nvm))
+ goto quit;
+
+ nvm.sr = STM32Lx_NVM_SR_ERR_M; // Clear errors
+
+ // Enable erasing
+ nvm.pecr = STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE;
+ if ((nvm.pecr & (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
+ != (STM32Lx_NVM_PECR_PROG | STM32Lx_NVM_PECR_ERASE))
+ goto quit;
+
+ while (Info.size > 0) {
+ *Info.destination = 0; // Initiate erase
+
+ Info.destination += Info.page_size/sizeof (*Info.destination);
+ Info.size -= Info.page_size;
+ }
quit:
- lock (nvm);
- __asm volatile ("bkpt");
+ lock(nvm);
+ __asm volatile ("bkpt");
}
/*
Local Variables:
- compile-command: "/opt/arm/arm-none-eabi-g++ -mcpu=cortex-m0plus -g -c -std=c++11 -mthumb -o stm32l05x-nvm-prog-erase.o -Os -Wa,-ahndl=stm32l05x-nvm-prog-erase.lst stm32l05x-nvm-prog-erase.cc ; /opt/arm/arm-none-eabi-objdump -S stm32l05x-nvm-prog-erase.o | ./code-to-array.pl > stm32l05x-nvm-prog-erase.stub"
+ compile-command: "/opt/arm/arm-none-eabi-g++ -mcpu=cortex-m0plus -g -c -std=c++11 -mthumb -o stm32l05x-nvm-prog-erase.o -Os -Wa,-ahndl=stm32l05x-nvm-prog-erase.lst stm32l05x-nvm-prog-erase.cc ; /opt/arm/arm-none-eabi-objdump -d -z stm32l05x-nvm-prog-erase.o | ./dump-to-array.sh > stm32l05x-nvm-prog-erase.stub"
End:
*/