More STM32C0-related work.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16352 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2023-07-30 11:40:16 +00:00
parent a636ba64c7
commit 1014f947e9
12 changed files with 333 additions and 37 deletions

View File

@ -72,7 +72,7 @@
* @note Allowed values are 16 or 32 bits.
*/
#if !defined(CH_CFG_ST_RESOLUTION)
#define CH_CFG_ST_RESOLUTION 32
#define CH_CFG_ST_RESOLUTION 16
#endif
/**

View File

@ -57,7 +57,7 @@
#define STM32_HSE_ENABLED FALSE
#define STM32_LSI_ENABLED TRUE
#define STM32_LSE_ENABLED TRUE
#define STM32_SW STM32_SW_PLLRCLK
#define STM32_SW STM32_SW_HSISYS
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE STM32_PPRE_DIV1
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
@ -72,7 +72,7 @@
#define STM32_USART1SEL STM32_USART1SEL_PCLK
#define STM32_I2C1SEL STM32_I2C1SEL_PCLK
#define STM32_I2S1SEL STM32_I2S1SEL_SYSCLK
#define STM32_ADCSEL STM32_ADCSEL_PLLPCLK
#define STM32_ADCSEL STM32_ADCSEL_SYSCLK
#define STM32_RTCSEL STM32_RTCSEL_NOCLOCK
/*

View File

@ -46,8 +46,8 @@
/* Handling differences in ST headers.*/
#if !defined(STM32H7XX) && !defined(STM32L4XX) && !defined(STM32L4XXP) && \
!defined(STM32G0XX) && !defined(STM32G4XX) && !defined(STM32WBXX) && \
!defined(STM32WLXX)
!defined(STM32C0XX) && !defined(STM32G0XX) && !defined(STM32G4XX) && \
!defined(STM32WBXX) && !defined(STM32WLXX)
#define EMR1 EMR
#define IMR1 IMR
#define PR1 PR

View File

@ -0,0 +1,92 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed 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.
*/
/**
* @file RCCv1/stm32_bd.inc
* @brief Shared backup domain handler.
*
* @addtogroup STM32_BD_V3_HANDLER
* @{
*/
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/**
* @brief Initializes the backup domain.
*/
__STATIC_INLINE void bd_init(void) {
uint32_t bdcr;
/* Current settings.*/
bdcr = RCC->CSR1;
#if HAL_USE_RTC
/* RTC enable.*/
if ((bdcr & RCC_CSR1_RTCEN) == 0U) {
bdcr |= RCC_CSR1_RTCEN;
}
#endif
/* Selectors.*/
bdcr &= ~(STM32_RTCSEL_MASK | STM32_LSCOSEL_MASK);
bdcr |= STM32_RTCSEL | STM32_LSCOSEL;
/* Final settings.*/
RCC->CSR1 = bdcr;
}
/**
* @brief Resets the backup domain.
* @note WARNING! Changing RTC clock source impossible without reset
* of the whole BKP domain.
*/
__STATIC_INLINE void bd_reset(void) {
/* Reset BKP domain if different clock source selected.*/
if ((RCC->CSR1 & STM32_RTCSEL_MASK) != STM32_RTCSEL) {
/* Backup domain reset.*/
RCC->CSR1 = RCC_CSR1_RTCRST;
RCC->CSR1 = 0U;
}
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/** @} */

View File

@ -95,7 +95,7 @@ __STATIC_INLINE void hsi48_disable(void) {
__STATIC_INLINE void hsi48_init(void) {
#if STM32_HSI48_ENABLED
#if (defined(RCC_CRRCR_HSI48ON) || defined(RCC_CR_HSI48ON)) && STM32_HSI48_ENABLED
/* HSI activation.*/
hsi48_enable();
#endif

View File

@ -0,0 +1,106 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed 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.
*/
/**
* @file RCCv1/stm32_lse_v3.inc
* @brief Shared LSE clock handler.
*
* @addtogroup STM32_LSE_V3_HANDLER
* @{
*/
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/* Registry checks for robustness.*/
#if !defined(STM32_RCC_HAS_LSE)
#error "STM32_RCC_HAS_LSE not defined in stm32_registry.h"
#endif
/* Checks on configurations.*/
#if !defined(STM32_LSE_ENABLED)
#error "STM32_LSE_ENABLED not defined in mcuconf.h"
#endif
#if !defined(STM32_LSECLK)
#error "STM32_LSECLK not defined in board.h"
#endif
#if !defined(STM32_LSEDRV)
#error "STM32_LSEDRV not defined in board.h"
#endif
/* Check on limits.*/
#if !defined(STM32_LSECLK_MAX)
#error "STM32_LSECLK_MAX not defined in hal_lld.h"
#endif
#if !defined(STM32_LSECLK_MIN)
#error "STM32_LSECLK_MIN not defined in hal_lld.h"
#endif
#if STM32_LSE_ENABLED
#if (STM32_LSECLK == 0)
#error "LSE frequency not defined"
#endif
#if (STM32_LSECLK < STM32_LSECLK_MIN) || (STM32_LSECLK > STM32_LSECLK_MAX)
#error "STM32_LSECLK outside acceptable range (STM32_LSECLK_MIN...STM32_LSECLK_MAX)"
#endif
#endif
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
__STATIC_INLINE void lse_init(void) {
#if STM32_LSE_ENABLED
/* LSE activation.*/
#if defined(STM32_LSE_BYPASS)
/* LSE Bypass.*/
RCC->CSR1 |= STM32_LSEDRV | RCC_CSR1_LSEON | RCC_CSR1_LSESYSEN | RCC_CSR1_LSEBYP;
#else
/* No LSE Bypass.*/
RCC->CSR1 |= STM32_LSEDRV | RCC_CSR1_LSEON;
while ((RCC->CSR1 & RCC_CSR1_LSERDY) != RCC_CSR1_LSERDY) {
}
#endif
#endif
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/** @} */

View File

@ -0,0 +1,113 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed 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.
*/
/**
* @file RCCv1/stm32_lsi.inc
* @brief Shared LSI clock handler.
*
* @addtogroup STM32_LSI_V3_HANDLER
* @{
*/
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/**
* @brief LSI clock frequency.
*/
#define STM32_LSIRCCLK 32000U
/**
* @name RCC_CSR2 register bits definitions
* @{
*/
#define STM32_LSIPRE_MASK (1U << RCC_CSR2_LSIPRE_Pos)
#define STM32_LSIPRE_NODIV (0U << RCC_CSR2_LSIPRE_Pos)
#define STM32_LSIPRE_DIV128 (1U << RCC_CSR2_LSIPRE_Pos)
/** @} */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/* Registry checks for robustness.*/
#if !defined(STM32_RCC_HAS_LSI)
#error "STM32_RCC_HAS_LSI not defined in stm32_registry.h"
#endif
#if !defined(STM32_RCC_HAS_LSI_PRESCALER)
#error "STM32_RCC_HAS_LSI_PRESCALER not defined in stm32_registry.h"
#endif
/* Checks on configurations.*/
#if !defined(STM32_LSI_ENABLED)
#error "STM32_LSI_ENABLED not defined in mcuconf.h"
#endif
#if STM32_RCC_HAS_LSI_PRESCALER || defined(__DOXYGEN__)
#if !defined(STM32_LSIPRE)
#error "STM32_LSIPRE not defined in mcuconf.h"
#endif
/**
* @brief LSI frequency.
*/
#if (STM32_LSIPRE == STM32_LSIPRE_NODIV) || defined(__DOXYGEN__)
#define STM32_LSICLK (STM32_LSIRCCLK)
#elif STM32_LSIPRE == STM32_LSIPRE_DIV128
#define STM32_LSICLK (STM32_LSIRCCLK / 128U)
#else
#error "invalid STM32_LSIPRE value specified"
#endif
#else /* !STM32_RCC_HAS_LSI_PRESCALER */
#define STM32_LSIPRE 0U
#define STM32_LSICLK (STM32_LSIRCCLK)
#endif /* !STM32_RCC_HAS_LSI_PRESCALER */
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
__STATIC_INLINE void lsi_init(void) {
#if STM32_LSI_ENABLED
/* LSI activation.*/
RCC->CSR2 |= STM32_LSIPRE | RCC_CSR2_LSION;
while ((RCC->CSR2 & RCC_CSR2_LSIRDY) == 0U) {
}
#endif
}
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/** @} */

View File

@ -61,8 +61,8 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WBXX) || defined(STM32WLXX)
#define ST_ENABLE_STOP() DBGMCU->APB1FZR1 |= DBGMCU_APB1FZR1_DBG_TIM1_STOP
#elif defined(STM32G0XX)
#define ST_ENABLE_STOP() DBG->APBFZ1 |= DBG_APB_FZ1_DBG_TIM1_STOP
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ2 |= DBG_APB_FZ2_DBG_TIM1_STOP
#elif defined(STM32H7XX)
#define ST_ENABLE_STOP() DBGMCU->APB1LFZ1 |= DBGMCU_APB1LFZ1_DBG_TIM1
#else
@ -88,7 +88,7 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WBXX) || defined(STM32WLXX)
#define ST_ENABLE_STOP() DBGMCU->APB1FZR1 |= DBGMCU_APB1FZR1_DBG_TIM2_STOP
#elif defined(STM32G0XX)
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ1 |= DBG_APB_FZ1_DBG_TIM2_STOP
#elif defined(STM32H7XX)
#define ST_ENABLE_STOP() DBGMCU->APB1LFZ1 |= DBGMCU_APB1LFZ1_DBG_TIM2
@ -115,7 +115,7 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WBXX)
#define ST_ENABLE_STOP() DBGMCU->APB1FZR1 |= DBGMCU_APB1FZR1_DBG_TIM3_STOP
#elif defined(STM32G0XX)
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ1 |= DBG_APB_FZ1_DBG_TIM3_STOP
#elif defined(STM32H7XX)
#define ST_ENABLE_STOP() DBGMCU->APB1LFZ1 |= DBGMCU_APB1LFZ1_DBG_TIM3
@ -344,6 +344,8 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WBXX)
#define ST_ENABLE_STOP() DBGMCU->APB1FZR1 |= DBGMCU_APB1FZR1_DBG_TIM14_STOP
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ2 |= DBG_APB_FZ2_DBG_TIM14_STOP
#elif defined(STM32H7XX)
#define ST_ENABLE_STOP() DBGMCU->APB1LFZ1 |= DBGMCU_APB1LFZ1_DBG_TIM14
#else
@ -394,6 +396,8 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WLXX)
#define ST_ENABLE_STOP() DBGMCU->APB2FZ |= DBGMCU_APB2FZ_DBG_TIM16_STOP
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ2 |= DBG_APB_FZ2_DBG_TIM16_STOP
#elif defined(STM32WBXX)
#define ST_ENABLE_STOP() DBGMCU->APB2FZR |= DBGMCU_APB2FZR_DBG_TIM16_STOP
#elif defined(STM32H7XX)
@ -421,6 +425,8 @@
#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX) || \
defined(STM32L5XX) || defined(STM32WLXX)
#define ST_ENABLE_STOP() DBGMCU->APB2FZ |= DBGMCU_APB2FZ_DBG_TIM17_STOP
#elif defined(STM32G0XX) || defined(STM32C0XX)
#define ST_ENABLE_STOP() DBG->APBFZ2 |= DBG_APB_FZ2_DBG_TIM17_STOP
#elif defined(STM32WBXX)
#define ST_ENABLE_STOP() DBGMCU->APB2FZR |= DBGMCU_APB2FZR_DBG_TIM17_STOP
#elif defined(STM32H7XX)

View File

@ -71,7 +71,7 @@ uint32_t SystemCoreClock = STM32_HCLK;
/* Driver local functions. */
/*===========================================================================*/
#include "stm32_bd.inc"
#include "stm32_bd_v3.inc"
/**
* @brief Safe setting of flash ACR register.

View File

@ -11,7 +11,7 @@
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.
limitations under the License.f
*/
/**
@ -121,26 +121,6 @@
#define STM32_SW_LSI (3U << 0)
#define STM32_SW_LSE (4U << 0)
#define STM32_HPRE_DIV_MASK (15U << 8)
#define STM32_HPRE_DIV_FIELD(n) ((n) << 8)
#define STM32_HPRE_DIV1 STM32_HPRE_DIV_FIELD(0U)
#define STM32_HPRE_DIV2 STM32_HPRE_DIV_FIELD(8U)
#define STM32_HPRE_DIV4 STM32_HPRE_DIV_FIELD(9U)
#define STM32_HPRE_DIV8 STM32_HPRE_DIV_FIELD(10U)
#define STM32_HPRE_DIV16 STM32_HPRE_DIV_FIELD(11U)
#define STM32_HPRE_DIV64 STM32_HPRE_DIV_FIELD(12U)
#define STM32_HPRE_DIV128 STM32_HPRE_DIV_FIELD(13U)
#define STM32_HPRE_DIV256 STM32_HPRE_DIV_FIELD(14U)
#define STM32_HPRE_DIV512 STM32_HPRE_DIV_FIELD(15U)
#define STM32_PPRE_DIV_MASK (15U << 12)
#define STM32_PPRE_DIV_FIELD(n) ((n) << 12)
#define STM32_PPRE_DIV1 STM32_PPRE_DIV_FIELD(0U)
#define STM32_PPRE_DIV2 STM32_PPRE_DIV_FIELD(4U)
#define STM32_PPRE_DIV4 STM32_PPRE_DIV_FIELD(5U)
#define STM32_PPRE_DIV8 STM32_PPRE_DIV_FIELD(6U)
#define STM32_PPRE_DIV16 STM32_PPRE_DIV_FIELD(7U)
#define STM32_MCO2SEL_MASK (7U << 16)
#define STM32_MCO2SEL_FIELD(n) ((n) << 16)
#define STM32_MCO2SEL_NOCLOCK STM32_MCO2SEL_FIELD(0U)
@ -524,8 +504,8 @@
/** @} */
/* Clock handlers.*/
#include "stm32_lse.inc"
#include "stm32_lsi.inc"
#include "stm32_lse_v3.inc"
#include "stm32_lsi_v3.inc"
#include "stm32_hsi48.inc"
#include "stm32_hse.inc"

View File

@ -1,8 +1,7 @@
# Required platform files.
PLATFORMSRC := $(CHIBIOS)/os/hal/ports/common/ARMCMx/nvic.c \
$(CHIBIOS)/os/hal/ports/STM32/STM32C0xx/stm32_isr.c \
$(CHIBIOS)/os/hal/ports/STM32/STM32C0xx/hal_lld.c \
$(CHIBIOS)/os/hal/ports/STM32/STM32C0xx/hal_efl_lld.c
$(CHIBIOS)/os/hal/ports/STM32/STM32C0xx/hal_lld.c
# Required include directories.
PLATFORMINC := $(CHIBIOS)/os/hal/ports/common/ARMCMx \

View File

@ -68,7 +68,7 @@
#define STM32_HSE_ENABLED ${doc.STM32_HSE_ENABLED!"FALSE"}
#define STM32_LSI_ENABLED ${doc.STM32_LSI_ENABLED!"FALSE"}
#define STM32_LSE_ENABLED ${doc.STM32_LSE_ENABLED!"FALSE"}
#define STM32_SW ${doc.STM32_SW!"STM32_SW_HSI48"}
#define STM32_SW ${doc.STM32_SW!"STM32_SW_HSISYS"}
#define STM32_HPRE ${doc.STM32_HPRE!"STM32_HPRE_DIV1"}
#define STM32_PPRE ${doc.STM32_PPRE!"STM32_PPRE_DIV1"}
#define STM32_MCOSEL ${doc.STM32_MCOSEL!"STM32_MCOSEL_NOCLOCK"}