Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

移植到ESP8266后无限重启 #166

Open
CloudSir opened this issue Sep 28, 2023 · 7 comments
Open

移植到ESP8266后无限重启 #166

CloudSir opened this issue Sep 28, 2023 · 7 comments

Comments

@CloudSir
Copy link

错误说明

将letter shell移植到ESP8266后,可以正常编译和烧录,但程序运行到 shellInit(&shell, shellBuffer, 512);后会无限重启

ESP8266运行时输出的日志信息:

�
 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 7168, room 16 
tail 0
chksum 0x80
load 0x3ffe8408, len 24, room 8 
tail 0
chksum 0x09
load 0x3ffe8420, len 3528, room 8 
tail 0
chksum 0x48
csum 0x48
�[0;32mI (45) boot: ESP-IDF e5ec3b46-dirty 2nd stage bootloader�[0m
�[0;32mI (46) boot: compile time 08:44:11�[0m
�[0;32mI (46) qio_mode: Enabling default flash chip QIO�[0m
�[0;32mI (53) boot: SPI Speed      : 40MHz�[0m
�[0;32mI (59) boot: SPI Mode       : QIO�[0m
�[0;32mI (66) boot: SPI Flash Size : 2MB�[0m
�[0;32mI (72) boot: Partition Table:�[0m
�[0;32mI (77) boot: ## Label            Usage          Type ST Offset   Length�[0m
�[0;32mI (89) boot:  0 nvs              WiFi data        01 02 00009000 00006000�[0m
�[0;32mI (100) boot:  1 phy_init         RF data          01 01 0000f000 00001000�[0m
�[0;32mI (112) boot:  2 factory          factory app      00 00 00010000 000f0000�[0m
�[0;32mI (123) boot: End of partition table�[0m
�[0;32mI (130) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x1993c (104764) map�[0m
�[0;32mI (178) esp_image: segment 1: paddr=0x00029954 vaddr=0x4022994c size=0x04070 ( 16496) map�[0m
�[0;32mI (184) esp_image: segment 2: paddr=0x0002d9cc vaddr=0x3ffe8000 size=0x003cc (   972) load�[0m
�[0;32mI (189) esp_image: segment 3: paddr=0x0002dda0 vaddr=0x40100000 size=0x00a50 (  2640) load�[0m
�[0;32mI (203) esp_image: segment 4: paddr=0x0002e7f8 vaddr=0x40100a50 size=0x04bb4 ( 19380) load�[0m
�[0;32mI (222) boot: Loaded app from partition at offset 0x10000�[0m
�[0;32mI (240) system_api: Base MAC address is not set, read default base MAC address from EFUSE�[0m
�[0;32mI (244) system_api: Base MAC address is not set, read default base MAC address from EFUSE�[0m

版本说明

  • letter shell版本:3.1
  • ESP8266 RTOS SDK版本:3.2
  • 编译工具链版本:5.2.0

详细代码

main.c

/* Esptouch example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "tcpip_adapter.h"
#include "esp_smartconfig.h"
#include "shell.h"
#include "driver/uart.h"

char *TAG = "Hello";


#define     SHELL_UART      UART_NUM_0

Shell shell;
char shellBuffer[512];

/**
 * @brief 用户shell写
 * 
 * @param data 数据
 * @param len 数据长度
 * 
 * @return unsigned short 写入实际长度
 */
unsigned short userShellWrite(char *data, unsigned short len)
{
    return uart_write_bytes(SHELL_UART, (const char *)data, len);
}


/**
 * @brief 用户shell读
 * 
 * @param data 数据
 * @param len 数据长度
 * 
 * @return unsigned short 读取实际长度
 */
signed char userShellRead(char *data, unsigned short len)
{
    return uart_read_bytes(SHELL_UART, (uint8_t *)data, len, portMAX_DELAY);
}


/**
 * @brief 用户shell初始化
 * 
 */
void userShellInit(void)
{
    uart_config_t uartConfig = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(SHELL_UART, &uartConfig);
    uart_driver_install(SHELL_UART, 256 * 2, 0, 0, NULL, 0);
    shell.write = userShellWrite;
    shell.read = userShellRead;
    shellInit(&shell, shellBuffer, 512);

    xTaskCreate(shellTask, "shell", 2048, &shell, 10, NULL);
}

void test_cmd()
{
    printf("you input cmd!!!\n");
}

SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE (SHELL_TYPE_CMD_MAIN)|SHELL_CMD_DISABLE_RETURN,test, test_cmd, show command info\r\nhelp [cmd]);


// https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/
void app_main()
{
	ESP_LOGI(TAG, "Hello");
    ESP_ERROR_CHECK( nvs_flash_init() );

    userShellInit();
    ESP_LOGI(TAG, "init shell end");
}

letter-shell-shell3.1/CMakeLists.txt

idf_component_register(SRCS "./src/*.c"
                    INCLUDE_DIRS "./src/" "."
                        LDFRAGMENTS "shell.lf"
)

letter-shell-shell3.1/component.mk

COMPONENT_ADD_INCLUDEDIRS := src .
COMPONENT_SRCDIRS := src

letter-shell-shell3.1/shell.lf

[sections:shellCommand]
entries:
    shellCommand+

[scheme:shell_command]
entries:
    shellCommand -> flash_rodata

[mapping:shell]
archive: *
entries:
    * (shell_command);
        shellCommand -> flash_rodata KEEP() ALIGN(4, pre, post) SURROUND(shell_command)
@NevermindZZT
Copy link
Owner

改一下任务栈大小看看

@CloudSir
Copy link
Author

改一下任务栈大小看看

把主任务栈大小改成9999后依然重启

  Task stack [uiT] stack from [0x3ffee718] to [0x3fff0e24], total [10000] size                     0          4          8          c         10         14         18         1c         20         24         28         2c         30         34         38         3c   3fff0d80  0x3ffee498 0x00000000 0x40213b10 0x4022f538 0x00000119 0x00780a0a 0x3fff1c40 0x00000000 0x00000000 0x3ffee504 0x3ffee498 0x4023076a 0x00000000 0x3fff0dd0 0x00000000 0x00000000  3fff0dc0  0x00000000 0x3ffee498 0x00000000 0x402284c1 0x00012480 0x00000003 0x00000000 0x00000001 0x00000000 0x00000000 0x3ffe86bc 0x4022a724 0x00000000 0x00000000 0x3ffe86bc 0x4022850a  3fff0e00  0x00000000 0x00000000 0x3ffe86bc 0x402166d7 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000            PC: 0x4000bdcb        PS: 0x00000030        A0: 0x40230648        A1: 0x3fff0d80         A2: 0x40213b10        A3: 0x00000000        A4: 0x00000008        A5: 0x00000030         A6: 0x00000008        A7: 0x00000023        A8: 0x0000006c        A9: 0x0000c8d8        A10: 0x00000003       A11: 0x40211728       A12: 0x00000000       A13: 0x3ffee708        A14: 0x3ffee708       A15: 0x0000ffff       SAR: 0x00000019  EXCCAUSE: 0x0000001c

�
 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

@CloudSir CloudSir reopened this Oct 11, 2023
@NevermindZZT
Copy link
Owner

有没有重启前的打印,我记得发生异常,重启前会打印出异常原因和调用栈的

@CloudSir
Copy link
Author

有没有重启前的打印,我记得发生异常,重启前会打印出异常原因和调用栈的

这是完整的打印

�
 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x40100000, len 7204, room 16 
tail 4
chksum 0xab
load 0x3ffe8408, len 24, room 4 
tail 4
chksum 0x22
load 0x3ffe8420, len 3536, room 4 
tail 12
chksum 0x47
csum 0x47
�[0;32mI (46) boot: ESP-IDF v3.2-dirty 2nd stage bootloader�[0m
�[0;32mI (46) boot: compile time 08:36:49�[0m
�[0;32mI (46) qio_mode: Enabling default flash chip QIO�[0m
�[0;32mI (53) boot: SPI Speed      : 40MHz�[0m
�[0;32mI (59) boot: SPI Mode       : QIO�[0m
�[0;32mI (65) boot: SPI Flash Size : 2MB�[0m
�[0;32mI (71) boot: Partition Table:�[0m
�[0;32mI (77) boot: ## Label            Usage          Type ST Offset   Length�[0m
�[0;32mI (88) boot:  0 nvs              WiFi data        01 02 00009000 00006000�[0m
�[0;32mI (100) boot:  1 phy_init         RF data          01 01 0000f000 00001000�[0m
�[0;32mI (111) boot:  2 factory          factory app      00 00 00010000 000f0000�[0m
�[0;32mI (123) boot: End of partition table�[0m
�[0;32mI (129) esp_image: segment 0: paddr=0x00010010 vaddr=0x40210010 size=0x33e2c (212524) map�[0m
�[0;32mI (214) esp_image: segment 1: paddr=0x00043e44 vaddr=0x3ffe8000 size=0x00528 (  1320) load�[0m
�[0;32mI (215) esp_image: segment 2: paddr=0x00044374 vaddr=0x3ffe8528 size=0x0019c (   412) load�[0m
�[0;32mI (225) esp_image: segment 3: paddr=0x00044518 vaddr=0x40100000 size=0x05ae0 ( 23264) load�[0m
�[0;32mI (246) boot: Loaded app from partition at offset 0x10000�[0m
�[0;32mI (283) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE�[0m
�[0;32mI (283) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE�[0m
�[0;32mI (473) phy_init: phy ver: 1055_12�[0m
�[0;32mI (473) reset_reason: RTC reset 2 wakeup 0 store 3, reason is 2�[0m
�[0;32mI (473) Hello: Hello�[0m
 

Task stack [uiT] stack from [0x3ffee718] to [0x3fff0e24], total [10000] size                     0          4          8          c         10         14         18         1c         20         24         28         2c         30         34         38         3c   3fff0d80  0x3ffee498 0x00000000 0x40213b10 0x4022f538 0x00000119 0x00780a0a 0x3fff1c40 0x00000000 0x00000000 0x3ffee504 0x3ffee498 0x4023076a 0x00000000 0x3fff0dd0 0x00000000 0x00000000  3fff0dc0  0x00000000 0x3ffee498 0x00000000 0x402284c1 0x00012480 0x00000003 0x00000000 0x00000001 0x00000000 0x00000000 0x3ffe86bc 0x4022a724 0x00000000 0x00000000 0x3ffe86bc 0x4022850a  3fff0e00  0x00000000 0x00000000 0x3ffe86bc 0x402166d7 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000            PC: 0x4000bdcb        PS: 0x00000030        A0: 0x40230648        A1: 0x3fff0d80         A2: 0x40213b10        A3: 0x00000000        A4: 0x00000008        A5: 0x00000030         A6: 0x00000008        A7: 0x00000023        A8: 0x0000006c        A9: 0x0000c8d8        A10: 0x00000003       A11: 0x40211728       A12: 0x00000000       A13: 0x3ffee708        A14: 0x3ffee708       A15: 0x0000ffff       SAR: 0x00000019  EXCCAUSE: 0x0000001c

@NevermindZZT
Copy link
Owner

最后有把栈和寄存器信息打印出来,用 idf_monitor 或者 addr2line 分析下调用栈,看看是在哪里挂掉的

@CloudSir
Copy link
Author

CloudSir commented Nov 6, 2023

最后有把栈和寄存器信息打印出来,用 idf_monitor 或者 addr2line 分析下调用栈,看看是在哪里挂掉的

任务栈

Task stack [uiT] stack from [0x3ffee718] to [0x3fff0e24], total [10000] size 0 4 8 c 10 14 18 1c 20 24 28 2c 30 34 38 3c 3fff0d80 0x3ffee498 0x00000000 0x40213b10 0x4022f538 0x00000119 0x00780a0a 0x3fff1c40 0x00000000 0x00000000 0x3ffee504 0x3ffee498 0x4023076a 0x00000000 0x3fff0dd0 0x00000000 0x00000000 3fff0dc0 0x00000000 0x3ffee498 0x00000000 0x402284c1 0x00012480 0x00000003 0x00000000 0x00000001 0x00000000 0x00000000 0x3ffe86bc 0x4022a724 0x00000000 0x00000000 0x3ffe86bc 0x4022850a 3fff0e00 0x00000000 0x00000000 0x3ffe86bc 0x402166d7 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000

寄存器

PC: 0x4000bdcb PS: 0x00000030 A0: 0x40230648 A1: 0x3fff0d80 A2: 0x40213b10 A3: 0x00000000 A4: 0x00000008 A5: 0x00000030 A6: 0x00000008 A7: 0x00000023 A8: 0x0000006c A9: 0x0000c8d8 A10: 0x00000003 A11: 0x40211728 A12: 0x00000000 A13: 0x3ffee708 A14: 0x3ffee708 A15: 0x0000ffff SAR: 0x00000019 EXCCAUSE: 0x0000001c

根据官方文档:https://blog.csdn.net/espressif/article/details/102658110, PC寄存器的值为0x4000bdcb,【PC 寄存器值若为野指针, 例如 0x80001210, 可能是内存踩踏. 一旦踩踏到栈底的 PC, 形如 retw.n 就会弹出野指针.】

猜测可能是调用letter-shell初始化函数的时候的时候出现了指针调用的问题。

@NevermindZZT
Copy link
Owner

初始化时野指针,可能是命令表没有被编译进去,现在里面 esp idf 的例程不确定是不是适合 8266 最好看看 map 文件,确认下命令表是不是都编译到一块连续空间了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants