본문으로 바로가기

[nRF52 ] FDS_ERR_UNALIGNED_ADDR 에러 디버깅

category Nordic_nRF52 2023. 9. 8. 11:39

: fds_record_write()  함수 호출시 FDS_ERR_UNALIGNED_ADDR 에러가 발생을 해 디버깅 해봤습니다.

Debug 모드 빌드시는 발생하지 않았고. .Release 모드에서만  발생하네요.

 

▶ SES 이용해 에러시 Call Stack 을 읽어 봤습니다. (error_code = 0x8602)

 

0x8602 코드 해석

1> sdk_errors.h 파일에 다음이 정의가 되어 있습니다.
#define NRF_ERROR_FDS_ERR_BASE              (0x8600)

2> fds.h 파일
enum
{
    FDS_ERR_OPERATION_TIMEOUT = NRF_ERROR_FDS_ERR_BASE,  //!< Error. The operation timed out.
    FDS_ERR_NOT_INITIALIZED,                             //!< Error. The module has not been initialized.
    FDS_ERR_UNALIGNED_ADDR,           <--- 요기          //!< Error. The input data is not aligned to a word boundary.
    FDS_ERR_INVALID_ARG,                                 //!< Error. The parameter contains invalid data.
    ~~ 중략 ~~
 };

 

  에러내용은 찾았고 그럼 코드를 따라가 보겠습니다.

    → call stack main() 클릭시 에러 위치

 

  → fds_record_write () 함수 정의

ret_code_t fds_record_write(fds_record_desc_t       * const p_desc,
                            fds_record_t      const * const p_record)
{
    return write_enqueue(p_desc, p_record, NULL, FDS_OP_WRITE);
}

 

 

  →  write_enqueue() 함수 정의

// Enqueues write and update operations.
static ret_code_t write_enqueue(fds_record_desc_t         * const p_desc,
                                fds_record_t        const * const p_record,
                                fds_reserve_token_t const * const p_tok,
                                fds_op_code_t                     op_code)
{
    ~~ 중략 ~~
    if (!is_word_aligned(p_record->data.p_data))     <--- 요기
    {
        return FDS_ERR_UNALIGNED_ADDR;    
    }
    ~~ 중략 ~~
}

 

  ▶  p_record->data.p_data  가 word_align  안되었다??  

     → 변수 역추적하기

 1> fds_record_write(&desc, &m_sys_config_record);   
	--> m_sys_config_record 정의에 문제가 있는것 같네요.
    
 2>  m_sys_config_record 관련 코드 찾기
     /* A record containing dummy configuration data. */
    static fds_record_t const m_sys_config_record  =
    {
        .file_id           = CONFIG_SYS_FILE,
        .key               = CONFIG_SYS_REC_KEY,
        .data.p_data       = &g_sys_config,     <----- 요기
        /* The length of a record is always expressed in 4-byte units (words). */
        .data.length_words = (sizeof(g_sys_config) + 3) / sizeof(uint32_t),
    };
 
  3>  g_sys_config 변수 정의
  	SystemConfig g_sys_config ;

 

  ▶ g_sys_config word align  추가하기

      SystemConfig g_sys_config __attribute__ ((aligned (4)));

 

 

  ▶  이후 에러없이 정상 작동하네요.

  

 

 

에러 디버깅시 참고하세요.

 

 

 

 

반응형