Hi,
I have the problem as described in the title, and I have already searched and looked every thread in this forum about this issue, but none of them seems could help.
The closest case is this one: https://devzone.nordicsemi.com/f/nordic-q-a/45838/sd_softdevice_enable-hardfault/180723#180723 , but in that thread problem was solved by adding 2 preprocessor definitions, not work for me.
My situation is : I'm writing a simplest code doing a single sd_softdevice_enable() call only, and the call never returns, if I tracked it I found the code got stuck at 0x8c8, according to the above thread, that's the hard fault handler address inside MBR.
I created the project from the scratch, but have all the settings set according to the ble_app_blank example in the SDK. Here are the settings I've configured:
Set to use the flash placement file and the xml file is copied from ble_app_blank example.
The segment placement macros are set to:
FLASH_PH_START=0x0
FLASH_PH_SIZE=0x80000
RAM_PH_START=0x20000000
RAM_PH_SIZE=0x10000
FLASH_START=0x26000
FLASH_SIZE=0x5a000
RAM_START=0x20002218
RAM_SIZE=0xdde8
copied Preprocessor definitions from the ble_app_blank:
BOARD_PCA10040
CONFIG_GPIO_AS_PINRESET
FLOAT_ABI_HARD
NO_VTOR_CONFIG
NRF52
NRF52832_XXAA
NRF52_PAN_74
NRF_SD_BLE_API_VERSION=6
S132
SOFTDEVICE_PRESENT
SWI_DISABLE0
INITIALIZE_USER_SECTIONS
set the Additional Load File[0] to s132_nrf52_6.0.0_softdevice.hex
my source code is as this:
// main cpp program
#include <stdio.h>
#include <nrf.h>
#include <nrf_sdm.h> // clock_lf_cfg_t
#define NRF_SDH_CLOCK_LF_SRC 1
#define NRF_SDH_CLOCK_LF_RC_CTIV 0
#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0
#define NRF_SDH_CLOCK_LF_ACCURACY 7
uint32_t result;
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
printf("nrf sd error");
}
int main(void)
{
nrf_clock_lf_cfg_t const clock_lf_cfg =
{
.source = NRF_SDH_CLOCK_LF_SRC,
.rc_ctiv = NRF_SDH_CLOCK_LF_RC_CTIV,
.rc_temp_ctiv = NRF_SDH_CLOCK_LF_RC_TEMP_CTIV,
.accuracy = NRF_SDH_CLOCK_LF_ACCURACY
};
result = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);
if (result == NRF_SUCCESS)
{
printf("successful");
}
else
{
printf("error");
}
while (1);
}
I modified the ble_add_blank example's main function like this:
/**@brief Function for application main entry.
*/
int main(void)
{
bool erase_bonds;
nrf_clock_lf_cfg_t const clock_lf_cfg =
{
.source = NRF_SDH_CLOCK_LF_SRC,
.rc_ctiv = NRF_SDH_CLOCK_LF_RC_CTIV,
.rc_temp_ctiv = NRF_SDH_CLOCK_LF_RC_TEMP_CTIV,
.accuracy = NRF_SDH_CLOCK_LF_ACCURACY
};
sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);
...
I let it call the sd_softdevice_enable() right at the beginning of the main() and it returns correctly. But my own code just got stuck in sd_softdevice_enable().
As instructed in the above thread, I compared the to .map files, and couldn't find any significant difference. The __reserved_ram_end__ and _app_ram_start__ were both 0x20002218 in two files, and __vectors and __vectors_end__ were both 0x26000 and 0x260dc .
My code goes to the main() when the debugging starts, so the vector tables must work correctly. The sd_softdevice_enable() call in ble_app_blank example code and my code both jump to address 0x90c , I think which means my code has got the correct SVC call executed.
I believe there must be some compiler or linker settings missing in my code ? But I couldn't figure it out, can anybody help here? Thank you very much!
Jian