feat(linux_target): enable hello world example for linux target

pull/12525/head
Marius Vikhammer 2023-10-24 10:04:09 +08:00
rodzic 88af378d2e
commit 8c52b0845d
12 zmienionych plików z 25 dodań i 129 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
idf_build_get_property(target IDF_TARGET)
if(${target} STREQUAL "linux")
idf_component_register(INCLUDE_DIRS include
idf_component_register(SRCS "linux/spi_flash_linux.c"
INCLUDE_DIRS include
PRIV_INCLUDE_DIRS include/spi_flash)
return()
endif()

Wyświetl plik

@ -0,0 +1,13 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_flash.h"
esp_err_t esp_flash_get_size(esp_flash_t *chip, uint32_t *out_size)
{
(void)chip;
*out_size = UINT32_MAX;
return ESP_OK;
}

Wyświetl plik

@ -8,4 +8,4 @@ examples/get-started/blink:
examples/get-started/hello_world:
enable:
- if: INCLUDE_DEFAULT == 1
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"

Wyświetl plik

@ -1,5 +1,5 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ----- |
# Hello World Example

Wyświetl plik

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import hashlib
@ -21,6 +21,12 @@ def test_hello_world(
log_minimum_free_heap_size()
@pytest.mark.linux
@pytest.mark.host_test
def test_hello_world_linux(dut: IdfDut) -> None:
dut.expect('Hello world!')
def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None:
sha256 = hashlib.sha256()
with open(app.elf_file, 'rb') as f:

Wyświetl plik

@ -15,10 +15,6 @@ tools/test_apps/linux_compatible/driver_mock:
enable:
- if: IDF_TARGET == "linux"
tools/test_apps/linux_compatible/hello_world_linux_compatible:
enable:
- if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux"
tools/test_apps/linux_compatible/linux_freertos:
enable:
- if: IDF_TARGET == "linux"

Wyświetl plik

@ -1,7 +0,0 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello_world)

Wyświetl plik

@ -1,45 +0,0 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ----- |
# Hello World Example Compatible with POSIX-port
This is a version of the "Hello World" example compatible with the linux target. Just by using `idf.py (--preview) set-target <target>`, it can be compiled for chip targets as well as for the [FreeRTOS POSIX/Linux simulator](https://www.freertos.org/FreeRTOS-simulator-for-Linux.html), i.e., for running it on Linux. The applications can then be run on the chosen target.
## Requirements
If you want to use this example on Linux, you need a Linux machine as host. The remaining requirements are the same requirements as for [Unit Testing on Linux (using cmock)](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/linux-host-testing.html#requirements), except you do not need Ruby.
## How to use example
### Configure the project
No special configuration is required, we also do not recommend changing configuration when compiled for the POSIX/Linux simulator as this is still in preview. If you have to configure something, use the usual IDF menuconfig:
```
idf.py menuconfig
```
### Build and Flash
You can compile this example for chip targets, e.g. ESP32 and then run it by using:
```
idf.py set-target esp32
idf.py build
idf.py -p <port> flash monitor
```
If you want to build this example for the linux target and run it, use the same commands except setting the linux target and omitting the flash command:
```
idf.py --preview set-target linux
idf.by build
idf.py monitor
```
The linux target is still in preview, hence the necessary `--preview` argument. Flashing can be omitted on Linux.
## Example folder contents
The files in this project have the same structure as the files in the [original Hello World application](../../../../examples/get-started/hello_world/).
## Example Output
The output is similar to the output of the [original Hello World application](../../../../examples/get-started/hello_world/), except that no chip information is printed and there won't be any bootloader output on the linux target.

Wyświetl plik

@ -1,2 +0,0 @@
idf_component_register(SRCS "hello_world_main.c"
INCLUDE_DIRS "")

Wyświetl plik

@ -1,49 +0,0 @@
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_system.h"
void app_main(void)
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
/* get_flash_size API not available on Linux*/
flash_size = UINT32_MAX;
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}

Wyświetl plik

@ -1,17 +0,0 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import pytest
from pytest_embedded_idf.dut import IdfDut
@pytest.mark.supported_targets
@pytest.mark.generic
def test_hello_world_linux_compatible(dut: IdfDut) -> None:
dut.expect('Hello world!')
@pytest.mark.linux
@pytest.mark.host_test
def test_hello_world_linux(dut: IdfDut) -> None:
dut.expect('Hello world!')