Hedy Wang


I am using lwip/sockets and create a task to build a socket, it can be compiled successfully, but when running the code, there will be hard fault error.

I went to track the code, and then I found that the error occurred when executing to memp_tab[type] = memp-> next in the memp_malloc () function (Ln408, sdk-ameba1-v3.4b3_without_NDA\component\common\network\lwip\lwip_v1.4.1\src\core\memp.c).

Here is my main code:

#include "FreeRTOS.h"
#include "task.h"
#include "diag.h"
#include "main.h"
#include <example_entry.h>
#include "lwip/sockets.h"
#include "lwip/memp.h"

#define STACKSIZE (512 + 768)

extern void console_init(void);

static void create_socket(void)
int s = -1;
printf("create socket!\n");
s = socket(AF_INET, SOCK_DGRAM, 0);
printf("s equla to %d\n", s);

* @brief Main program.
* @param None
* @retval None
void main(void)
if ( rtl_cryptoEngine_init() != 0 ) {
DiagPrintf("crypto engine init failed\r\n");

/* Initialize log uart and at command service */

/* pre-processor of application example */

/* wlan intialization */
#if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK)

/* Execute application example */

xTaskCreate(create_socket, ((const char*)"init"), STACKSIZE, NULL, tskIDLE_PRIORITY + 3 + PRIORITIE_OFFSET, NULL);

/*Enable Schedule, Start Kernel*/

Here is the result:


ROM Version: 0.3

Build ToolChain Version: gcc version 4.8.3 (Realtek ASDK-4.8.3p1 Build 2003)

Check boot type form eFuse
SPI Initial
Image1 length: 0x36e8, Image Addr: 0x10000bc8
Image1 Validate OK, Going jump to Image1
===== Enter Image 1 ====
SDR Controller Init

load NEW fw 0
Flash Image2:Addr 0xb000, Len 252668, Load to SRAM 0x10006000
No Image3
Img2 Sign: RTKWin, InfaStart @ 0x10006079
===== Enter Image 2 ====
#create socket!
RTL8195A[HAL]: Hard Fault Error!!!!
RTL8195A[HAL]: R0 = 0x6
RTL8195A[HAL]: R1 = 0x0
RTL8195A[HAL]: R2 = 0x2889
RTL8195A[HAL]: R3 = 0x0
RTL8195A[HAL]: R12 = 0x6
RTL8195A[HAL]: LR = 0x1000db41
RTL8195A[HAL]: PC = 0x1000adc2
RTL8195A[HAL]: PSR = 0x61000000
RTL8195A[HAL]: BFAR = 0x7c8abf47
RTL8195A[HAL]: CFSR = 0x8200
RTL8195A[HAL]: HFSR = 0x40000000
RTL8195A[HAL]: DFSR = 0x0
RTL8195A[HAL]: AFSR = 0x0
RTL8195A[HAL]: PriMask 0x0
RTL8195A[HAL]: BasePri 0x50
RTL8195A[HAL]: SVC priority: 0x00
RTL8195A[HAL]: PendSVC priority: 0xf0
RTL8195A[HAL]: Systick priority: 0xf0

I don't know why this is so, is there anything that needs to be set?

sean 回答了