aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/stm32/dfu_f1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platforms/stm32/dfu_f1.c')
-rw-r--r--src/platforms/stm32/dfu_f1.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c
index 9d82bec..abbdbe6 100644
--- a/src/platforms/stm32/dfu_f1.c
+++ b/src/platforms/stm32/dfu_f1.c
@@ -16,11 +16,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+#include "general.h"
+#include "usbdfu.h"
#include <libopencm3/stm32/f1/flash.h>
#include <libopencm3/cm3/scb.h>
-#include "usbdfu.h"
#define FLASH_OBP_RDP 0x1FFFF800
#define FLASH_OBP_WRP10 0x1FFFF808
@@ -48,7 +48,7 @@ void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len)
{
for(int i = 0; i < len; i += 2)
flash_program_half_word(baseaddr + i,
- *(u16*)(buf+i));
+ *(uint16_t*)(buf+i));
}
uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum)
@@ -59,8 +59,10 @@ uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum)
return 100;
}
-void dfu_protect_enable(void)
+void dfu_protect(dfu_mode_t mode)
{
+ if (mode == DFU_MODE) {
+#ifdef DFU_SELF_PROTECT
if ((FLASH_WRPR & 0x03) != 0x00) {
flash_unlock();
FLASH_CR = 0;
@@ -70,19 +72,26 @@ void dfu_protect_enable(void)
/* MD Device: Protect 2 bits with (4 * 1k pages each)*/
flash_program_option_bytes(FLASH_OBP_WRP10, 0x03FC);
}
+#endif
+ }
+ else if (mode == UPD_MODE) {
+ flash_unlock();
+ FLASH_CR = 0;
+ flash_erase_option_bytes();
+ }
}
void dfu_jump_app_if_valid(void)
{
/* Boot the application if it's valid */
- if((*(volatile u32*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) {
+ if((*(volatile uint32_t*)app_address & 0x2FFE0000) == 0x20000000) {
/* Set vector table base address */
- SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/
+ SCB_VTOR = app_address & 0x1FFFFF; /* Max 2 MByte Flash*/
/* Initialise master stack pointer */
asm volatile ("msr msp, %0"::"g"
- (*(volatile u32*)APP_ADDRESS));
+ (*(volatile uint32_t*)app_address));
/* Jump to application */
- (*(void(**)())(APP_ADDRESS + 4))();
+ (*(void(**)())(app_address + 4))();
}
}