Getting Hard Fault Reset using read/write Functions RAK811

Hi, im using the read_partition/wirte_partition Functions to save 1 counter inside the structure of g_lora_config. The code was modified to understand my problem:

if (read_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config)) < 0) {
    e_printf(RAK_RD_CFG_ERR);		}
g_lora_config.Cont= 0;
write_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config));
e_printf("OK\r\n");
...
...
...
...
while(1) {
g_lora_config.Cont= g_lora_config.Cont +1;
HAL_Delay(1000);
write_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config));
e_printf("OK\r\n");	
}

If i see the Serial :

Welcome to RAK811.
Selected LoraWAN 1.0.2 Region: US915
The Hard Fault exception occurs,Reset!
Welcome to RAK811.
Selected LoraWAN 1.0.2 Region: US915
The Hard Fault exception occurs,Reset!

I also can get this :

Return of Read USR Config: -1
Table crc error! base_addr:0x801ea00 , crc:0x913f

This is the Function:

int read_partition(partition_index partition, char *out, uint16_t out_len)
{
    uint16_t crc;
    table_header_t table;
    uint32_t base_addr;

    base_addr = get_active_partition(partition);
    read_data(base_addr, &table, sizeof(table_header_t));
    p_log("R- base_addr:0x%x ,crc:0x%x\r\n", base_addr, table.crc);
    
    if (table.magic != PARTITION_MAGIC_WORD) {
        p_log("Table magic error! base_addr:0x%x\r\n", base_addr);
				e_printf("Table magic error! base_addr:0x%x\r\n", base_addr); 			
        return -1;
    }
    if (table.length != out_len) {
        p_log("Table length error! base_addr:0x%x\r\n", base_addr);
				e_printf("Table length error! base_addr:0x%x\r\n", base_addr);
        return -1;    
    }
 
    read_data(base_addr + sizeof(table_header_t), out, table.length);
    crc = crc_calc(0, out, out + table.length);
    if (crc != table.crc) {
        p_log("Table crc error! base_addr:0x%x , crc:0x%x\r\n", base_addr, crc);
				e_printf("Table crc error! base_addr:0x%x , crc:0x%x\r\n", base_addr, crc);
        return -1;       
    }

    return 0;
}

So, the base_addr was change after the Sleeping, i dont know why

base_addr:0x801e200 , crc:0x56c
Sending Data…
at+recv=1,0,0
TX_CONFIRMED ok!
JOIN COUNTER 0

Sleeping
Welcome to RAK811.
base_addr:0x801ea00 , crc:0x56c
Table crc error! base_addr:0x801ea00 , crc:0xfc07
Return Read USR CFG: -1
Using default settings
base_addr:0x801e200 , crc:0x56c

Hi,@FraCaPr
Which project’s firmware are you using?

hi, i’m using the last version :

but i “solved” using this function:

 write_data(addres,buffer,sizeof(buffer)) ;
 read_data(addres,buffer,sizeof(buffer)) ;

Hi @FraCaPr

This exception is caused by stack space overflow possibly. Finding this problem is complicated.So you need check your app logic.

You’d better execute twice in a row “write_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config));”
in fuction “int write_partition(partition_index partition, char *out, uint16_t out_len)”. It is possible that flash is not fully unlocked, so do once write to unlock it first,then write flash normally .

This open source code is very old and will not be updated.So you could try our RUI:https://forum.rakwireless.com/t/rak-online-compiler-for-you-to-compile-your-customized-firmware-based-on-rui/662

1 Like