You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/03/12 12:27:39 UTC
[mynewt-core] branch master updated: Add stm32 common hal for
shared drivers
This is an automated email from the ASF dual-hosted git repository.
utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 15cef3a Add stm32 common hal for shared drivers
15cef3a is described below
commit 15cef3a900d3003771feb81b3de1333c4da61842
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Tue Feb 20 09:10:28 2018 -0300
Add stm32 common hal for shared drivers
Signed-off-by: Fabio Utzig <ut...@apache.org>
---
hw/mcu/stm/{stm32f1xx => stm32_common}/pkg.yml | 14 +----
.../{stm32l1xx => stm32_common}/src/hal_os_tick.c | 0
.../{stm32f4xx => stm32_common}/src/hal_system.c | 3 +-
.../src/hal_system_start.c | 7 ++-
.../{stm32f1xx => stm32_common}/src/hal_watchdog.c | 5 +-
.../src/stm32_hw_id.c} | 7 +--
.../stm32f1xx_hw_id.c => include/mcu/stm32_hal.h} | 38 ++++++++------
hw/mcu/stm/stm32f1xx/pkg.yml | 2 +-
hw/mcu/stm/stm32f1xx/src/hal_os_tick.c | 55 --------------------
hw/mcu/stm/stm32f1xx/src/hal_system.c | 55 --------------------
hw/mcu/stm/stm32f1xx/src/hal_system_start.c | 54 --------------------
.../hal_watchdog.c => include/mcu/stm32_hal.h} | 57 ++++++++++-----------
hw/mcu/stm/stm32f4xx/pkg.yml | 6 +--
hw/mcu/stm/stm32f4xx/src/hal_os_tick.c | 55 --------------------
.../stm32f7xx_hw_id.c => include/mcu/stm32_hal.h} | 46 +++++++++++------
hw/mcu/stm/stm32f7xx/pkg.yml | 2 +-
hw/mcu/stm/stm32f7xx/src/hal_os_tick.c | 55 --------------------
hw/mcu/stm/stm32f7xx/src/hal_system.c | 55 --------------------
hw/mcu/stm/stm32f7xx/src/hal_system_start.c | 55 --------------------
hw/mcu/stm/stm32f7xx/src/hal_watchdog.c | 59 ----------------------
.../stm32l1xx_hw_id.c => include/mcu/stm32_hal.h} | 44 +++++++++-------
hw/mcu/stm/stm32l1xx/pkg.yml | 2 +-
hw/mcu/stm/stm32l1xx/src/hal_system.c | 55 --------------------
hw/mcu/stm/stm32l1xx/src/hal_system_start.c | 54 --------------------
hw/mcu/stm/stm32l1xx/src/hal_watchdog.c | 59 ----------------------
25 files changed, 123 insertions(+), 721 deletions(-)
diff --git a/hw/mcu/stm/stm32f1xx/pkg.yml b/hw/mcu/stm/stm32_common/pkg.yml
similarity index 81%
copy from hw/mcu/stm/stm32f1xx/pkg.yml
copy to hw/mcu/stm/stm32_common/pkg.yml
index 919a3e0..90575b3 100644
--- a/hw/mcu/stm/stm32f1xx/pkg.yml
+++ b/hw/mcu/stm/stm32_common/pkg.yml
@@ -17,23 +17,13 @@
# under the License.
#
-pkg.name: hw/mcu/stm/stm32f1xx
-pkg.description: MCU definition for STM32F1 ARM Cortex-M3 chips.
+pkg.name: hw/mcu/stm/stm32_common
+pkg.description: STM32 shared drivers
pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- stm32
- - stm32f1
-
-pkg.type: sdk
-
-pkg.ign_files:
- - ".*template.*"
-
-pkg.ign_dirs:
- - "Device"
pkg.deps:
- hw/hal
- - hw/mcu/stm/stm32f1xx
- hw/cmsis-core
diff --git a/hw/mcu/stm/stm32l1xx/src/hal_os_tick.c b/hw/mcu/stm/stm32_common/src/hal_os_tick.c
similarity index 100%
rename from hw/mcu/stm/stm32l1xx/src/hal_os_tick.c
rename to hw/mcu/stm/stm32_common/src/hal_os_tick.c
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_system.c b/hw/mcu/stm/stm32_common/src/hal_system.c
similarity index 95%
rename from hw/mcu/stm/stm32f4xx/src/hal_system.c
rename to hw/mcu/stm/stm32_common/src/hal_system.c
index 2167830..57522dc 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_system.c
+++ b/hw/mcu/stm/stm32_common/src/hal_system.c
@@ -17,10 +17,9 @@
* under the License.
*/
-#include <mcu/cortex_m4.h>
+#include "mcu/stm32_hal.h"
#include <os/os.h>
#include "hal/hal_system.h"
-#include "stm32f4xx_hal_def.h"
void
hal_system_reset(void)
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_system_start.c b/hw/mcu/stm/stm32_common/src/hal_system_start.c
similarity index 91%
rename from hw/mcu/stm/stm32f4xx/src/hal_system_start.c
rename to hw/mcu/stm/stm32_common/src/hal_system_start.c
index 42c85a0..4f26632 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_system_start.c
+++ b/hw/mcu/stm/stm32_common/src/hal_system_start.c
@@ -20,7 +20,8 @@
#include <assert.h>
#include <stddef.h>
#include <inttypes.h>
-#include <mcu/cortex_m4.h>
+
+#include "mcu/stm32_hal.h"
/**
* Boots the image described by the supplied image header.
@@ -44,9 +45,7 @@ hal_system_start(void *img_start)
jump_addr = base0entry;
fn = (jump_fn *)jump_addr;
- /* Remap memory such that flash gets mapped to the code region. */
- SYSCFG->MEMRMP = 0;
- __DSB();
+ STM32_HAL_FLASH_REMAP();
/* Jump to image. */
fn();
diff --git a/hw/mcu/stm/stm32f1xx/src/hal_watchdog.c b/hw/mcu/stm/stm32_common/src/hal_watchdog.c
similarity index 95%
rename from hw/mcu/stm/stm32f1xx/src/hal_watchdog.c
rename to hw/mcu/stm/stm32_common/src/hal_watchdog.c
index 7bc5a69..02723f0 100644
--- a/hw/mcu/stm/stm32f1xx/src/hal_watchdog.c
+++ b/hw/mcu/stm/stm32_common/src/hal_watchdog.c
@@ -18,8 +18,7 @@
*/
#include "hal/hal_watchdog.h"
-#include "stm32f1xx_hal.h"
-#include "stm32f1xx_hal_iwdg.h"
+#include "mcu/stm32_hal.h"
IWDG_HandleTypeDef g_wdt_cfg;
@@ -40,6 +39,7 @@ hal_watchdog_init(uint32_t expire_msecs)
g_wdt_cfg.Instance = IWDG;
g_wdt_cfg.Init.Prescaler = IWDG_PRESCALER_256;
g_wdt_cfg.Init.Reload = reload;
+ STM32_HAL_WATCHDOG_CUSTOM_INIT(&g_wdt_cfg);
return 0;
}
@@ -56,4 +56,3 @@ hal_watchdog_tickle(void)
{
HAL_IWDG_Refresh(&g_wdt_cfg);
}
-
diff --git a/hw/mcu/stm/stm32f4xx/src/stm32f4xx_hw_id.c b/hw/mcu/stm/stm32_common/src/stm32_hw_id.c
similarity index 88%
rename from hw/mcu/stm/stm32f4xx/src/stm32f4xx_hw_id.c
rename to hw/mcu/stm/stm32_common/src/stm32_hw_id.c
index 19f99db..4dad67a 100644
--- a/hw/mcu/stm/stm32f4xx/src/stm32f4xx_hw_id.c
+++ b/hw/mcu/stm/stm32_common/src/stm32_hw_id.c
@@ -20,23 +20,20 @@
#include <inttypes.h>
#include <string.h>
+#include "mcu/stm32_hal.h"
#include <hal/hal_bsp.h>
#ifndef min
#define min(a, b) ((a)<(b)?(a):(b))
#endif
-/*
- * STM32F4 has a unique 96-bit id at address 0x1FFF7A10.
- * See ref manual chapter 39.1.
- */
int
hal_bsp_hw_id(uint8_t *id, int max_len)
{
int cnt;
cnt = min(12, max_len);
- memcpy(id, (void *)0x1FFF7A10, cnt);
+ memcpy(id, (void *)STM32_HW_ID_ADDR, cnt);
return cnt;
}
diff --git a/hw/mcu/stm/stm32f1xx/src/stm32f1xx_hw_id.c b/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
similarity index 68%
rename from hw/mcu/stm/stm32f1xx/src/stm32f1xx_hw_id.c
rename to hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
index 9fac0a3..9dc7e87 100644
--- a/hw/mcu/stm/stm32f1xx/src/stm32f1xx_hw_id.c
+++ b/hw/mcu/stm/stm32f1xx/include/mcu/stm32_hal.h
@@ -17,26 +17,34 @@
* under the License.
*/
-#include <inttypes.h>
-#include <string.h>
+#ifndef STM32_HAL_H
+#define STM32_HAL_H
-#include <hal/hal_bsp.h>
-
-#ifndef min
-#define min(a, b) ((a)<(b)?(a):(b))
+#ifdef __cplusplus
+extern "C" {
#endif
-/*
+#include <mcu/cortex_m3.h>
+
+#include "stm32f1xx_hal.h"
+#include "stm32f1xx_hal_def.h"
+
+/* hal_watchdog */
+#include "stm32f1xx_hal_iwdg.h"
+#define STM32_HAL_WATCHDOG_CUSTOM_INIT(x)
+
+/* 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.
*/
-int
-hal_bsp_hw_id(uint8_t *id, int max_len)
-{
- int cnt;
-
- cnt = min(12, max_len);
- memcpy(id, (void *)0x1FFFF7E8, cnt);
+#define STM32_HW_ID_ADDR 0x1FFFF7E8
- return cnt;
+#ifdef __cplusplus
}
+#endif
+
+#endif /* STM32_HAL_H */
diff --git a/hw/mcu/stm/stm32f1xx/pkg.yml b/hw/mcu/stm/stm32f1xx/pkg.yml
index 919a3e0..d7bb5b8 100644
--- a/hw/mcu/stm/stm32f1xx/pkg.yml
+++ b/hw/mcu/stm/stm32f1xx/pkg.yml
@@ -35,5 +35,5 @@ pkg.ign_dirs:
pkg.deps:
- hw/hal
- - hw/mcu/stm/stm32f1xx
+ - hw/mcu/stm/stm32_common
- hw/cmsis-core
diff --git a/hw/mcu/stm/stm32f1xx/src/hal_os_tick.c b/hw/mcu/stm/stm32f1xx/src/hal_os_tick.c
deleted file mode 100644
index 46b935a..0000000
--- a/hw/mcu/stm/stm32f1xx/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/stm32f1xx/src/hal_system.c b/hw/mcu/stm/stm32f1xx/src/hal_system.c
deleted file mode 100644
index e6408af..0000000
--- a/hw/mcu/stm/stm32f1xx/src/hal_system.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 <mcu/cortex_m3.h>
-#include <os/os.h>
-#include "hal/hal_system.h"
-#include "stm32f1xx_hal_def.h"
-
-void
-hal_system_reset(void)
-{
- while (1) {
- if (hal_debugger_connected()) {
- /*
- * If debugger is attached, breakpoint here.
- */
- asm("bkpt");
- }
- NVIC_SystemReset();
- }
-}
-
-int
-hal_debugger_connected(void)
-{
- return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
-}
-
-uint32_t
-HAL_GetTick(void)
-{
- return os_time_get();
-}
-
-HAL_StatusTypeDef
-HAL_InitTick (uint32_t TickPriority)
-{
- return HAL_OK;
-}
diff --git a/hw/mcu/stm/stm32f1xx/src/hal_system_start.c b/hw/mcu/stm/stm32f1xx/src/hal_system_start.c
deleted file mode 100644
index 5e9dee4..0000000
--- a/hw/mcu/stm/stm32f1xx/src/hal_system_start.c
+++ /dev/null
@@ -1,54 +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_m3.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. */
- //SYSCFG->MEMRMP = 0;
- //__DSB();
-
- /* Jump to image. */
- fn();
-}
-
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
similarity index 56%
rename from hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
rename to hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
index 4d55151..ce4442f 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_watchdog.c
+++ b/hw/mcu/stm/stm32f4xx/include/mcu/stm32_hal.h
@@ -17,43 +17,38 @@
* under the License.
*/
-#include "hal/hal_watchdog.h"
-#include "stm32f4xx_hal.h"
-#include "stm32f4xx_hal_iwdg.h"
+#ifndef STM32_HAL_H
+#define STM32_HAL_H
-IWDG_HandleTypeDef g_wdt_cfg;
+#ifdef __cplusplus
+extern "C" {
+#endif
-int
-hal_watchdog_init(uint32_t expire_msecs)
-{
- uint32_t reload;
+#include <mcu/cortex_m4.h>
- /* Max prescaler is 256 */
- reload = 32768 / 256;
- reload = (reload * expire_msecs) / 1000;
+#include "stm32f4xx_hal.h"
+#include "stm32f4xx_hal_def.h"
- /* Check to make sure we are not trying a reload value that is too large */
- if (reload > IWDG_RLR_RL) {
- return -1;
- }
+/* hal_watchdog */
+#include "stm32f4xx_hal_iwdg.h"
+#define STM32_HAL_WATCHDOG_CUSTOM_INIT(x)
- g_wdt_cfg.Instance = IWDG;
- g_wdt_cfg.Init.Prescaler = IWDG_PRESCALER_256;
- g_wdt_cfg.Init.Reload = reload;
+/* hal_system_start */
+#define STM32_HAL_FLASH_REMAP() \
+ do { \
+ SYSCFG->MEMRMP = 0; \
+ __DSB(); \
+ } while (0)
- return 0;
-}
-
-void
-hal_watchdog_enable(void)
-{
- __HAL_DBGMCU_FREEZE_IWDG();
- HAL_IWDG_Init(&g_wdt_cfg);
-}
+/* 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
-void
-hal_watchdog_tickle(void)
-{
- HAL_IWDG_Refresh(&g_wdt_cfg);
+#ifdef __cplusplus
}
+#endif
+#endif /* STM32_HAL_H */
diff --git a/hw/mcu/stm/stm32f4xx/pkg.yml b/hw/mcu/stm/stm32f4xx/pkg.yml
index 2ebebba..0b56024 100644
--- a/hw/mcu/stm/stm32f4xx/pkg.yml
+++ b/hw/mcu/stm/stm32f4xx/pkg.yml
@@ -41,7 +41,7 @@ pkg.ign_files:
pkg.ign_dirs:
- "Device"
-pkg.deps:
- - hw/hal
- - hw/mcu/stm/stm32f4xx
+pkg.deps:
+ - hw/hal
+ - hw/mcu/stm/stm32_common
- hw/cmsis-core
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c b/hw/mcu/stm/stm32f4xx/src/hal_os_tick.c
deleted file mode 100644
index 46b935a..0000000
--- a/hw/mcu/stm/stm32f4xx/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/stm32f7xx/src/stm32f7xx_hw_id.c b/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
similarity index 53%
rename from hw/mcu/stm/stm32f7xx/src/stm32f7xx_hw_id.c
rename to hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
index 6847569..9187517 100644
--- a/hw/mcu/stm/stm32f7xx/src/stm32f7xx_hw_id.c
+++ b/hw/mcu/stm/stm32f7xx/include/mcu/stm32_hal.h
@@ -17,26 +17,42 @@
* under the License.
*/
-#include <inttypes.h>
-#include <string.h>
+#ifndef STM32_HAL_H
+#define STM32_HAL_H
-#include <hal/hal_bsp.h>
-
-#ifndef min
-#define min(a, b) ((a)<(b)?(a):(b))
+#ifdef __cplusplus
+extern "C" {
#endif
-/*
+#include <mcu/cortex_m7.h>
+
+#include "stm32f7xx_hal.h"
+#include "stm32f7xx_hal_def.h"
+
+/* hal_watchdog */
+#include "stm32f7xx_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 { \
+ SYSCFG->MEMRMP = 0; \
+ SCB_InvalidateICache(); \
+ __DSB(); \
+ } while (0)
+
+/* stm32_hw_id
+ *
* STM32F7 has a unique 96-bit id at address 0x1FF0F420.
* See ref manual chapter 45.1.
*/
-int
-hal_bsp_hw_id(uint8_t *id, int max_len)
-{
- int cnt;
-
- cnt = min(12, max_len);
- memcpy(id, (void *)0x1FF0F420, cnt);
+#define STM32_HW_ID_ADDR 0x1FF0F420
- return cnt;
+#ifdef __cplusplus
}
+#endif
+
+#endif /* STM32_HAL_H */
diff --git a/hw/mcu/stm/stm32f7xx/pkg.yml b/hw/mcu/stm/stm32f7xx/pkg.yml
index f82185b..e0df78f 100644
--- a/hw/mcu/stm/stm32f7xx/pkg.yml
+++ b/hw/mcu/stm/stm32f7xx/pkg.yml
@@ -35,5 +35,5 @@ pkg.ign_dirs:
pkg.deps:
- hw/hal
- - hw/mcu/stm/stm32f7xx
+ - hw/mcu/stm/stm32_common
- hw/cmsis-core
diff --git a/hw/mcu/stm/stm32f7xx/src/hal_os_tick.c b/hw/mcu/stm/stm32f7xx/src/hal_os_tick.c
deleted file mode 100644
index 46b935a..0000000
--- a/hw/mcu/stm/stm32f7xx/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/stm32f7xx/src/hal_system.c b/hw/mcu/stm/stm32f7xx/src/hal_system.c
deleted file mode 100644
index fa50ead..0000000
--- a/hw/mcu/stm/stm32f7xx/src/hal_system.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 <mcu/cortex_m7.h>
-#include <os/os.h>
-#include "hal/hal_system.h"
-#include "stm32f7xx_hal_def.h"
-
-void
-hal_system_reset(void)
-{
- while (1) {
- if (hal_debugger_connected()) {
- /*
- * If debugger is attached, breakpoint here.
- */
- asm("bkpt");
- }
- NVIC_SystemReset();
- }
-}
-
-int
-hal_debugger_connected(void)
-{
- return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
-}
-
-uint32_t
-HAL_GetTick(void)
-{
- return os_time_get();
-}
-
-HAL_StatusTypeDef
-HAL_InitTick (uint32_t TickPriority)
-{
- return HAL_OK;
-}
diff --git a/hw/mcu/stm/stm32f7xx/src/hal_system_start.c b/hw/mcu/stm/stm32f7xx/src/hal_system_start.c
deleted file mode 100644
index d18bb21..0000000
--- a/hw/mcu/stm/stm32f7xx/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_m7.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. */
- SYSCFG->MEMRMP = 0;
- SCB_InvalidateICache();
- __DSB();
-
- /* Jump to image. */
- fn();
-}
-
diff --git a/hw/mcu/stm/stm32f7xx/src/hal_watchdog.c b/hw/mcu/stm/stm32f7xx/src/hal_watchdog.c
deleted file mode 100644
index 0d869b2..0000000
--- a/hw/mcu/stm/stm32f7xx/src/hal_watchdog.c
+++ /dev/null
@@ -1,59 +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 "stm32f7xx_hal.h"
-#include "stm32f7xx_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/stm32l1xx/src/stm32l1xx_hw_id.c b/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
similarity index 62%
rename from hw/mcu/stm/stm32l1xx/src/stm32l1xx_hw_id.c
rename to hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
index 41ef2f9..5cdcfd8 100644
--- a/hw/mcu/stm/stm32l1xx/src/stm32l1xx_hw_id.c
+++ b/hw/mcu/stm/stm32l1xx/include/mcu/stm32_hal.h
@@ -17,29 +17,39 @@
* under the License.
*/
-#include <inttypes.h>
-#include <string.h>
+#ifndef STM32_HAL_H
+#define STM32_HAL_H
-#include <hal/hal_bsp.h>
-
-#ifndef min
-#define min(a, b) ((a)<(b)?(a):(b))
+#ifdef __cplusplus
+extern "C" {
#endif
-/*
+#include <mcu/cortex_m3.h>
+
+#include "stm32l1xx_hal.h"
+#include "stm32l1xx_hal_def.h"
+
+/* hal_watchdog */
+#include "stm32l1xx_hal_iwdg.h"
+#define STM32_HAL_WATCHDOG_CUSTOM_INIT(x)
+
+/* hal_system_start */
+#define STM32_HAL_FLASH_REMAP() \
+ do { \
+ SYSCFG->MEMRMP = 0; \
+ __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.
*/
-int
-hal_bsp_hw_id(uint8_t *id, int max_len)
-{
- int cnt;
-
- cnt = min(12, max_len);
-
- /* 96-bit id address for STM32L152C */
- memcpy(id, (void *)0x1FF800D0, cnt);
+#define STM32_HW_ID_ADDR 0x1FF800D0
- return cnt;
+#ifdef __cplusplus
}
+#endif
+
+#endif /* STM32_HAL_H */
diff --git a/hw/mcu/stm/stm32l1xx/pkg.yml b/hw/mcu/stm/stm32l1xx/pkg.yml
index 713c798..64e8222 100644
--- a/hw/mcu/stm/stm32l1xx/pkg.yml
+++ b/hw/mcu/stm/stm32l1xx/pkg.yml
@@ -35,5 +35,5 @@ pkg.ign_dirs:
pkg.deps:
- hw/hal
- - hw/mcu/stm/stm32l1xx
+ - hw/mcu/stm/stm32_common
- hw/cmsis-core
diff --git a/hw/mcu/stm/stm32l1xx/src/hal_system.c b/hw/mcu/stm/stm32l1xx/src/hal_system.c
deleted file mode 100644
index 7dc83fc..0000000
--- a/hw/mcu/stm/stm32l1xx/src/hal_system.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 <mcu/cortex_m3.h>
-#include <os/os.h>
-#include "hal/hal_system.h"
-#include "stm32l1xx_hal_def.h"
-
-void
-hal_system_reset(void)
-{
- while (1) {
- if (hal_debugger_connected()) {
- /*
- * If debugger is attached, breakpoint here.
- */
- asm("bkpt");
- }
- NVIC_SystemReset();
- }
-}
-
-int
-hal_debugger_connected(void)
-{
- return CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
-}
-
-uint32_t
-HAL_GetTick(void)
-{
- return os_time_get();
-}
-
-HAL_StatusTypeDef
-HAL_InitTick (uint32_t TickPriority)
-{
- return HAL_OK;
-}
diff --git a/hw/mcu/stm/stm32l1xx/src/hal_system_start.c b/hw/mcu/stm/stm32l1xx/src/hal_system_start.c
deleted file mode 100644
index 872558b..0000000
--- a/hw/mcu/stm/stm32l1xx/src/hal_system_start.c
+++ /dev/null
@@ -1,54 +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_m3.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. */
- SYSCFG->MEMRMP = 0;
- __DSB();
-
- /* Jump to image. */
- fn();
-}
-
diff --git a/hw/mcu/stm/stm32l1xx/src/hal_watchdog.c b/hw/mcu/stm/stm32l1xx/src/hal_watchdog.c
deleted file mode 100644
index 1183fc3..0000000
--- a/hw/mcu/stm/stm32l1xx/src/hal_watchdog.c
+++ /dev/null
@@ -1,59 +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 "stm32l1xx_hal.h"
-#include "stm32l1xx_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;
-
- 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);
-}
-
--
To stop receiving notification emails like this one, please contact
utzig@apache.org.