From c08044e22bc5477b27820d1f526b49bdcf9ba436 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Fri, 29 Sep 2017 13:47:35 +0900
Subject: Fix sys for STM32F103.

---
 ChangeLog           |  5 +++++
 mcu/sys-stm32f103.c | 16 ++++++++--------
 mcu/sys-stm32f103.h | 14 +++++++-------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f97607d..43f40e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-29  NIIBE Yutaka  <gniibe@fsij.org>
+
+	* mcu/sys-stm32f103.c (flash_program_halfword, flash_erase_page)
+	(flash_write, flash_erase_all_and_exec): Use uintptr_t.
+
 2017-09-08  NIIBE Yutaka  <gniibe@fsij.org>
 
 	* mcu/sys-gnu-linux.c: Flash emulation implemented.
diff --git a/mcu/sys-stm32f103.c b/mcu/sys-stm32f103.c
index 81d8ec1..f391fa6 100644
--- a/mcu/sys-stm32f103.c
+++ b/mcu/sys-stm32f103.c
@@ -148,7 +148,7 @@ flash_wait_for_last_operation (uint32_t timeout)
 #define FLASH_ERASE_TIMEOUT   0x01000000
 
 static int
-flash_program_halfword (uint32_t addr, uint16_t data)
+flash_program_halfword (uintptr_t addr, uint16_t data)
 {
   int status;
 
@@ -170,7 +170,7 @@ flash_program_halfword (uint32_t addr, uint16_t data)
 }
 
 static int
-flash_erase_page (uint32_t addr)
+flash_erase_page (uintptr_t addr)
 {
   int status;
 
@@ -210,13 +210,13 @@ flash_check_blank (const uint8_t *p_start, size_t size)
 #define FLASH_SIZE_REG   ((uint16_t *)0x1ffff7e0)
 
 static int
-flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
+flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len)
 {
   int status;
 #if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
-  uint32_t flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
+  uintptr_t flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
 #else
-  uint32_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
+  uintptr_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
 #endif
 
   if (dst_addr < FLASH_START || dst_addr + len > flash_end)
@@ -272,11 +272,11 @@ flash_protect (void)
 static void __attribute__((naked))
 flash_erase_all_and_exec (void (*entry)(void))
 {
-  uint32_t addr = FLASH_START;
+  uintptr_t addr = FLASH_START;
 #if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
-  uint32_t end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
+  uintptr_t end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
 #else
-  uint32_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
+  uintptr_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
 #endif
   uint32_t page_size = 1024;
   int r;
diff --git a/mcu/sys-stm32f103.h b/mcu/sys-stm32f103.h
index 59f6253..a39afd5 100644
--- a/mcu/sys-stm32f103.h
+++ b/mcu/sys-stm32f103.h
@@ -47,17 +47,17 @@ flash_unlock (void)
 }
 
 static inline int
-flash_program_halfword (uint32_t addr, uint16_t data)
+flash_program_halfword (uintptr_t addr, uint16_t data)
 {
-  int (*func) (uint32_t, uint16_t) = (int (*)(uint32_t, uint16_t))vector[4];
+  int (*func) (uintptr_t, uint16_t) = (int (*)(uintptr_t, uint16_t))vector[4];
 
   return (*func) (addr, data);
 }
 
 static inline int
-flash_erase_page (uint32_t addr)
+flash_erase_page (uintptr_t addr)
 {
-  int (*func) (uint32_t) = (int (*)(uint32_t))vector[5];
+  int (*func) (uintptr_t) = (int (*)(uintptr_t))vector[5];
 
   return (*func) (addr);
 }
@@ -71,10 +71,10 @@ flash_check_blank (const uint8_t *p_start, size_t size)
 }
 
 static inline int
-flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
+flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len)
 {
-  int (*func) (uint32_t, const uint8_t *, size_t)
-    = (int (*)(uint32_t, const uint8_t *, size_t))vector[7];
+  int (*func) (uintptr_t, const uint8_t *, size_t)
+    = (int (*)(uintptr_t, const uint8_t *, size_t))vector[7];
 
   return (*func) (dst_addr, src, len);
 }
-- 
cgit v1.2.3