Skip to content

Prerelease 0.2.0 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
67bd297
Switch to karalabe/hid to allow cross compiling
facchinm Jun 28, 2023
b078697
Try to fix enumeration error on win
facchinm Jul 3, 2023
60dc088
USB: set manufacturer name to Arduino
facchinm Jul 3, 2023
1094c0e
Modify AT+RESET to allow reboot to bootloader
facchinm Jul 3, 2023
919d640
BLE: add initial support for ArduinoBLE shim
facchinm Jul 3, 2023
5248bc0
remove code to get fw version
pennam Jul 3, 2023
9005c55
Add hid submodule
pennam Jul 3, 2023
ef587df
Add print if no board is connected
pennam Jul 3, 2023
dc72b22
Make scripts executable
pennam Jul 3, 2023
e90a342
Add print to check if Enumerate call fails
pennam Jul 3, 2023
7bc8a2f
Don't try to open two times
pennam Jul 3, 2023
0be0c7f
BLE: fix functionality
facchinm Jul 3, 2023
72d0d2e
Merge remote-tracking branch 'origin/main' into ble_support
facchinm Jul 3, 2023
ef9062a
Merge remote-tracking branch 'origin/win-hid-fix' into ble_support
facchinm Jul 3, 2023
0986b22
Publish 0.2.0
facchinm Jul 3, 2023
a45dfe4
wip: add script to vendor esp32 core
facchinm Jul 4, 2023
627a7c3
ble: fix chunked read()
facchinm Jul 4, 2023
7373dec
Publish 0.2.0
facchinm Jul 3, 2023
2db7363
serial: flush on baud change
facchinm Jul 4, 2023
ddb7aa5
Fix typo
pennam Jul 4, 2023
b218c25
Fix fqbn
pennam Jul 4, 2023
9924d76
Add symbolic links to esptool and toolchain
pennam Jul 4, 2023
356f1f7
Add ArduinoBLE library
pennam Jul 5, 2023
4ae014f
Download core and tools only once
pennam Jul 5, 2023
bf71400
Adapt export and combine scripts to new compile flow
pennam Jul 5, 2023
d28a74d
Move certificate bundle and binary blob in the sketch build directory
pennam Jul 5, 2023
5b1cb1f
Merge remote-tracking branch 'origin/bundled-esp32-core' into ble_sup…
facchinm Jul 5, 2023
f498595
compile.sh: add -e to export binaries
facchinm Jul 5, 2023
cc08508
Fix bridge product name
pennam Jul 3, 2023
189ec9d
unor4wifi-reboot: use local hid submodule library
facchinm Jul 5, 2023
cd63b00
at_commands: fix AT+RESET peculiar behaviour
facchinm Jul 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "unor4wifi-reboot/hid"]
path = unor4wifi-reboot/hid
url = https://github.com/pennam/hid.git
4 changes: 4 additions & 0 deletions UNOR4USBBridge/UNOR4USBBridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void setup() {
#else
USB.VID(0x2341);
USB.PID(0x1002);
USB.manufacturerName("Arduino");
USB.productName("UNO WiFi R4 CMSIS-DAP");
//USB.enableDFU();
DAP.begin();
Expand Down Expand Up @@ -205,6 +206,9 @@ void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id,
} else {
SERIAL_USER_INTERNAL.updateBaudRate(baud);
}
while (SERIAL_USER_INTERNAL.available()) {
SERIAL_USER_INTERNAL.read();
}
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions UNOR4USBBridge/at_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "cmds_wifi_netif.h"
#include "cmds_wifi_SSL.h"
#include "cmds_wifi_udp.h"
#include "cmds_ble_bridge.h"

using namespace SudoMaker;

Expand Down Expand Up @@ -124,4 +125,5 @@ CAtHandler::CAtHandler(HardwareSerial *s) : last_server_client_sock(0) {
add_cmds_wifi_SSL();
add_cmds_wifi_netif();
add_cmds_wifi_udp();
add_cmds_ble_bridge();
}
7 changes: 4 additions & 3 deletions UNOR4USBBridge/at_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#define MAX_SERVER_AVAILABLE 4
#define MAX_UDP_AVAILABLE 4

#define ESP_FW_VERSION "0.1.0"
#define ESP_FW_VERSION "0.2.0"
#define FIRMWARE_MAYOR 0
#define FIRMWARE_MINOR 1
#define FIRMWARE_MINOR 2
#define FIRMWARE_PATCH 0

using namespace SudoMaker;
Expand Down Expand Up @@ -75,7 +75,8 @@ class CAtHandler {
void add_cmds_wifi_softAP();
void add_cmds_wifi_SSL();
void add_cmds_wifi_netif();
void add_cmds_wifi_udp();
void add_cmds_wifi_udp();
void add_cmds_ble_bridge();
public:
std::vector<std::uint8_t> cert_buf;
CAtHandler(HardwareSerial *s);
Expand Down
158 changes: 158 additions & 0 deletions UNOR4USBBridge/cmds_ble_bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#ifndef CMDS_BLE_BRIDGE_H
#define CMDS_BLE_BRIDGE_H

#include "at_handler.h"
#include "ArduinoBLE.h"
#include "utility/HCIVirtualTransport.h"

extern HCIVirtualTransportClass HCIVirtualTransport;

void CAtHandler::add_cmds_ble_bridge() {

/* ....................................................................... */
command_table[_HCI_BEGIN] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
srv.write_response_prompt();
switch (parser.cmd_mode) {
case chAT::CommandMode::Run: {
auto res = HCIVirtualTransport.begin();
if (res) {
return chAT::CommandStatus::OK;
}
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
command_table[_HCI_END] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
srv.write_response_prompt();
switch (parser.cmd_mode) {
case chAT::CommandMode::Run: {
HCIVirtualTransport.end();
return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
command_table[_HCI_WAIT] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
srv.write_response_prompt();
switch (parser.cmd_mode) {
case chAT::CommandMode::Write: {
if (parser.args.size() != 1) {
return chAT::CommandStatus::ERROR;
}

auto &timeout = parser.args[0];
if (timeout.empty()) {
return chAT::CommandStatus::ERROR;
}
int _timeout = atoi(timeout.c_str());
HCIVirtualTransport.wait(_timeout);
return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
command_table[_HCI_AVAILABLE] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Read: {
srv.write_response_prompt();
String av(HCIVirtualTransport.available());
srv.write_str((const char *)(av.c_str()));
srv.write_line_end();
return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
command_table[_HCI_READ] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Run: {
std::vector<uint8_t> data;
int i = 0;
auto howmany = HCIVirtualTransport.available();
while (i < howmany) {
data.push_back(HCIVirtualTransport.read());
i++;
}
data.resize(howmany);
srv.write_response_prompt();
srv.write_str(String(i).c_str());
srv.write_str("|");
srv.write_vec8(data);

return chAT::CommandStatus::OK;
}
default:
return chAT::CommandStatus::ERROR;
}
};

/* ....................................................................... */
command_table[_HCI_WRITE] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Write: {

if (parser.args.size() != 1) {
return chAT::CommandStatus::ERROR;
}

/* data len */
auto &size_p = parser.args[0];
if (size_p.empty()) {
return chAT::CommandStatus::ERROR;
}

int data_size = atoi(size_p.c_str());

if(data_size <= 0) {
return chAT::CommandStatus::ERROR;
}

/* -----------------------------------
* BEGIN TRANSPARENT DATA TRANSMISSION
* ----------------------------------- */
std::vector<uint8_t> data_received;
data_received = srv.inhibit_read(data_size);
size_t offset = data_received.size();

if(offset < data_size) {

data_received.resize(data_size);
do {
offset += serial->read(data_received.data() + offset, data_size - offset);
} while (offset < data_size);
}

srv.continue_read();

unsigned long start_time = millis();
int sent = 0;
while(millis() - start_time < 5000 && sent < data_received.size()){
sent += HCIVirtualTransport.write(data_received.data() + sent, data_received.size() - sent);
}

if (sent < data_received.size()) {
return chAT::CommandStatus::ERROR;
}

return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};
}

#endif
26 changes: 23 additions & 3 deletions UNOR4USBBridge/cmds_esp_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@
#define CMDS_ESP_GENERIC_H

#include "at_handler.h"
extern "C" {
#include "esp32-hal-tinyusb.h"
}

void CAtHandler::add_cmds_esp_generic() {

/* ....................................................................... */
command_table[_RESET] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
ESP.restart();
return chAT::CommandStatus::OK;
switch (parser.cmd_mode) {
case chAT::CommandMode::Run: {
ESP.restart();
return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
command_table[_RESTART_BOOTLOADER] = [this](auto & srv, auto & parser) {
/* ....................................................................... */
switch (parser.cmd_mode) {
case chAT::CommandMode::Run: {
usb_persist_restart(RESTART_BOOTLOADER);
return chAT::CommandStatus::OK;
}
}
return chAT::CommandStatus::ERROR;
};

/* ....................................................................... */
Expand Down
7 changes: 7 additions & 0 deletions UNOR4USBBridge/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ enum {
#define _SOFTAPCONFIG "+SOFTAPCONFIG"
#define _SERVERWRITE "+SERVERWRITE"

#define _HCI_BEGIN "+HCIBEGIN"
#define _HCI_END "+HCIEND"
#define _HCI_WAIT "+HCIWAIT"
#define _HCI_READ "+HCIREAD"
#define _HCI_WRITE "+HCIWRITE"
#define _HCI_AVAILABLE "+HCIAVAILABLE"



#define CMD(x) _AT x _ENDL
Expand Down
2 changes: 1 addition & 1 deletion UNOR4USBBridge/dap_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define DAP_CONFIG_FAST_CLOCK 2400000 // Hz

#define DAP_CONFIG_VENDOR_STR "Arduino"
#define DAP_CONFIG_PRODUCT_STR "Santiago CMSIS-DAP Adapter"
#define DAP_CONFIG_PRODUCT_STR "UNO R4 WiFi CMSIS-DAP Adapter"
#define DAP_CONFIG_SER_NUM_STR "123456789101112"
#define DAP_CONFIG_CMSIS_DAP_VER_STR "2.0.0"

Expand Down
24 changes: 24 additions & 0 deletions arduino-cli.yaml.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
board_manager:
additional_urls: []
build_cache:
compilations_before_purge: 10
ttl: 720h0m0s
daemon:
port: "50051"
directories:
user: PWD
library:
enable_unsafe_install: false
logging:
file: ""
format: text
level: info
metrics:
addr: :9090
enabled: true
output:
no_color: false
sketch:
always_export_binaries: false
updater:
enable_notification: true
10 changes: 5 additions & 5 deletions combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import sys;

booloaderData = open("UNOR4USBBridge/build/esp32.esp32.esp32s3/UNOR4USBBridge.ino.bootloader.bin", "rb").read()
partitionData = open("UNOR4USBBridge/build/esp32.esp32.esp32s3/UNOR4USBBridge.ino.partitions.bin", "rb").read()
booloaderData = open("UNOR4USBBridge/build/esp32-patched.esp32.esp32s3/UNOR4USBBridge.ino.bootloader.bin", "rb").read()
partitionData = open("UNOR4USBBridge/build/esp32-patched.esp32.esp32s3/UNOR4USBBridge.ino.partitions.bin", "rb").read()
bootApp = open("boot/boot_app0.bin", "rb").read()
appData = open("UNOR4USBBridge/build/esp32.esp32.esp32s3/UNOR4USBBridge.ino.bin", "rb").read()
certsData = open("x509_crt_bundle", "rb").read()
appData = open("UNOR4USBBridge/build/esp32-patched.esp32.esp32s3/UNOR4USBBridge.ino.bin", "rb").read()
certsData = open("UNOR4USBBridge/build/esp32-patched.esp32.esp32s3/x509_crt_bundle", "rb").read()

# 0x000000 bootloader
# 0x008000 partitions
Expand Down Expand Up @@ -39,7 +39,7 @@
outputData[0x3C0000 + i] = certsData[i]


outputFilename = "S3.bin"
outputFilename = "UNOR4USBBridge/build/esp32-patched.esp32.esp32s3/S3.bin"
if (len(sys.argv) > 1):
outputFilename = sys.argv[1]

Expand Down
23 changes: 22 additions & 1 deletion compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# modify esp32 platform.txt from g++11 to gcc+17

arduino-cli compile --fqbn=esp32:esp32:esp32s3:JTAGAdapter=default,PSRAM=disabled,FlashMode=qio,FlashSize=4M,LoopCore=1,EventsCore=1,USBMode=default,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,PartitionScheme=huge_app,CPUFreq=240,UploadSpeed=921600,DebugLevel=none,EraseFlash=none -v UNOR4USBBridge
if [ ! -d hardware ]; then
mkdir -p hardware/esp32-patched
cd hardware/esp32-patched
git clone https://github.com/espressif/arduino-esp32 -b 2.0.9 --depth=1 esp32
cd esp32
patch -p1 < ../../../core_esp32.patch
./tools/get.py
cd ../../../

sed s#PWD#$PWD#g arduino-cli.yaml.orig > arduino-cli.yaml

cd hardware/esp32-patched/esp32/libraries
git clone https://github.com/facchinm/ArduinoBLE.git
cd ArduinoBLE/
git checkout uno_r4_wifi
cd ../../../../../

ln -s $(pwd)/hardware/esp32-patched/esp32/esptool hardware/esp32-patched/esp32/tools/esptool
ln -s $(pwd)/hardware/esp32-patched/esp32/xtensa-esp32s3-elf hardware/esp32-patched/esp32/tools/xtensa-esp32s3-elf
fi

arduino-cli compile -e --config-file arduino-cli.yaml --fqbn=esp32-patched:esp32:esp32s3:JTAGAdapter=default,PSRAM=disabled,FlashMode=qio,FlashSize=4M,LoopCore=1,EventsCore=1,USBMode=default,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,PartitionScheme=huge_app,CPUFreq=240,UploadSpeed=921600,DebugLevel=none,EraseFlash=none -v UNOR4USBBridge
Loading