Skip to content

Commit

Permalink
stm32: f24: flash: Make code match documentation
Browse files Browse the repository at this point in the history
This removes the shift from the defines, and includes them in the helper
function, making the code match the documentation, and following how the
rest of the library commonly operates.

Code using the existing defines will continue to work.
  • Loading branch information
karlp committed Jul 31, 2015
1 parent 07ee71c commit ec15c1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions include/libopencm3/stm32/common/flash_common_f24.h
Expand Up @@ -76,10 +76,12 @@
#define FLASH_CR_PG (1 << 0)
#define FLASH_CR_SNB_SHIFT 3
#define FLASH_CR_SNB_MASK 0x1f
#define FLASH_CR_PROGRAM_X8 (0x00 << 8)
#define FLASH_CR_PROGRAM_X16 (0x01 << 8)
#define FLASH_CR_PROGRAM_X32 (0x02 << 8)
#define FLASH_CR_PROGRAM_X64 (0x03 << 8)
#define FLASH_CR_PROGRAM_MASK 0x3
#define FLASH_CR_PROGRAM_SHIFT 8
#define FLASH_CR_PROGRAM_X8 0
#define FLASH_CR_PROGRAM_X16 1
#define FLASH_CR_PROGRAM_X32 2
#define FLASH_CR_PROGRAM_X64 3

/* --- FLASH_OPTCR values -------------------------------------------------- */

Expand Down
4 changes: 2 additions & 2 deletions lib/stm32/common/flash_common_f24.c
Expand Up @@ -38,8 +38,8 @@ programming manual for more information.

static inline void flash_set_program_size(uint32_t psize)
{
FLASH_CR &= ~(((1 << 0) | (1 << 1)) << 8);
FLASH_CR |= psize;
FLASH_CR &= ~(FLASH_CR_PROGRAM_MASK << FLASH_CR_PROGRAM_SHIFT);
FLASH_CR |= psize << FLASH_CR_PROGRAM_SHIFT;
}

/*---------------------------------------------------------------------------*/
Expand Down

0 comments on commit ec15c1c

Please sign in to comment.