new uart driver and acessing flash boots the system
Posted: 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 ?
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);
}