new uart driver and acessing flash boots the system

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

new uart driver and acessing flash boots the system

Postby jumjum123 » Tue Nov 22, 2016 3:43 pm

After switching my application to new uart firmware shuts down.
I could bring it down to this example. If keystrokes are comin in fast, it reboots.
Holding down a key on keyboard to repeat same character creates this problem.
Any idea whats going wrong, and wht I should do ?

Code: Select all

/* uart_flash 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 <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/uart.h"
#include "esp_spi_flash.h"
#include "freertos/queue.h"

QueueHandle_t uart0_queue;
int uart_num = 0;

void uart_init(){
    uart_config_t uart_config = {
       .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,
       .rx_flow_ctrl_thresh = 122,
    };
    uart_param_config(uart_num, &uart_config);
    //Set UART pins,(-1: default pin, no change.)
    uart_set_pin(uart_num, -1, -1, 15, 13);
    //Install UART driver, and get the queue.
    uart_driver_install(uart_num, 1024 * 2, 1024*4, 10, 17, &uart0_queue);
}

void uart_flash_task(void *pvParameters)
{   int uart_num = (int)pvParameters;
    uart_event_t event;
    int len;
    uint8_t dtmp[1000];
    for(;;) {
        //Waiting for UART event.
        if(xQueueReceive(uart0_queue, (void * )&event, (portTickType)portMAX_DELAY)) {
            switch(event.type) {
                memset(dtmp, 0, sizeof(dtmp));
                //Event of UART receving data
                case UART_DATA:
                    len = uart_read_bytes(uart_num, dtmp, event.size, 10);
                    uart_write_bytes(uart_num, (const char*)dtmp, len);
                    spi_flash_erase_sector(0x100000 >> 12);
                    break;
                default:
                    break;
            }
       }
    } 
}
void app_main()
{  nvs_flash_init();
    system_init();
    uart_init();
    xTaskCreate(uart_flash_task, "uTask", 2048*8, (void*)uart_num, 10, NULL);
}

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: new uart driver and acessing flash boots the system

Postby kolban » Tue Nov 22, 2016 4:54 pm

When your ESP32 "reboots" ... might this be because you have generated an exception and the default handler for an exception is to log the exception messages and reboot. I tend to find that I get value from using "make menuconfig" to flag the operation to halt in a GDB stub when an exception is detected. That way I can then analyze the exception and, if possible, attach GDB to see where the exception occurred. Might I suggest that you try putting your ESP32 into this mode and running again. Then when the exception occurs you can find out more diagnostics. Primarily of which will be the address of the exception. That by itself wouldn't be of value to post to this thread ... but from the address, you can locally find out where within the code base the exception occurs.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: new uart driver and acessing flash boots the system

Postby WiFive » Tue Nov 22, 2016 6:18 pm

Code: Select all

spi_flash_erase_sector(0x100000 >> 12);
Why?

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: new uart driver and acessing flash boots the system

Postby jumjum123 » Tue Nov 22, 2016 7:49 pm

@WiFiv shifting right makes it easy for me not to forget how to convert adress to sector.
There is no technical reason and could easily be replaced by a sector number.

@kolban errormessage I get is
aGuru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled.
Register dump:
PC : 40081c1e PS : 00050031 A0 : 400810b9 A1 : 3ffb37c0
A2 : 3ffb88bc A3 : 3f401964 A4 : 00000000 A5 : 00000000
A6 : 3ffbe0f0 A7 : bad00bad A8 : 40081065 A9 : 08000000
A10 : 00000003 A11 : 3ffb4e70 A12 : 8008241e A13 : 3ffb37b0
A14 : 00000000 A15 : 00000000 SAR : 00000014 EXCCAUSE: 0000001c
EXCVADDR: bad00bb5 LBEG : 4000c2e0 LEND : 4000c2f6 LCOUNT : ffffffff
Rebooting...

Tried to start objdump, and got
can't disassemble for architecture UNKNOWN!
Anyway, there is a lst-file and as far as I can see, exception happens in uart_rx_intr_handler_default (which starts at 0x40081c04)

Some more info after finding this http://www.esp32.com/viewtopic.php?t=263#p1131
Its a beautiful help given by ESP_Sprite . Taking the help, error is in line 447, and for now I've no idea where to go now.
list *0x40081c1e
0x40081c1e is in uart_rx_intr_handler_default (/home/esp32/esp-idf/components/driver/./uart.c:447).
442 {
443 uart_obj_t *p_uart = (uart_obj_t*) param;
444 uint8_t uart_num = p_uart->uart_num;
445 uart_dev_t* uart_reg = UART[uart_num];
446 uint8_t buf_idx = 0;
447 uint32_t uart_intr_status = UART[uart_num]->int_st.val;
448 int rx_fifo_len = 0;
449 uart_event_t uart_event;
450 portBASE_TYPE HPTaskAwoken = 0;
451

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: new uart driver and acessing flash boots the system

Postby kolban » Tue Nov 22, 2016 9:31 pm

That's GREAT as far as it goes. Since we see that are aren't failing in your code ... the next question would be what is the "stack trace" ... i.e. what path took us to the failure point. What statement in your code got us here? I would use xtensa GDB to look at that. Failing that technique, sprinkle log statements throughout to see what statement we enter but don't leave.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: new uart driver and acessing flash boots the system

Postby WiFive » Tue Nov 22, 2016 9:46 pm

No I mean why are you erasing the flash every time UART data is received? Trying to kill that sector?

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: new uart driver and acessing flash boots the system

Postby jumjum123 » Tue Nov 22, 2016 10:32 pm

I had the problem in an application and tried to create a reproducable version.
So stripped it down.
In my application, I'm reading from console, and depending from input read from flash.
For testing I decided to use erase page to make it as easy to follow as possible.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: new uart driver and acessing flash boots the system

Postby ESP_Angus » Tue Nov 22, 2016 11:55 pm

Hi jumjum,

Thanks for doing such good investigative work and supplying comprehensive information. I think you've found a fun bug!

The compiler has quietly noticed the UART array (accessed at line 447) is never written to, even though it's not marked const, so it has marked the elements as constant meaning they are saved in flash by default. The ISR may run while flash cache is disabled, so it can only access data in RAM (in this case flash cache is disabled due to the flash erase operation in progress).

A clue in the crash dump is that the excvaddr (the address whose read caused the crash) is 0xbad00bb5. This is the value read back from flash cash that is unmapped at runtime.

Can you please try checking out this branch of esp-idf and see if it fixes the problem:
https://github.com/espressif/esp-idf/tr ... isr_rodata

(Command line commands 'git fetch origin; get checkout bugfix/uart_isr_rodata' should do the trick.)

Thanks,

Angus

jumjum123
Posts: 199
Joined: Mon Oct 17, 2016 3:11 pm

Re: new uart driver and acessing flash boots the system

Postby jumjum123 » Wed Nov 23, 2016 8:54 am

Thanks for the feedback.
Good news first, I tried with the new definition and it doesn't crash anymore.

Bad news is, got a new not reproducable problem.
After holding down a key for some time, pressed a different key, but this newly pressed key arrived with delay of some clicks.
To make it easier to follow, pressed "a" for some time, and got a lot of "a"
Next pressed "bcdef" and got "aabcd"
Same happend 2 more times, but now its gone :?

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: new uart driver and acessing flash boots the system

Postby rudi ;-) » Wed Nov 23, 2016 2:43 pm

jumjum123 wrote:Thanks for the feedback.
Good news first, I tried with the new definition and it doesn't crash anymore.

Bad news is, got a new not reproducable problem.
After holding down a key for some time, pressed a different key, but this newly pressed key arrived with delay of some clicks.
To make it easier to follow, pressed "a" for some time, and got a lot of "a"
Next pressed "bcdef" and got "aabcd"
Same happend 2 more times, but now its gone :?

yeap,
the same i get too

like this:

if i run from a terminal prog 1000 times like this
example strings..

Code: Select all

comport1.writeln("Testing the RingBuffer, and HW Fifo\r\n");
the things are perhabs 880 times done and response.
if i send then a simple "new data in the pipe of Fifo / Buffer then comes the "rest" interval like i send new.
its the same effect like you have.

how you have it help to go now?


my problem is: how clear / clean Ringbuffer, HW fifo
http://esp32.com/viewtopic.php?f=2&t=534

how you clear this?
get you not his message

Code: Select all


 //Event of HW FIFO overflow detected
                  case UART_FIFO_OVF:
                      ESP_LOGI(TAG, "hw fifo overflow\n");
					  // uart_reg->int_clr.val = UART_RXFIFO_FULL_INT_CLR_M | UART_RXFIFO_TOUT_INT_CLR_M;
					  
					  // UART_RXFIFO_OVF_INT_ST_M
					  // uart_reg->int_clr.val = UART_RXFIFO_OVF_INT_ST_M;
					  
					  // reg_delay(); // nop delay after write register
					  // ESP_LOGI(TAG, "try cleared..\n");
					  
					  // uart_flush(uart_num);
					  // ESP_LOGI(TAG, "uart_flush cleared..\n");
					  
					  break;
                  //Event of UART ring buffer full
                  case UART_BUFFER_FULL:
                      ESP_LOGI(TAG, "ring buffer full\n");
                      break;
                  //Event of UART RX break detected
                  case UART_BREAK:
                      ESP_LOGI(TAG, "uart rx break\n");
                      break;
                  //Event of UART parity check error
                  case UART_PARITY_ERR:
                      ESP_LOGI(TAG, "uart parity error\n");
                      break;
                  //Event of UART frame error
                  case UART_FRAME_ERR:
                      ESP_LOGI(TAG, "uart frame error\n");
                      break;
                  //Others
                  default:
                      ESP_LOGI(TAG, "uart event type: %d\n", event.type);
                      break;

txs

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: No registered users and 188 guests