Skip to content

Commit

Permalink
nrfx 1.7.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kl-cruz committed Apr 8, 2019
1 parent ab87d03 commit 9d68726
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All notable changes to this project are documented in this file.

## [1.7.1] - 2019-04-08
### Added
- Added functions in the NVMC driver for getting the flash page size, the count of pages and the total flash size.

### Fixed
- Fixed handling of short unaligned write requests (1 or 2 bytes in length) in the nrfx_nvmc_bytes_write() function.

## [1.7.0] - 2019-03-29
### Added
- Added drivers for NVMC and TEMP.
Expand Down
21 changes: 21 additions & 0 deletions drivers/include/nrfx_nvmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ void nrfx_nvmc_bytes_write(uint32_t address, void const * src, uint32_t num_byte
*/
void nrfx_nvmc_words_write(uint32_t address, void const * src, uint32_t num_words);

/**
* @brief Function for getting the total flash size in bytes.
*
* @return Flash total size in bytes.
*/
uint32_t nrfx_nvmc_flash_size_get(void);

/**
* @brief Function for getting the flash page size in bytes.
*
* @return Flash page size in bytes.
*/
uint32_t nrfx_nvmc_flash_page_size_get(void);

/**
* @brief Function for getting the flash page count.
*
* @return Flash page count.
*/
uint32_t nrfx_nvmc_flash_page_count_get(void);

/**
* @brief Function for checking if the last flash write has been completed.
*
Expand Down
87 changes: 55 additions & 32 deletions drivers/src/nrfx_nvmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
#define NVMC_BYTES_IN_WORD 4

/**
* Value representing non-volatile memory (NVM) total size in bytes.
* Value representing non-volatile memory (NVM) page count.
*
* This symbol is needed to determine NVM total size for chips that cannot
* This symbol is needed to determine NVM page count for chips that cannot
* always access FICR for this information.
*/
#if defined(NRF9160_XXAA)
#define NVMC_FLASH_TOTAL_SIZE 0x100000 ///< 1024 kB
#define NVMC_FLASH_PAGE_COUNT 256
#endif

/**
Expand Down Expand Up @@ -94,36 +94,42 @@ static uint32_t m_partial_erase_page_addr = NVMC_PARTIAL_ERASE_INVALID_ADDR;

#endif // defined(NRF_NVMC_PARTIAL_ERASE_PRESENT)

static uint32_t flash_total_size_get(void)
static uint32_t flash_page_size_get(void)
{
uint32_t flash_total_size = 0;
uint32_t flash_page_size = 0;

#if defined(NRF51) || defined(NRF52_SERIES)
flash_total_size = nrf_ficr_codepagesize_get(NRF_FICR) * nrf_ficr_codesize_get(NRF_FICR);
#elif defined(NVMC_FLASH_TOTAL_SIZE)
flash_total_size = NVMC_FLASH_TOTAL_SIZE;
flash_page_size = nrf_ficr_codepagesize_get(NRF_FICR);
#elif defined(NVMC_FLASH_PAGE_SIZE)
flash_page_size = NVMC_FLASH_PAGE_SIZE;
#else
#error "Cannot determine Flash total size for given SoC."
#error "Cannot determine flash page size for a given SoC."
#endif

return flash_total_size;
return flash_page_size;
}

static uint32_t flash_page_size_get(void)
static uint32_t flash_page_count_get(void)
{
uint32_t flash_page_size = 0;
uint32_t page_count = 0;

#if defined(NRF51) || defined(NRF52_SERIES)
flash_page_size = nrf_ficr_codepagesize_get(NRF_FICR);
#elif defined(NVMC_FLASH_PAGE_SIZE)
flash_page_size = NVMC_FLASH_PAGE_SIZE;
page_count = nrf_ficr_codesize_get(NRF_FICR);
#elif defined(NVMC_FLASH_PAGE_COUNT)
page_count = NVMC_FLASH_PAGE_COUNT;
#else
#error "Cannot determine Flash page size for given SoC."
#error "Cannot determine flash page count for a given SoC."
#endif

return flash_page_size;
return page_count;
}

static uint32_t flash_total_size_get(void)
{
return flash_page_size_get() * flash_page_count_get();
}


static bool is_page_aligned_check(uint32_t addr)
{
/* If the modulo operation returns '0', then the address is aligned. */
Expand Down Expand Up @@ -178,7 +184,7 @@ static void nvmc_erase_mode_set(void)

static void nvmc_word_write(uint32_t addr, uint32_t value)
{
#if defined(NVMC_READYNEXT_READYNEXT_Msk)
#if defined(NRF9160_XXAA)
while (!nrf_nvmc_write_ready_check(NRF_NVMC))
{}
#else
Expand Down Expand Up @@ -328,19 +334,22 @@ void nrfx_nvmc_bytes_write(uint32_t addr, void const * src, uint32_t num_bytes)

nvmc_write_mode_set();

uint32_t leftover = addr % NVMC_BYTES_IN_WORD;
uint8_t const * bytes_src = (uint8_t const *)src;

if (leftover != 0)
uint32_t unaligned_bytes = addr % NVMC_BYTES_IN_WORD;
if (unaligned_bytes != 0)
{
/* Deal with unaligned leading bytes */
nvmc_word_write(addr - leftover,
partial_word_create(addr, bytes_src, NVMC_BYTES_IN_WORD - leftover));

leftover = NVMC_BYTES_IN_WORD - leftover;
num_bytes -= leftover;
addr += leftover;
bytes_src += leftover;
uint32_t leading_bytes = NVMC_BYTES_IN_WORD - unaligned_bytes;
if (leading_bytes > num_bytes)
{
leading_bytes = num_bytes;
}

nvmc_word_write(addr - unaligned_bytes,
partial_word_create(addr, bytes_src, leading_bytes));
num_bytes -= leading_bytes;
addr += leading_bytes;
bytes_src += leading_bytes;
}

#if defined(__CORTEX_M) && (__CORTEX_M == 0U)
Expand Down Expand Up @@ -372,11 +381,10 @@ void nrfx_nvmc_bytes_write(uint32_t addr, void const * src, uint32_t num_bytes)
bytes_src += word_count * NVMC_BYTES_IN_WORD;
}

leftover = num_bytes % NVMC_BYTES_IN_WORD;
if (leftover != 0)
uint32_t trailing_bytes = num_bytes % NVMC_BYTES_IN_WORD;
if (trailing_bytes != 0)
{
/* Deal with unaligned trailing bytes */
nvmc_word_write(addr, partial_word_create(addr, bytes_src, leftover));
nvmc_word_write(addr, partial_word_create(addr, bytes_src, trailing_bytes));
}

nvmc_readonly_mode_set();
Expand All @@ -395,4 +403,19 @@ void nrfx_nvmc_words_write(uint32_t addr, void const * src, uint32_t num_words)
nvmc_readonly_mode_set();
}

uint32_t nrfx_nvmc_flash_size_get(void)
{
return flash_total_size_get();
}

uint32_t nrfx_nvmc_flash_page_size_get(void)
{
return flash_page_size_get();
}

uint32_t nrfx_nvmc_flash_page_count_get(void)
{
return flash_page_count_get();
}

#endif // NRFX_CHECK(NRFX_NVMC_ENABLED)

0 comments on commit 9d68726

Please sign in to comment.