Skip to content

Commit aff6ef0

Browse files
Merge pull request #152 from martinayotte/master
STM32F4 put back original bkp.* files (not symlink)
2 parents fe7bae2 + 52da419 commit aff6ef0

2 files changed

Lines changed: 295 additions & 2 deletions

File tree

STM32F4/cores/maple/libmaple/bkp.c

Lines changed: 0 additions & 1 deletion
This file was deleted.

STM32F4/cores/maple/libmaple/bkp.c

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/******************************************************************************
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 LeafLabs, LLC.
5+
*
6+
* Permission is hereby granted, free of charge, to any person
7+
* obtaining a copy of this software and associated documentation
8+
* files (the "Software"), to deal in the Software without
9+
* restriction, including without limitation the rights to use, copy,
10+
* modify, merge, publish, distribute, sublicense, and/or sell copies
11+
* of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*****************************************************************************/
26+
27+
/**
28+
* @file bkp.c
29+
* @brief Backup register support.
30+
*/
31+
32+
#include "bkp.h"
33+
#include "pwr.h"
34+
#include "rcc.h"
35+
#include "bitband.h"
36+
37+
static inline __io uint32* data_register(uint8 reg);
38+
39+
bkp_dev bkp = {
40+
.regs = BKP_BASE,
41+
};
42+
/** Backup device. */
43+
const bkp_dev *BKP = &bkp;
44+
45+
/**
46+
* @brief Initialize backup interface.
47+
*
48+
* Enables the power and backup interface clocks, and resets the
49+
* backup device.
50+
*/
51+
void bkp_init(void) {
52+
/* Don't call pwr_init(), or you'll reset the device. We just
53+
* need the clock. */
54+
rcc_clk_enable(RCC_PWR);
55+
rcc_clk_enable(RCC_BKP);
56+
rcc_reset_dev(RCC_BKP);
57+
}
58+
59+
/**
60+
* Enable write access to the backup registers. Backup interface must
61+
* be initialized for subsequent register writes to work.
62+
* @see bkp_init()
63+
*/
64+
void bkp_enable_writes(void) {
65+
*bb_perip(&PWR_BASE->CR, PWR_CR_DBP) = 1;
66+
}
67+
68+
/**
69+
* Disable write access to the backup registers.
70+
*/
71+
void bkp_disable_writes(void) {
72+
*bb_perip(&PWR_BASE->CR, PWR_CR_DBP) = 0;
73+
}
74+
75+
/**
76+
* Read a value from given backup data register.
77+
* @param reg Data register to read, from 1 to BKP_NR_DATA_REGS (10 on
78+
* medium-density devices, 42 on high-density devices).
79+
*/
80+
uint16 bkp_read(uint8 reg) {
81+
__io uint32* dr = data_register(reg);
82+
if (!dr) {
83+
ASSERT(0); /* nonexistent register */
84+
return 0;
85+
}
86+
return (uint16)*dr;
87+
}
88+
89+
/**
90+
* @brief Write a value to given data register.
91+
*
92+
* Write access to backup registers must be enabled.
93+
*
94+
* @param reg Data register to write, from 1 to BKP_NR_DATA_REGS (10
95+
* on medium-density devices, 42 on high-density devices).
96+
* @param val Value to write into the register.
97+
* @see bkp_enable_writes()
98+
*/
99+
void bkp_write(uint8 reg, uint16 val) {
100+
__io uint32* dr = data_register(reg);
101+
if (!dr) {
102+
ASSERT(0); /* nonexistent register */
103+
return;
104+
}
105+
*dr = (uint32)val;
106+
}
107+
108+
/*
109+
* Data register memory layout is not contiguous. It's split up from
110+
* 1--NR_LOW_DRS, beginning at BKP_BASE->DR1, through to
111+
* (NR_LOW_DRS+1)--BKP_NR_DATA_REGS, beginning at BKP_BASE->DR11.
112+
*/
113+
#define NR_LOW_DRS 10
114+
115+
static inline __io uint32* data_register(uint8 reg) {
116+
if (reg < 1 || reg > BKP_NR_DATA_REGS) {
117+
return 0;
118+
}
119+
120+
#if BKP_NR_DATA_REGS == NR_LOW_DRS
121+
return (uint32*)BKP_BASE + reg;
122+
#else
123+
if (reg <= NR_LOW_DRS) {
124+
return (uint32*)BKP_BASE + reg;
125+
} else {
126+
return (uint32*)&(BKP_BASE->DR11) + (reg - NR_LOW_DRS - 1);
127+
}
128+
#endif
129+
}

STM32F4/cores/maple/libmaple/bkp.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

STM32F4/cores/maple/libmaple/bkp.h

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/******************************************************************************
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 LeafLabs, LLC.
5+
*
6+
* Permission is hereby granted, free of charge, to any person
7+
* obtaining a copy of this software and associated documentation
8+
* files (the "Software"), to deal in the Software without
9+
* restriction, including without limitation the rights to use, copy,
10+
* modify, merge, publish, distribute, sublicense, and/or sell copies
11+
* of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*****************************************************************************/
26+
27+
/**
28+
* @file bkp.h
29+
* @brief Backup register support.
30+
*/
31+
32+
#ifndef _BKP_H_
33+
#define _BKP_H_
34+
35+
#include "libmaple.h"
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
#if defined(STM32_MEDIUM_DENSITY)
42+
#define BKP_NR_DATA_REGS 10
43+
#elif defined(STM32_HIGH_DENSITY)
44+
#define BKP_NR_DATA_REGS 42
45+
#endif
46+
47+
/** Backup peripheral register map type. */
48+
typedef struct bkp_reg_map {
49+
const uint32 RESERVED1; ///< Reserved
50+
__io uint32 DR1; ///< Data register 1
51+
__io uint32 DR2; ///< Data register 2
52+
__io uint32 DR3; ///< Data register 3
53+
__io uint32 DR4; ///< Data register 4
54+
__io uint32 DR5; ///< Data register 5
55+
__io uint32 DR6; ///< Data register 6
56+
__io uint32 DR7; ///< Data register 7
57+
__io uint32 DR8; ///< Data register 8
58+
__io uint32 DR9; ///< Data register 9
59+
__io uint32 DR10; ///< Data register 10
60+
__io uint32 RTCCR; ///< RTC control register
61+
__io uint32 CR; ///< Control register
62+
__io uint32 CSR; ///< Control and status register
63+
#ifdef STM32_HIGH_DENSITY
64+
const uint32 RESERVED2; ///< Reserved
65+
const uint32 RESERVED3; ///< Reserved
66+
__io uint32 DR11; ///< Data register 11
67+
__io uint32 DR12; ///< Data register 12
68+
__io uint32 DR13; ///< Data register 13
69+
__io uint32 DR14; ///< Data register 14
70+
__io uint32 DR15; ///< Data register 15
71+
__io uint32 DR16; ///< Data register 16
72+
__io uint32 DR17; ///< Data register 17
73+
__io uint32 DR18; ///< Data register 18
74+
__io uint32 DR19; ///< Data register 19
75+
__io uint32 DR20; ///< Data register 20
76+
__io uint32 DR21; ///< Data register 21
77+
__io uint32 DR22; ///< Data register 22
78+
__io uint32 DR23; ///< Data register 23
79+
__io uint32 DR24; ///< Data register 24
80+
__io uint32 DR25; ///< Data register 25
81+
__io uint32 DR26; ///< Data register 26
82+
__io uint32 DR27; ///< Data register 27
83+
__io uint32 DR28; ///< Data register 28
84+
__io uint32 DR29; ///< Data register 29
85+
__io uint32 DR30; ///< Data register 30
86+
__io uint32 DR31; ///< Data register 31
87+
__io uint32 DR32; ///< Data register 32
88+
__io uint32 DR33; ///< Data register 33
89+
__io uint32 DR34; ///< Data register 34
90+
__io uint32 DR35; ///< Data register 35
91+
__io uint32 DR36; ///< Data register 36
92+
__io uint32 DR37; ///< Data register 37
93+
__io uint32 DR38; ///< Data register 38
94+
__io uint32 DR39; ///< Data register 39
95+
__io uint32 DR40; ///< Data register 40
96+
__io uint32 DR41; ///< Data register 41
97+
__io uint32 DR42; ///< Data register 42
98+
#endif
99+
} bkp_reg_map;
100+
101+
/** Backup peripheral register map base pointer. */
102+
#define BKP_BASE ((struct bkp_reg_map*)0x40006C00)
103+
104+
/** Backup peripheral device type. */
105+
typedef struct bkp_dev {
106+
bkp_reg_map *regs; /**< Register map */
107+
} bkp_dev;
108+
109+
extern const bkp_dev *BKP;
110+
111+
/*
112+
* Register bit definitions
113+
*/
114+
115+
/* Data Registers */
116+
117+
#define BKP_DR_D 0xFFFF
118+
119+
/* RTC Clock Calibration Register */
120+
121+
#define BKP_RTCCR_ASOS_BIT 9
122+
#define BKP_RTCCR_ASOE_BIT 8
123+
#define BKP_RTCCR_CCO_BIT 7
124+
125+
#define BKP_RTCCR_ASOS BIT(BKP_RTCCR_ASOS_BIT)
126+
#define BKP_RTCCR_ASOE BIT(BKP_RTCCR_ASOE_BIT)
127+
#define BKP_RTCCR_CCO BIT(BKP_RTCCR_CCO_BIT)
128+
#define BKP_RTCCR_CAL 0x7F
129+
130+
/* Backup control register */
131+
132+
#define BKP_CR_TPAL_BIT 1
133+
#define BKP_CR_TPE_BIT 0
134+
135+
#define BKP_CR_TPAL BIT(BKP_CR_TPAL_BIT)
136+
#define BKP_CR_TPE BIT(BKP_CR_TPE_BIT)
137+
138+
/* Backup control/status register */
139+
140+
#define BKP_CSR_TIF_BIT 9
141+
#define BKP_CSR_TEF_BIT 8
142+
#define BKP_CSR_TPIE_BIT 2
143+
#define BKP_CSR_CTI_BIT 1
144+
#define BKP_CSR_CTE_BIT 0
145+
146+
#define BKP_CSR_TIF BIT(BKP_CSR_TIF_BIT)
147+
#define BKP_CSR_TEF BIT(BKP_CSR_TEF_BIT)
148+
#define BKP_CSR_TPIE BIT(BKP_CSR_TPIE_BIT)
149+
#define BKP_CSR_CTI BIT(BKP_CSR_CTI_BIT)
150+
#define BKP_CSR_CTE BIT(BKP_CSR_CTE_BIT)
151+
152+
/*
153+
* Convenience functions
154+
*/
155+
156+
void bkp_init(void);
157+
void bkp_enable_writes(void);
158+
void bkp_disable_writes(void);
159+
uint16 bkp_read(uint8 reg);
160+
void bkp_write(uint8 reg, uint16 val);
161+
162+
#ifdef __cplusplus
163+
} /* extern "C" */
164+
#endif
165+
166+
#endif

0 commit comments

Comments
 (0)