Skip to content

Commit d2a731a

Browse files
committed
[WB] Move OTP interface as a bsp
Signed-off-by: Frederic Pillon <[email protected]>
1 parent a12e123 commit d2a731a

File tree

5 files changed

+100
-65
lines changed

5 files changed

+100
-65
lines changed

cores/arduino/board.h

Lines changed: 1 addition & 0 deletions
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/otp.h

Lines changed: 61 additions & 0 deletions
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****/

libraries/SrcWrapper/src/stm32/otp.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include "otp.h"
15+
16+
#ifdef OTP_AREA_BASE
17+
18+
uint8_t *OTP_Read(uint8_t id)
19+
{
20+
uint8_t *p_id;
21+
22+
p_id = (uint8_t *)(OTP_AREA_END_ADDR - 7) ;
23+
24+
while (((*(p_id + 7)) != id) && (p_id != (uint8_t *)OTP_AREA_BASE)) {
25+
p_id -= 8 ;
26+
}
27+
28+
if ((*(p_id + 7)) != id) {
29+
p_id = 0 ;
30+
}
31+
32+
return p_id ;
33+
}
34+
35+
#endif /* OTP_AREA_BASE */
36+
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

variants/PNUCLEO_WB55RG/otp.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

variants/PNUCLEO_WB55RG/variant.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,14 @@ const PinName digitalPin[] = {
8989
extern "C" {
9090
#endif
9191

92-
static uint8_t *OTP_Read(uint8_t id)
93-
{
94-
uint8_t *p_id;
95-
96-
p_id = (uint8_t *)(CFG_OTP_END_ADDRESS - 7) ;
97-
98-
while (((*(p_id + 7)) != id) && (p_id != (uint8_t *)CFG_OTP_BASE_ADDRESS)) {
99-
p_id -= 8 ;
100-
}
101-
102-
if ((*(p_id + 7)) != id) {
103-
p_id = 0 ;
104-
}
105-
106-
return p_id ;
107-
}
108-
10992
static void Config_HSE(void)
11093
{
111-
OTP_ID0_t *p_otp;
94+
OTP_BT_t *p_otp;
11295

11396
/**
11497
* Read HSE_Tuning from OTP
11598
*/
116-
p_otp = (OTP_ID0_t *) OTP_Read(0);
99+
p_otp = (OTP_BT_t *) OTP_Read(0);
117100
if (p_otp) {
118101
LL_RCC_HSE_SetCapacitorTuning(p_otp->hse_tuning);
119102
}

0 commit comments

Comments
 (0)