nrf: Make sure to not use SD functions when SD not available
This commit is contained in:
parent
9d191f7f9f
commit
47c8e20e5a
|
@ -30,8 +30,11 @@
|
||||||
#include "py/objtuple.h"
|
#include "py/objtuple.h"
|
||||||
#include "py/qstr.h"
|
#include "py/qstr.h"
|
||||||
|
|
||||||
|
#ifdef BLUETOOTH_SD
|
||||||
#include "nrf_sdm.h"
|
#include "nrf_sdm.h"
|
||||||
#include "nrf_soc.h"
|
#endif
|
||||||
|
|
||||||
|
#include "nrf.h"
|
||||||
|
|
||||||
STATIC const qstr os_uname_info_fields[] = {
|
STATIC const qstr os_uname_info_fields[] = {
|
||||||
MP_QSTR_sysname, MP_QSTR_nodename,
|
MP_QSTR_sysname, MP_QSTR_nodename,
|
||||||
|
@ -61,15 +64,15 @@ mp_obj_t common_hal_os_uname(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
|
bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
|
||||||
uint8_t sd_en = 0;
|
#ifdef BLUETOOTH_SD
|
||||||
(void) sd_softdevice_is_enabled(&sd_en);
|
uint8_t sd_en = 0;
|
||||||
|
(void) sd_softdevice_is_enabled(&sd_en);
|
||||||
|
|
||||||
|
if (sd_en) {
|
||||||
|
return NRF_SUCCESS == sd_rand_application_vector_get(buffer,length);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if ( sd_en )
|
|
||||||
{
|
|
||||||
return NRF_SUCCESS == sd_rand_application_vector_get(buffer,length);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
// SoftDevice is not enabled.
|
|
||||||
NRF_RNG->EVENTS_VALRDY = 0;
|
NRF_RNG->EVENTS_VALRDY = 0;
|
||||||
NRF_RNG->TASKS_START = 1;
|
NRF_RNG->TASKS_START = 1;
|
||||||
|
|
||||||
|
@ -82,7 +85,6 @@ bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NRF_RNG->TASKS_STOP = 1;
|
NRF_RNG->TASKS_STOP = 1;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,10 @@
|
||||||
#include "supervisor/shared/rgb_led_status.h"
|
#include "supervisor/shared/rgb_led_status.h"
|
||||||
|
|
||||||
#include "nrf.h"
|
#include "nrf.h"
|
||||||
#include "nrf_soc.h"
|
|
||||||
|
#ifdef BLUETOOTH_SD
|
||||||
|
#include "nrf_sdm.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// defined in linker
|
// defined in linker
|
||||||
extern uint32_t __fatfs_flash_start_addr[];
|
extern uint32_t __fatfs_flash_start_addr[];
|
||||||
|
@ -83,6 +86,8 @@ static uint32_t convert_block_to_flash_addr(uint32_t block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||||
|
uint8_t sd_en = 0;
|
||||||
|
|
||||||
#ifdef MICROPY_HW_LED_MSC
|
#ifdef MICROPY_HW_LED_MSC
|
||||||
port_pin_set_output_level(MICROPY_HW_LED_MSC, true);
|
port_pin_set_output_level(MICROPY_HW_LED_MSC, true);
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,12 +104,48 @@ bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
|
||||||
memcpy(buf, flash_align, FLASH_PAGE_SIZE);
|
memcpy(buf, flash_align, FLASH_PAGE_SIZE);
|
||||||
memcpy(buf + (dest%FLASH_PAGE_SIZE), src, FILESYSTEM_BLOCK_SIZE);
|
memcpy(buf + (dest%FLASH_PAGE_SIZE), src, FILESYSTEM_BLOCK_SIZE);
|
||||||
|
|
||||||
if (NRF_SUCCESS != sd_flash_page_erase(pagenum)) {
|
#ifdef BLUETOOTH_SD
|
||||||
return false;
|
(void) sd_softdevice_is_enabled(&sd_en);
|
||||||
}
|
|
||||||
|
|
||||||
if (NRF_SUCCESS != sd_flash_write((uint32_t*) flash_align, (uint32_t*) buf, FLASH_PAGE_SIZE/4)) {
|
if (sd_en) {
|
||||||
return false;
|
if (NRF_SUCCESS != sd_flash_page_erase(pagenum)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NRF_SUCCESS != sd_flash_write((uint32_t*) flash_align, (uint32_t*) buf, FLASH_PAGE_SIZE / sizeof(uint32_t))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!sd_en) {
|
||||||
|
// Erase
|
||||||
|
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos);
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
NRF_NVMC->ERASEPAGE = dest;
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
// Write
|
||||||
|
uint32_t *src = (uint32_t*) buf;
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
while (i < (FLASH_PAGE_SIZE / sizeof(uint32_t))) {
|
||||||
|
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
*flash_align++ = *src++;
|
||||||
|
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
|
||||||
|
while (NRF_NVMC->READY == NVMC_READY_READY_Busy);
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_temp_status();
|
clear_temp_status();
|
||||||
|
|
Loading…
Reference in New Issue