You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/15 16:58:20 UTC

[GitHub] utzig closed pull request #910: Common hal for stm32f3

utzig closed pull request #910: Common hal for stm32f3
URL: https://github.com/apache/mynewt-core/pull/910
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld b/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
index 5a7c3b9e0..4509320b3 100755
--- a/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
+++ b/hw/bsp/stm32f3discovery/boot-stm32f3discovery.ld
@@ -22,7 +22,7 @@ ENTRY(Reset_Handler)
  * Memory map
  */
 MEMORY {
-    FLASH (rx): ORIGIN = 0x08000000, LENGTH = 24K
+    FLASH (rx): ORIGIN = 0x08000000, LENGTH = 16K
     CCRAM (rw): ORIGIN = 0x10000000, LENGTH = 8K
     SRAM  (rw): ORIGIN = 0x20000000, LENGTH = 40K
 }
diff --git a/hw/bsp/stm32f3discovery/bsp.yml b/hw/bsp/stm32f3discovery/bsp.yml
index 7e92d65a5..5cc58b247 100644
--- a/hw/bsp/stm32f3discovery/bsp.yml
+++ b/hw/bsp/stm32f3discovery/bsp.yml
@@ -36,28 +36,28 @@ bsp.flash_map:
         FLASH_AREA_BOOTLOADER:
             device: 0
             offset: 0x08000000
-            size:   24kB
+            size: 16kB
         FLASH_AREA_IMAGE_0:
             device: 0
-            offset: 0x08006000
-            size:   96kB
+            offset: 0x08004000
+            size: 88kB
         FLASH_AREA_IMAGE_1:
             device: 0
-            offset: 0x0801e000
-            size:   96kB
+            offset: 0x0801a000
+            size: 88kB
         FLASH_AREA_IMAGE_SCRATCH:
             device: 0
-            offset: 0x08036000
-            size:   16kB
+            offset: 0x08030000
+            size: 16kB
 
         # User areas.
         FLASH_AREA_REBOOT_LOG:
             user_id: 0
             device: 0
-            offset: 0x0803a000
-            size: 8kB
+            offset: 0x08034000
+            size: 16kB
         FLASH_AREA_NFFS:
             user_id: 1
             device: 0
-            offset: 0x0803c000
-            size: 16kB
+            offset: 0x08038000
+            size: 32kB
diff --git a/hw/bsp/stm32f3discovery/stm32f3discovery.ld b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
index c137613c9..58ee95ec5 100755
--- a/hw/bsp/stm32f3discovery/stm32f3discovery.ld
+++ b/hw/bsp/stm32f3discovery/stm32f3discovery.ld
@@ -22,7 +22,7 @@ ENTRY(Reset_Handler)
  * Memory map
  */
 MEMORY {
-    FLASH (rx): ORIGIN = 0x08006000, LENGTH = 256K
+    FLASH (rx): ORIGIN = 0x08004000, LENGTH = 240K
     CCRAM (rw): ORIGIN = 0x10000000, LENGTH = 8K
     SRAM  (rw): ORIGIN = 0x20000000, LENGTH = 40K
 }
diff --git a/hw/mcu/stm/stm32_common/src/stm32_hw_id.c b/hw/mcu/stm/stm32_common/src/stm32_hw_id.c
index 4dad67af9..333138be3 100644
--- a/hw/mcu/stm/stm32_common/src/stm32_hw_id.c
+++ b/hw/mcu/stm/stm32_common/src/stm32_hw_id.c
@@ -33,7 +33,7 @@ hal_bsp_hw_id(uint8_t *id, int max_len)
     int cnt;
 
     cnt = min(12, max_len);
-    memcpy(id, (void *)STM32_HW_ID_ADDR, cnt);
+    memcpy(id, (void *)UID_BASE, cnt);
 
     return cnt;
 }
diff --git a/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h b/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
index 9dc7e870d..3685e62c1 100644
--- a/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
+++ b/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
@@ -36,13 +36,6 @@ extern "C" {
 /* hal_system_start */
 #define STM32_HAL_FLASH_REMAP()
 
-/* stm32_hw_id
- *
- * STM32F1 has a unique 96-bit id at address 0x1FFFF7E8.
- * See ref manual chapter 30.2.
- */
-#define STM32_HW_ID_ADDR 0x1FFFF7E8
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_system.c b/hw/mcu/stm/stm32f3xx/include/mcu/stm32_hal.h
similarity index 59%
rename from hw/mcu/stm/stm32f3xx/src/hal_system.c
rename to hw/mcu/stm/stm32f3xx/include/mcu/stm32_hal.h
index 6bcbc96a3..63b9ca816 100644
--- a/hw/mcu/stm/stm32f3xx/src/hal_system.c
+++ b/hw/mcu/stm/stm32f3xx/include/mcu/stm32_hal.h
@@ -17,27 +17,33 @@
  * under the License.
  */
 
+#ifndef STM32_HAL_H
+#define STM32_HAL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <mcu/cortex_m4.h>
-#include <os/os.h>
-#include "hal/hal_system.h"
+
+#include "stm32f3xx_hal.h"
 #include "stm32f3xx_hal_def.h"
 
-void
-hal_system_reset(void)
-{
-    while (1) {
-        if (hal_debugger_connected()) {
-            /*
-             * If debugger is attached, breakpoint here.
-             */
-            asm("bkpt");
-        }
-        NVIC_SystemReset();
-    }
-}
+/* hal_watchdog */
+#include "stm32f3xx_hal_iwdg.h"
+#define STM32_HAL_WATCHDOG_CUSTOM_INIT(x)           \
+    do {                                            \
+        (x)->Init.Window = IWDG_WINDOW_DISABLE;     \
+    } while (0)
+
+/* hal_system_start */
+#define STM32_HAL_FLASH_REMAP()                  \
+    do {                                         \
+        __HAL_SYSCFG_REMAPMEMORY_FLASH();        \
+    } while (0)
 
-int
-hal_debugger_connected(void)
-{
-    return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
+#ifdef __cplusplus
 }
+#endif
+
+#endif /* STM32_HAL_H */
diff --git a/hw/mcu/stm/stm32f3xx/pkg.yml b/hw/mcu/stm/stm32f3xx/pkg.yml
index d470c3ffc..bb5fa98dc 100644
--- a/hw/mcu/stm/stm32f3xx/pkg.yml
+++ b/hw/mcu/stm/stm32f3xx/pkg.yml
@@ -29,5 +29,5 @@ pkg.type: sdk
 
 pkg.deps:
     - hw/hal
-    - hw/mcu/stm/stm32f3xx
+    - hw/mcu/stm/stm32_common
     - hw/cmsis-core
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_flash.c b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
index e9fb3da11..84dc2b691 100644
--- a/hw/mcu/stm/stm32f3xx/src/hal_flash.c
+++ b/hw/mcu/stm/stm32f3xx/src/hal_flash.c
@@ -127,7 +127,7 @@ stm32f3_flash_dev()
         stm32f3_flash_dev_.hf_base_addr = FLASH_BASE;
         stm32f3_flash_dev_.hf_size = HAL_FLASH_SIZE;
         stm32f3_flash_dev_.hf_sector_cnt = HAL_FLASH_SIZE / HAL_FLASH_SECTOR_SIZE;
-        stm32f3_flash_dev_.hf_align = FLASH_PAGE_SIZE;
+        stm32f3_flash_dev_.hf_align = 2;
     }
     return &stm32f3_flash_dev_;
 }
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_os_tick.c b/hw/mcu/stm/stm32f3xx/src/hal_os_tick.c
deleted file mode 100644
index 46b935a74..000000000
--- a/hw/mcu/stm/stm32f3xx/src/hal_os_tick.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <os/os.h>
-#include <hal/hal_os_tick.h>
-
-/*
- * XXX implement tickless mode.
- */
-void
-os_tick_idle(os_time_t ticks)
-{
-    OS_ASSERT_CRITICAL();
-    __DSB();
-    __WFI();
-}
-
-void
-os_tick_init(uint32_t os_ticks_per_sec, int prio)
-{
-    uint32_t reload_val;
-
-    reload_val = ((uint64_t)SystemCoreClock / os_ticks_per_sec) - 1;
-
-    /* Set the system time ticker up */
-    SysTick->LOAD = reload_val;
-    SysTick->VAL = 0;
-    SysTick->CTRL = 0x0007;
-
-    /* Set the system tick priority */
-    NVIC_SetPriority(SysTick_IRQn, prio);
-
-    /*
-     * Keep clocking debug even when CPU is sleeping, stopped or in standby.
-     */
-    DBGMCU->CR |= (DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP |
-      DBGMCU_CR_DBG_STANDBY);
-}
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_system_start.c b/hw/mcu/stm/stm32f3xx/src/hal_system_start.c
deleted file mode 100644
index 3dc24698f..000000000
--- a/hw/mcu/stm/stm32f3xx/src/hal_system_start.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <stddef.h>
-#include <inttypes.h>
-#include <mcu/cortex_m4.h>
-#include "stm32f3xx_hal.h"
-
-/**
- * Boots the image described by the supplied image header.
- *
- * @param hdr                   The header for the image to boot.
- */
-void
-hal_system_start(void *img_start)
-{
-    typedef void jump_fn(void);
-
-    uint32_t base0entry;
-    uint32_t jump_addr;
-    jump_fn *fn;
-
-    /* First word contains initial MSP value. */
-    __set_MSP(*(uint32_t *)img_start);
-
-    /* Second word contains address of entry point (Reset_Handler). */
-    base0entry = *(uint32_t *)(img_start + 4);
-    jump_addr = base0entry;
-    fn = (jump_fn *)jump_addr;
-
-    /* Remap memory such that flash gets mapped to the code region. */
-    __HAL_SYSCFG_REMAPMEMORY_FLASH();
-    __DSB();
-
-    /* Jump to image. */
-    fn();
-}
-
diff --git a/hw/mcu/stm/stm32f3xx/src/hal_watchdog.c b/hw/mcu/stm/stm32f3xx/src/hal_watchdog.c
deleted file mode 100644
index ab7394a88..000000000
--- a/hw/mcu/stm/stm32f3xx/src/hal_watchdog.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "hal/hal_watchdog.h"
-#include "stm32f3xx_hal.h"
-#include "stm32f3xx_hal_iwdg.h"
-
-IWDG_HandleTypeDef g_wdt_cfg;
-
-int
-hal_watchdog_init(uint32_t expire_msecs)
-{
-    uint32_t reload;
-
-    /* Max prescaler is 256 */
-    reload = 32768 / 256;
-    reload = (reload * expire_msecs) / 1000;
-
-    /* Check to make sure we are not trying a reload value that is too large */
-    if (reload > IWDG_RLR_RL) {
-        return -1;
-    }
-
-    g_wdt_cfg.Instance = IWDG;
-    g_wdt_cfg.Init.Prescaler = IWDG_PRESCALER_256;
-    g_wdt_cfg.Init.Reload = reload;
-    g_wdt_cfg.Init.Window = IWDG_WINDOW_DISABLE;
-
-    return 0;
-}
-
-void
-hal_watchdog_enable(void)
-{
-    __HAL_DBGMCU_FREEZE_IWDG();
-    HAL_IWDG_Init(&g_wdt_cfg);
-}
-
-void
-hal_watchdog_tickle(void)
-{
-    HAL_IWDG_Refresh(&g_wdt_cfg);
-}
-
diff --git a/hw/mcu/stm/stm32f3xx/src/stm32f3xx_hw_id.c b/hw/mcu/stm/stm32f3xx/src/stm32f3xx_hw_id.c
deleted file mode 100644
index 9b0d508e4..000000000
--- a/hw/mcu/stm/stm32f3xx/src/stm32f3xx_hw_id.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "stm32f3xx_ll_utils.h"
-
-#include <inttypes.h>
-#include <string.h>
-#include <hal/hal_bsp.h>
-
-#ifndef min
-#define min(a, b) ((a)<(b)?(a):(b))
-#endif
-
-/*
- * hw id
- * 
- * Answer UID of the mcu.
- *
- * @param *id
- * @param max_len
- *
- * @return int
- */
-int
-hal_bsp_hw_id(uint8_t *id, int max_len)
-{
-    int cnt;
-
-    cnt = min(12, max_len);
-    memcpy(id, (void *)UID_BASE_ADDRESS, cnt);
-
-    return cnt;
-}
diff --git a/hw/mcu/stm/stm32f3xx/syscfg.yml b/hw/mcu/stm/stm32f3xx/syscfg.yml
index d21223965..f455638ef 100644
--- a/hw/mcu/stm/stm32f3xx/syscfg.yml
+++ b/hw/mcu/stm/stm32f3xx/syscfg.yml
@@ -21,7 +21,7 @@ syscfg.defs:
         description: >
             Specifies the required alignment for internal flash writes.
             Used internally by the newt tool.
-        value: 1
+        value: 2
 
     MCU_STM32F3:
         description: MCUs are of STM32F3xx family
diff --git a/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
index ce4442fe3..b6e65fab4 100644
--- a/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
@@ -40,13 +40,6 @@ extern "C" {
         __DSB();                                 \
     } while (0)
 
-/* stm32_hw_id
- *
- * STM32F4 has a unique 96-bit id at address 0x1FFF7A10.
- * See ref manual chapter 39.1.
- */
-#define STM32_HW_ID_ADDR 0x1FFF7A10
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h b/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
index 9187517c6..60d53f078 100644
--- a/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
+++ b/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
@@ -44,13 +44,6 @@ extern "C" {
         __DSB();                                 \
     } while (0)
 
-/* stm32_hw_id
- *
- * STM32F7 has a unique 96-bit id at address 0x1FF0F420.
- * See ref manual chapter 45.1.
- */
-#define STM32_HW_ID_ADDR 0x1FF0F420
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h b/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
index 5cdcfd813..ebc5b3b9c 100644
--- a/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
+++ b/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
@@ -40,14 +40,6 @@ extern "C" {
         __DSB();                                 \
     } while (0)
 
-/* stm32_hw_id
- *
- * STM32L1 has a unique 96-bit id at address either address
- * 0x1FF80050 or 0x1FF800D0 depending on the specific device.
- * See ref manual chapter 31.2.
- */
-#define STM32_HW_ID_ADDR 0x1FF800D0
-
 #ifdef __cplusplus
 }
 #endif


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services