EasyManuals Logo

ST STM32F31xx User Manual

ST STM32F31xx
584 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #18 background imageLoading...
Page #18 background image
STM32F30xx Standard Peripheral Library
UM1581
18/584
DocID023800 Rev 1
Peripheral registers bits
All the peripheral registers bits are defined as constants in the stm32f30x.h file. They are
defined as acronyms written in upper-case into the form:
PPP_<register_name>_<bit_name>
Example:
#define SPI_CR1_CPHA ((uint16_t)0x0001) /*!< Clock Phase */
#define SPI_CR1_CPOL ((uint16_t)0x0002) /*!< Clock Polarity */
#define SPI_CR1_MSTR ((uint16_t)0x0004) /*!< Master Selection */
#define SPI_CR1_BR ((uint16_t)0x0038) /*!< BR[2:0] bits (Baud
Rate Control) */
#define SPI_CR1_BR_0 ((uint16_t)0x0008) /*!< Bit 0 */
#define SPI_CR1_BR_1 ((uint16_t)0x0010) /*!< Bit 1 */
#define SPI_CR1_BR_2 ((uint16_t)0x0020) /*!< Bit 2 */
1.1.4 Bit-Banding
The Cortex-M4 memory map includes two bit-band memory regions. These regions map
each word in an alias region of memory to a bit in a bit-band region of memory. Writing to a
word in the alias region has the same effect as a read/modify/write operation on the
targeted bit in the bit-band region.
All the STM32F30/F31xx peripheral registers are mapped in a bit-band region. This feature
is consequently intensively used functions performing single bit set/reset in order to reduce
and optimize code size.
The sections below describe how the bit-band access is used in the Library.
Mapping formula
The mapping formula shows how to link each word in the alias region to a corresponding
target bit in the bit-band region. The mapping formula is given below:
bit_word_offset = (byte_offset x 32) + (bit_number × 4)
bit_word_addr = bit_band_base + bit_word_offset
where:
ï‚· bit_word_offset is the position of the target bit in the bit-band memory region
ï‚· bit_word_addr is the address of the word in the alias memory region that maps to the
targeted bit.
ï‚· bit_band_base is the starting address of the alias region
ï‚· byte_offset is the number of the byte in the bit-band region that contains the targeted
bit
ï‚· bit_number is the bit position (0-7) of the targeted bit.
Example of implementation
The following example shows how to map the PLLON[24] bit of RCC_CR register in the
alias region:
...
/*!< Peripheral base address in the alias region */
#define PERIPH_BASE ((uint32_t)0x40000000)
...
/*!< Peripheral base address in the bit-band region */
#define PERIPH_BB_BASE ((uint32_t)0x42000000)
...

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the ST STM32F31xx and is the answer not in the manual?

ST STM32F31xx Specifications

General IconGeneral
BrandST
ModelSTM32F31xx
CategoryMicrocontrollers
LanguageEnglish

Related product manuals