Skip to content

Commit 82cdead

Browse files
authored
Merge pull request #1291 from fpistm/WB_fix
WB enhancements
2 parents a12e123 + 89e2f09 commit 82cdead

File tree

18 files changed

+387
-445
lines changed

18 files changed

+387
-445
lines changed

cores/arduino/board.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "digital_io.h"
1313
#include "dwt.h"
1414
#include "hw_config.h"
15+
#include "otp.h"
1516
#include "timer.h"
1617
#include "uart.h"
1718

cores/arduino/stm32/clock.h

+14-36
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,15 @@
1-
/**
2-
******************************************************************************
3-
* @file clock.h
4-
* @author WI6LABS
5-
* @version V1.0.0
6-
* @date 01-August-2016
7-
* @brief Header for clock.c module
8-
******************************************************************************
9-
* @attention
10-
*
11-
* <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
12-
*
13-
* Redistribution and use in source and binary forms, with or without modification,
14-
* are permitted provided that the following conditions are met:
15-
* 1. Redistributions of source code must retain the above copyright notice,
16-
* this list of conditions and the following disclaimer.
17-
* 2. Redistributions in binary form must reproduce the above copyright notice,
18-
* this list of conditions and the following disclaimer in the documentation
19-
* and/or other materials provided with the distribution.
20-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
21-
* may be used to endorse or promote products derived from this software
22-
* without specific prior written permission.
23-
*
24-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34-
*
35-
******************************************************************************
36-
*/
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2016-2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
3713

3814
/* Define to prevent recursive inclusion -------------------------------------*/
3915
#ifndef __CLOCK_H
@@ -62,6 +38,8 @@ uint32_t getCurrentMillis(void);
6238
uint32_t getCurrentMicros(void);
6339

6440
void enableClock(sourceClock_t source);
41+
void configHSECapacitorTuning(void);
42+
6543
#ifdef __cplusplus
6644
}
6745
#endif

cores/arduino/stm32/lock_resource.h

+168-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
/**
2-
******************************************************************************
3-
* @file lock_resource.h
4-
* @author MCD Application Team
5-
* @brief Header for lock_resource.c
6-
******************************************************************************
7-
* @attention
8-
*
9-
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10-
* All rights reserved.</center></h2>
11-
*
12-
* This software component is licensed by ST under BSD 3-Clause license,
13-
* the "License"; You may not use this file except in compliance with the
14-
* License. You may obtain a copy of the License at:
15-
* opensource.org/licenses/BSD-3-Clause
16-
*
17-
******************************************************************************
18-
*/
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2019-2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
1913
/* Define to prevent recursive inclusion -------------------------------------*/
2014
#ifndef _LOCK_RESOURCE_H
2115
#define _LOCK_RESOURCE_H
2216

2317
/* Includes ------------------------------------------------------------------*/
2418
#include "stm32_def.h"
19+
#include "stm32yyxx_ll_hsem.h"
2520

2621
#ifdef __cplusplus
2722
extern "C" {
@@ -35,15 +30,163 @@ typedef enum {
3530
} LockResource_Status_t;
3631

3732
/* Exported constants --------------------------------------------------------*/
38-
#define LOCK_RESOURCE_TIMEOUT 100U /* timeout in ms */
33+
#if defined(STM32WBxx)
34+
/*
35+
* HW semaphore Complement ID list defined in hw_conf.h from STM32WB.
36+
* They could be used also for H7 dualcore targets.
37+
*/
38+
/*
39+
* Index of the semaphore used by CPU2 to prevent the CPU1 to either write or
40+
* erase data in flash. The CPU1 shall not either write or erase in flash when
41+
* this semaphore is taken by the CPU2. When the CPU1 needs to either write or
42+
* erase in flash, it shall first get the semaphore and release it just
43+
* after writing a raw (64bits data) or erasing one sector.
44+
* On v1.4.0 and older CPU2 wireless firmware, this semaphore is unused and
45+
* CPU2 is using PES bit. By default, CPU2 is using the PES bit to protect its
46+
* timing. The CPU1 may request the CPU2 to use the semaphore instead of the
47+
* PES bit by sending the system command SHCI_C2_SetFlashActivityControl()
48+
*/
49+
#define CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID 7U
3950

40-
/* Exported macro ------------------------------------------------------------*/
41-
#define PERIPH_LOCK(__Periph__) Periph_Lock(__Periph__, LOCK_RESOURCE_TIMEOUT)
42-
#define PERIPH_UNLOCK(__Periph__) Periph_Unlock(__Periph__)
51+
/*
52+
* Index of the semaphore used by CPU1 to prevent the CPU2 to either write or
53+
* erase data in flash. In order to protect its timing, the CPU1 may get this
54+
* semaphore to prevent the CPU2 to either write or erase in flash
55+
* (as this will stall both CPUs)
56+
* The PES bit shall not be used as this may stall the CPU2 in some cases.
57+
*/
58+
#define CFG_HW_BLOCK_FLASH_REQ_BY_CPU1_SEMID 6U
4359

44-
/* Exported functions ------------------------------------------------------- */
45-
LockResource_Status_t Periph_Lock(void *Peripheral, uint32_t Timeout);
46-
void Periph_Unlock(void *Peripheral);
60+
/*
61+
* Index of the semaphore used to manage the CLK48 clock configuration
62+
* When the USB is required, this semaphore shall be taken before configuring
63+
* the CLK48 for USB and should be released after the application switch OFF
64+
* the clock when the USB is not used anymore. When using the RNG, it is good
65+
* enough to use CFG_HW_RNG_SEMID to control CLK48.
66+
* More details in AN5289
67+
*/
68+
#define CFG_HW_CLK48_CONFIG_SEMID 5U
69+
#define CFG_HW_RCC_CRRCR_CCIPR_SEMID CFG_HW_CLK48_CONFIG_SEMID
70+
71+
/* Index of the semaphore used to manage the entry Stop Mode procedure */
72+
#define CFG_HW_ENTRY_STOP_MODE_SEMID 4U
73+
#define CFG_HW_ENTRY_STOP_MODE_MASK_SEMID (1U << CFG_HW_ENTRY_STOP_MODE_SEMID)
74+
75+
/* Index of the semaphore used to access the RCC */
76+
#define CFG_HW_RCC_SEMID 3U
77+
78+
/* Index of the semaphore used to access the FLASH */
79+
#define CFG_HW_FLASH_SEMID 2U
80+
81+
/* Index of the semaphore used to access the PKA */
82+
#define CFG_HW_PKA_SEMID 1U
83+
84+
/* Index of the semaphore used to access the RNG */
85+
#define CFG_HW_RNG_SEMID 0U
86+
87+
/* Index of the semaphore used to access GPIO */
88+
#define CFG_HW_GPIO_SEMID 8U
89+
90+
/* Index of the semaphore used to access the EXTI */
91+
#define CFG_HW_EXTI_SEMID 9U
92+
93+
#elif defined(STM32MP1xx)
94+
/*
95+
* HW semaphore from STM32MP1
96+
* EXTI and GPIO are inherited from STM32MP1 Linux.
97+
* Other SEMID are not used by linux and must not be used here,
98+
* but reserved for MPU.
99+
*/
100+
/* Index of the semaphore used to access GPIO */
101+
#define CFG_HW_GPIO_SEMID 0U
102+
103+
/* Index of the semaphore used to access the EXTI */
104+
#define CFG_HW_EXTI_SEMID 1U
105+
#endif /* STM32WBxx */
106+
107+
/* Fake semaphore ID definition for compilation purpose only */
108+
#ifndef HSEM_SEMID_MAX
109+
#define HSEM_SEMID_MAX 0U
110+
#endif
111+
#ifndef CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID
112+
#define CFG_HW_BLOCK_FLASH_REQ_BY_CPU2_SEMID (HSEM_SEMID_MAX +1)
113+
#endif
114+
#ifndef CFG_HW_BLOCK_FLASH_REQ_BY_CPU1_SEMID
115+
#define CFG_HW_BLOCK_FLASH_REQ_BY_CPU1_SEMID (HSEM_SEMID_MAX +1)
116+
#endif
117+
#ifndef CFG_HW_CLK48_CONFIG_SEMID
118+
#define CFG_HW_CLK48_CONFIG_SEMID (HSEM_SEMID_MAX +1)
119+
#endif
120+
#ifndef CFG_HW_RCC_CRRCR_CCIPR_SEMID
121+
#define CFG_HW_RCC_CRRCR_CCIPR_SEMID (HSEM_SEMID_MAX +1)
122+
#endif
123+
#ifndef CFG_HW_ENTRY_STOP_MODE_SEMID
124+
#define CFG_HW_ENTRY_STOP_MODE_SEMID (HSEM_SEMID_MAX +1)
125+
#endif
126+
#ifndef CFG_HW_RCC_SEMID
127+
#define CFG_HW_RCC_SEMID (HSEM_SEMID_MAX +1)
128+
#endif
129+
#ifndef CFG_HW_FLASH_SEMID
130+
#define CFG_HW_FLASH_SEMID (HSEM_SEMID_MAX +1)
131+
#endif
132+
#ifndef CFG_HW_PKA_SEMID
133+
#define CFG_HW_PKA_SEMID (HSEM_SEMID_MAX +1)
134+
#endif
135+
#ifndef CFG_HW_RNG_SEMID
136+
#define CFG_HW_RNG_SEMID (HSEM_SEMID_MAX +1)
137+
#endif
138+
#ifndef CFG_HW_GPIO_SEMID
139+
#define CFG_HW_GPIO_SEMID (HSEM_SEMID_MAX +1)
140+
#endif
141+
#ifndef CFG_HW_EXTI_SEMID
142+
#define CFG_HW_EXTI_SEMID (HSEM_SEMID_MAX +1)
143+
#endif
144+
145+
/* Hardware Semaphore wait forever value */
146+
#define HSEM_LOCK_WAIT_FOREVER 0xFFFFFFFFU
147+
/* Hardware Semaphore default retry value */
148+
#ifndef HSEM_LOCK_DEFAULT_RETRY
149+
#define HSEM_LOCK_DEFAULT_RETRY 0xFFFFU
150+
#endif
151+
152+
/*
153+
* @brief hsem_lock function is used for register protection of shared Peripheral
154+
* and shall be called before accessing registers of this shared Peripheral
155+
* If Semaphore id is already taken, the function will busy loop waiting for it to
156+
* be released, but give up after @retry downcounter have elapsed
157+
* @param semID: Semaphore id used to identify which peripheral to protect
158+
* @param retry: number of retry
159+
* @retval None
160+
*/
161+
static inline void hsem_lock(uint32_t semID, uint32_t retry)
162+
{
163+
#if defined(STM32MP1xx) || defined(STM32WBxx)
164+
if ((semID) <= HSEM_SEMID_MAX) {
165+
while (LL_HSEM_1StepLock(HSEM, semID)) {
166+
if (retry != HSEM_LOCK_WAIT_FOREVER) {
167+
retry--;
168+
if (retry == 0) {
169+
Error_Handler();
170+
}
171+
}
172+
}
173+
}
174+
#endif /* STM32MP1xx || STM32WBxx */
175+
}
176+
177+
/*
178+
* @brief hsem_unlock released a previously-acquired semaphore
179+
* @param semID Semaphore id used to identify which peripheral to release
180+
* @retval None
181+
*/
182+
static inline void hsem_unlock(uint32_t semID)
183+
{
184+
#if defined(STM32MP1xx) || defined(STM32WBxx)
185+
if ((semID) <= HSEM_SEMID_MAX) {
186+
LL_HSEM_ReleaseLock(HSEM, semID, 0);
187+
}
188+
#endif /* STM32MP1xx || STM32WBxx */
189+
}
47190

48191
#ifdef __cplusplus
49192
} // extern "C"

cores/arduino/stm32/otp.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
14+
/* Define to prevent recursive inclusion -------------------------------------*/
15+
#ifndef __OTP_H
16+
#define __OTP_H
17+
18+
#include "stm32_def.h"
19+
20+
#ifdef OTP_AREA_BASE
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
#ifdef STM32WBxx
26+
/*
27+
* See AN5042: Precise HSE frequency and startup time tuning
28+
* for STM32 wireless MCUs. Each OTP structure type is indicated
29+
* by its index (one byte).The index used for the BT structure is 0.
30+
*/
31+
typedef struct __packed {
32+
uint8_t bd_address[6];
33+
uint8_t hse_tuning;
34+
uint8_t id;
35+
} OTP_BT_t;
36+
#endif /* STM32WBxx */
37+
38+
/* Exported functions --------------------------------------------------------*/
39+
40+
/**
41+
* @brief This API return the address (64 bits aligned) of the ID parameter in the OTP
42+
* It returns the first ID declaration found from the higher address down to the base address
43+
* The user shall fill the OTP from the base address to the top of the OTP so that the more recent
44+
* declaration is returned by the API
45+
* The OTP manager handles only 64 bits parameter
46+
* | Id | Parameter |
47+
* | 8bits | 58bits |
48+
* | MSB | LSB |
49+
*
50+
* @param id: ID of the parameter to read from OTP
51+
* @retval Address of the ID in the OTP - returns 0 when no ID found
52+
*/
53+
uint8_t *OTP_Read(uint8_t id);
54+
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
#endif /* OTP_AREA_BASE */
59+
#endif /*__OTP_H */
60+
61+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)