Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 53 additions & 8 deletions gateway/esp32-rv/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
BUILD_PATH = '.'
process_holder = {}


#### (*) Cleaning functions
def do_fullclean_request(request):
""" Full clean the build directory """
Expand Down Expand Up @@ -81,7 +82,6 @@ def do_stop_monitor_request(request):
if error == 0:
req_data['status'] += 'Process stopped\n'


except Exception as e:
req_data['status'] += str(e) + '\n'

Expand Down Expand Up @@ -151,7 +151,6 @@ def do_cmd(req_data, cmd_array):

return req_data['error']


def do_cmd_output(req_data, cmd_array):
try:
result = subprocess.run(cmd_array, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=60)
Expand Down Expand Up @@ -443,7 +442,6 @@ def kill_all_processes(process_name):
logging.error(f"Ocurrió un error inesperado: {e}")
return 1


# (4.3) OpenOCD Function
def start_openocd_thread(req_data):
target_board = req_data['target_board']
Expand All @@ -462,8 +460,10 @@ def start_openocd_thread(req_data):
req_data['status'] += f"Error starting OpenOCD: {str(e)}\n"
logging.error(f"Error starting OpenOCD: {str(e)}")
return None

# (4.4) GDBGUI function
def start_gdbgui(req_data):
target_device = req_data['target_port']
route = os.path.join(BUILD_PATH, 'gdbinit')
logging.debug(f"GDB route: {route}")
route = os.path.join(BUILD_PATH, 'gdbinit')
Expand All @@ -474,7 +474,7 @@ def start_gdbgui(req_data):
req_data['status'] += f"GDB route: {route} does not exist.\n"
return jsonify(req_data)
req_data['status'] = ''
if check_uart_connection():
if check_uart_connection(target_device) != 0:
req_data['status'] += f"No UART found\n"
return jsonify(req_data)

Expand Down Expand Up @@ -503,8 +503,6 @@ def start_gdbgui(req_data):
req_data['status'] += f"Finished debug session: {e}\n"
return jsonify(req_data)



def do_debug_request(request):
global stop_event
global process_holder
Expand All @@ -529,7 +527,7 @@ def do_debug_request(request):
kill_all_processes("openocd")
process_holder.pop('openocd', None)
# Check UART
if check_uart_connection():
if check_uart_connection(target_device) != 0:
req_data['status'] += f"No UART found\n"
return jsonify(req_data)
# Check if JTAG is connected
Expand Down Expand Up @@ -560,6 +558,48 @@ def do_debug_request(request):
return jsonify(req_data)


# (5) Flasing assembly program into target board
def do_job_request(request):
try:
req_data = request.get_json()
target_device = req_data['target_port']
target_board = req_data['target_board']
asm_code = req_data['assembly']
req_data['status'] = ''

# create temporal assembly file
text_file = open("tmp_assembly.s", "w")
ret = text_file.write(asm_code)
text_file.close()

# transform th temporal assembly file
error = creator_build('tmp_assembly.s', "main/program.s");
if error != 0:
req_data['status'] += 'Error adapting assembly file...\n'

# flashing steps...
if error == 0:
error = do_cmd_output(req_data, ['idf.py', 'fullclean'])
if error == 0:
error = do_cmd_output(req_data, ['idf.py', 'set-target', target_board])
if error == 0:
error = do_cmd_output(req_data, ['idf.py', 'build'])
if error == 0:
error = do_cmd_output(req_data, ['idf.py', '-p', target_device, 'flash'])
if error == 0:
error = do_cmd_output(req_data, ['./gateway_monitor.sh', target_device, '50'])
error = do_cmd_output(req_data, ['cat', 'monitor_output.txt'])
error = do_cmd_output(req_data, ['rm', 'monitor_output.txt'])

except Exception as e:
req_data['status'] += str(e) + '\n'

return jsonify(req_data)





# Setup flask and cors:
app = Flask(__name__)
cors = CORS(app)
Expand Down Expand Up @@ -588,7 +628,6 @@ def post_flash():
def post_monitor():
return do_monitor_request(request)


# (4) POST /fullclean -> clean build directory
@app.route("/fullclean", methods=["POST"])
@cross_origin()
Expand All @@ -613,6 +652,12 @@ def post_debug():
def post_stop_monitor():
return do_stop_monitor_request(request)

# (8) POST /job -> flash + monitor
@app.route("/job", methods=["POST"])
@cross_origin()
def post_job():
return do_job_request(request)


# Run
app.run(host='0.0.0.0', port=8080, use_reloader=False, debug=True)
Binary file modified gateway/esp32c2.zip
Binary file not shown.
Binary file modified gateway/esp32c3.zip
Binary file not shown.
Binary file modified gateway/esp32c6.zip
Binary file not shown.
Binary file modified gateway/esp32h2.zip
Binary file not shown.
Binary file modified gateway/esp32s2.zip
Binary file not shown.
Binary file modified gateway/esp32s3.zip
Binary file not shown.