|
| 1 | +/* Flash multiple partitions example |
| 2 | +
|
| 3 | + This example code is in the Public Domain (or CC0 licensed, at your option.) |
| 4 | +
|
| 5 | + Unless required by applicable law or agreed to in writing, this |
| 6 | + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 7 | + CONDITIONS OF ANY KIND, either express or implied. |
| 8 | +*/ |
| 9 | + |
| 10 | +#include <sys/param.h> |
| 11 | +#include <string.h> |
| 12 | +#include "esp_err.h" |
| 13 | +#include "esp_log.h" |
| 14 | +#include "driver/uart.h" |
| 15 | +#include "driver/gpio.h" |
| 16 | +#include "esp32_port.h" |
| 17 | +#include "esp_loader.h" |
| 18 | +#include "example_common.h" |
| 19 | + |
| 20 | +static const char *TAG = "serial_flasher"; |
| 21 | +static const char example_data[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " |
| 22 | + "Donec pretium sem et condimentum tincidunt.n " |
| 23 | + "Quisque tristique in enim elementum aliquet. " |
| 24 | + "Integer consequat sodales bibendum. " |
| 25 | + "Nam enim quam, tristique id dui ut, fermentum porta felis. " |
| 26 | + "Phasellus vulputate sem quis ligula egestas, sed ullamcorper eros tincidunt. " |
| 27 | + "Donec imperdiet ac urna in placerat. " |
| 28 | + "Praesent ultrices velit nulla, eu rutrum nisi maximus in." |
| 29 | + "Donec non ligula molestie, blandit massa vel, auctor ipsum. " |
| 30 | + "Nunc consectetur mi nulla, a ultricies odio vehicula a. " |
| 31 | + "Praesent hendrerit tellus nunc, a interdum lectus mollis eget. " |
| 32 | + "Nullam in felis vitae diam posuere dignissim quis non urna. " |
| 33 | + "Quisque elementum ante at sapien condimentum, sit amet ultricies tortor feugiat. " |
| 34 | + "Aliquam id mi at purus maximus lobortis. " |
| 35 | + "Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. " |
| 36 | + "Nunc consequat lorem turpis, vitae dignissim leo fringilla eget. " |
| 37 | + "In ornare convallis finibus. " |
| 38 | + "Morbi libero neque, pretium et mollis non, dictum eget felis. " |
| 39 | + "Ut mattis vitae urna id vulputate. " |
| 40 | + "Nam porttitor dolor diam, eu rutrum tortor auctor id..."; |
| 41 | +static uint8_t read_buf[sizeof(example_data)]; |
| 42 | + |
| 43 | +#define HIGHER_BAUDRATE 230400 |
| 44 | + |
| 45 | +void app_main(void) |
| 46 | +{ |
| 47 | + const loader_esp32_config_t config = { |
| 48 | + .baud_rate = 115200, |
| 49 | + .uart_port = UART_NUM_1, |
| 50 | + .uart_rx_pin = GPIO_NUM_5, |
| 51 | + .uart_tx_pin = GPIO_NUM_4, |
| 52 | + .reset_trigger_pin = GPIO_NUM_25, |
| 53 | + .gpio0_trigger_pin = GPIO_NUM_26, |
| 54 | + }; |
| 55 | + |
| 56 | + if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) { |
| 57 | + ESP_LOGE(TAG, "serial initialization failed."); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + if (connect_to_target(HIGHER_BAUDRATE) == ESP_LOADER_SUCCESS) { |
| 62 | + |
| 63 | + ESP_LOGI(TAG, "Loading example data"); |
| 64 | + flash_binary((const uint8_t *)example_data, sizeof(example_data), 0x00000000); |
| 65 | + |
| 66 | + if (esp_loader_flash_read(read_buf, 0x00000000, sizeof(read_buf)) == ESP_LOADER_SUCCESS) { |
| 67 | + if (!memcmp(example_data, read_buf, sizeof(read_buf))) { |
| 68 | + ESP_LOGI(TAG, "Flash contents match example data"); |
| 69 | + } else { |
| 70 | + ESP_LOGE(TAG, "Flash contents do not match example data"); |
| 71 | + ESP_LOG_BUFFER_HEXDUMP("Programmed data: ", example_data, sizeof(read_buf), ESP_LOG_ERROR); |
| 72 | + ESP_LOG_BUFFER_HEXDUMP("Read data: ", read_buf, sizeof(read_buf), ESP_LOG_ERROR); |
| 73 | + } |
| 74 | + } else { |
| 75 | + ESP_LOGE(TAG, "Could not read from flash!"); |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + } |
| 80 | + vTaskDelete(NULL); |
| 81 | +} |
0 commit comments