71
ScriptBasic / Re: Pico
« Last post by John Spikowski on February 28, 2021, 12:09:14 PM »I was able to get CBASIC working with the ESP32-PICO. This is an example of random number generation and calculating the mean value. This example shows using a separate C program as a component.
mean.c
testable.h
pi@RPi3B:~/esp/unit_test $ idf.py -p /dev/ttyUSB0 monitor
WARNING: Python 3 versions older than 3.6 are not supported.
Executing action: monitor
Running idf_monitor in directory /home/pi/esp/unit_test
Executing "/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python /home/pi/esp/esp-idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- /home/pi/esp/unit_test/build/unit_test.elf -m '/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python' '/home/pi/esp/esp-idf/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6916
load:0x40078000,len:14336
ho 0 tail 12 room 4
load:0x40080400,len:3672
0x40080400: _init at ??:?
entry 0x40080678
I (30) boot: ESP-IDF v4.4-dev-4-g73db14240 2nd stage bootloader
I (30) boot: compile time 03:48:52
I (30) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed : 40MHz
I (46) boot.esp32: SPI Mode : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label Usage Type ST Offset Length
I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (78) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (86) boot: 2 factory factory app 00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=05bbch ( 23484) map
I (121) esp_image: segment 1: paddr=00015be4 vaddr=3ffb0000 size=02860h ( 10336) load
I (126) esp_image: segment 2: paddr=0001844c vaddr=40080000 size=07bcch ( 31692) load
I (143) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=1337ch ( 78716) map
I (171) esp_image: segment 4: paddr=000333a4 vaddr=40087bcc size=02f6ch ( 12140) load
I (182) boot: Loaded app from partition at offset 0x10000
I (182) boot: Disabling RNG early entropy source...
I (194) cpu_start: Pro cpu up.
I (194) cpu_start: Starting app cpu, entry point is 0x40080f34
0x40080f34: call_start_cpu1 at /home/pi/esp/esp-idf/components/esp_system/port/cpu_start.c:143
I (0) cpu_start: App cpu up.
I (208) cpu_start: Pro cpu start user code
I (208) cpu_start: cpu freq: 160000000
I (208) cpu_start: Application information:
I (212) cpu_start: Project name: unit_test
I (218) cpu_start: App version: 1
I (222) cpu_start: Compile time: Feb 28 2021 03:51:29
I (228) cpu_start: ELF file SHA256: 39e44e816ec30d58...
I (234) cpu_start: ESP-IDF: v4.4-dev-4-g73db14240
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (248) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (254) heap_init: At 3FFB3088 len 0002CF78 (179 KiB): DRAM
I (260) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (266) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (273) heap_init: At 4008AB38 len 000154C8 (85 KiB): IRAM
I (280) spi_flash: detected chip: gd
I (283) spi_flash: flash io: dio
W (287) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (301) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
In main application. Collecting 32 random numbers from 1 to 100:
76 26 40 9 74 28 37 19 78 66
99 75 29 63 48 22 2 1 65 37
54 63 25 24 20 75 4 31 32 75
30 90
Mean: 44
pi@RPi3B:~/esp/unit_test $
Code: C
- #include <stdio.h>
- #include "esp_system.h"
- #include "testable.h"
- #include "cbasic.h"
- SUB app_main(void)
- BEGIN_SUB
- CONST int count = 32;
- CONST int max = 100;
- PRINT("In main application. Collecting %d random numbers from 1 to %d:\n", count, max);
- DEF_FOR(int i = 0 TO i < count STEP INCR i)
- BEGIN_FOR
- numbers[i] = 1 + esp_random() MOD (max - 1);
- PRINT("%4d ", numbers[i]);
- IF ((i + 1) MOD 10 == 0) THEN
- PRINT("\n");
- END_IF
- NEXT
- DIM int AS mean = testable_mean(numbers, count);
- PRINT ("\nMean: %d\n", mean);
- END_SUB
mean.c
Code: C
- #include "testable.h"
- #include "cbasic.h"
- FUNCTION int testable_mean(const int PTR values, int count)
- BEGIN_FUNCTION
- IF (count == 0) THEN
- RETURN_FUNCTION(0);
- END_IF
- DIM int AS sum = 0;
- DEF_FOR (int i = 0 TO i < count STEP INCR i)
- BEGIN_FOR
- sum += values[i];
- NEXT
- RETURN_FUNCTION(sum / count);
- END_FUNCTION
testable.h
Code: C
- #pragma once
- /**
- * @brief Calculate arithmetic mean of integer values
- * @param values array of values
- * @param count number of elements in the array
- * @return arithmetic mean of values, or zero count is zero
- */
- int testable_mean(const int* values, int count);
pi@RPi3B:~/esp/unit_test $ idf.py -p /dev/ttyUSB0 monitor
WARNING: Python 3 versions older than 3.6 are not supported.
Executing action: monitor
Running idf_monitor in directory /home/pi/esp/unit_test
Executing "/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python /home/pi/esp/esp-idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- /home/pi/esp/unit_test/build/unit_test.elf -m '/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python' '/home/pi/esp/esp-idf/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6916
load:0x40078000,len:14336
ho 0 tail 12 room 4
load:0x40080400,len:3672
0x40080400: _init at ??:?
entry 0x40080678
I (30) boot: ESP-IDF v4.4-dev-4-g73db14240 2nd stage bootloader
I (30) boot: compile time 03:48:52
I (30) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed : 40MHz
I (46) boot.esp32: SPI Mode : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label Usage Type ST Offset Length
I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (78) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (86) boot: 2 factory factory app 00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=05bbch ( 23484) map
I (121) esp_image: segment 1: paddr=00015be4 vaddr=3ffb0000 size=02860h ( 10336) load
I (126) esp_image: segment 2: paddr=0001844c vaddr=40080000 size=07bcch ( 31692) load
I (143) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=1337ch ( 78716) map
I (171) esp_image: segment 4: paddr=000333a4 vaddr=40087bcc size=02f6ch ( 12140) load
I (182) boot: Loaded app from partition at offset 0x10000
I (182) boot: Disabling RNG early entropy source...
I (194) cpu_start: Pro cpu up.
I (194) cpu_start: Starting app cpu, entry point is 0x40080f34
0x40080f34: call_start_cpu1 at /home/pi/esp/esp-idf/components/esp_system/port/cpu_start.c:143
I (0) cpu_start: App cpu up.
I (208) cpu_start: Pro cpu start user code
I (208) cpu_start: cpu freq: 160000000
I (208) cpu_start: Application information:
I (212) cpu_start: Project name: unit_test
I (218) cpu_start: App version: 1
I (222) cpu_start: Compile time: Feb 28 2021 03:51:29
I (228) cpu_start: ELF file SHA256: 39e44e816ec30d58...
I (234) cpu_start: ESP-IDF: v4.4-dev-4-g73db14240
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (248) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (254) heap_init: At 3FFB3088 len 0002CF78 (179 KiB): DRAM
I (260) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (266) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (273) heap_init: At 4008AB38 len 000154C8 (85 KiB): IRAM
I (280) spi_flash: detected chip: gd
I (283) spi_flash: flash io: dio
W (287) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (301) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
In main application. Collecting 32 random numbers from 1 to 100:
76 26 40 9 74 28 37 19 78 66
99 75 29 63 48 22 2 1 65 37
54 63 25 24 20 75 4 31 32 75
30 90
Mean: 44
pi@RPi3B:~/esp/unit_test $