Skip to content
Open
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
47 changes: 47 additions & 0 deletions esp32_riscv_frozen_native_align.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake
index e3b1b81..6ec1f26 100644
--- a/ports/esp32/esp32_common.cmake
+++ b/ports/esp32/esp32_common.cmake
@@ -311,6 +311,15 @@ endforeach()
# Include the main MicroPython cmake rules.
include(${MICROPY_DIR}/py/mkrules.cmake)

+if(CONFIG_IDF_TARGET_ARCH_RISCV AND MICROPY_FROZEN_CONTENT)
+ # Frozen native code is emitted as byte arrays in a code section with a
+ # 4-byte alignment (tools/mpy-tool.py). With linker relaxation on, the
+ # assembler pads that alignment with R_RISCV_ALIGN NOPs, which cannot
+ # cover odd sizes ("can't relax section"); the file holds no code that
+ # could be relaxed, so assemble it without relaxation.
+ set_source_files_properties(${MICROPY_FROZEN_CONTENT} PROPERTIES COMPILE_OPTIONS "-mno-relax")
+endif()
+
# Generate source files for named pins (requires mkrules.cmake for MICROPY_GENHDR_DIR).

set(GEN_PINS_PREFIX "${MICROPY_PORT_DIR}/boards/pins_prefix.c")
diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py
index 67e2cbf..a61b0cc 100644
--- a/tools/mpy-tool.py
+++ b/tools/mpy-tool.py
@@ -1254,13 +1254,19 @@ class RawCodeNative(RawCode):
MP_NATIVE_ARCH_ARMV6,
MP_NATIVE_ARCH_XTENSA,
MP_NATIVE_ARCH_XTENSAWIN,
+ MP_NATIVE_ARCH_RV32IMC,
+ MP_NATIVE_ARCH_RV64IMC,
):
- # ARMV6 or Xtensa -- four byte align.
+ # ARMV6, Xtensa or RISC-V -- four byte align. RISC-V needs only two,
+ # but the assembler never pads a 2-byte alignment inside a code
+ # section, so arrays after an odd-sized one would start at an odd
+ # address (a 4-byte one is padded once relaxation is off, see
+ # ports/esp32/esp32_common.cmake).
self.fun_data_attributes += " __attribute__ ((aligned (4)))"
elif (
MP_NATIVE_ARCH_ARMV6M <= config.native_arch <= MP_NATIVE_ARCH_ARMV7EMDP
- ) or MP_NATIVE_ARCH_RV32IMC <= config.native_arch <= MP_NATIVE_ARCH_RV64IMC:
- # ARMVxxM or RV{32,64}IMC -- two byte align.
+ ):
+ # ARMVxxM -- two byte align.
self.fun_data_attributes += " __attribute__ ((aligned (2)))"

def disassemble(self):
15 changes: 15 additions & 0 deletions esp32_user_c_modules_abspath.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/builder/esp32.py b/builder/esp32.py
index 3f5fd15..bfc442d 100644
--- a/builder/esp32.py
+++ b/builder/esp32.py
@@ -612,7 +612,9 @@ def build_commands(_, extra_args, script_dir, lv_cflags, ___):
f'LV_CFLAGS="{lv_cflags}"',
f'LV_PORT=esp32',
f'BOARD={board}',
- 'USER_C_MODULES=../../../../../ext_mod/micropython.cmake'
+ # absolute: the relative form resolves against lib/micropython's real
+ # location, which is a different tree when lib/ is symlinked (git worktrees)
+ f'USER_C_MODULES={SCRIPT_DIR}/ext_mod/micropython.cmake'
])

# esp_cmd.extend(extra_args)
35 changes: 29 additions & 6 deletions ext_mod/lcd_bus/esp32_include/dsi_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
// esp-idf includes
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_interface.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_mipi_dsi.h"
#include "esp_ldo_regulator.h"

#if SOC_PPA_SUPPORTED
#include "driver/ppa.h"
#endif


typedef struct _mp_lcd_dsi_bus_obj_t {
// The first members mirror mp_lcd_bus_obj_t (lcd_types.h): the
// generic bus methods cast to it.
mp_obj_base_t base;

mp_obj_t callback;

void *buf1;
void *buf2;
mp_obj_array_t *view1;
mp_obj_array_t *view2;

uint32_t buffer_flags;

bool trans_done;
Expand All @@ -45,10 +52,26 @@
esp_lcd_dpi_panel_config_t panel_config;

uint32_t buffer_size;
mp_obj_array_t *view1;
mp_obj_array_t *view2;

void *transmitting_buf;
bool panel_started;

int phy_ldo_channel;
int phy_ldo_voltage_mv;
esp_ldo_channel_handle_t phy_ldo_handle;

// rotation (0/90/180/270 degrees, LVGL's sense): LVGL renders the
// rotated (logical) picture into its own buffers and every update
// is rotated into the panel's frame buffers by the PPA
int rotation;
uint8_t bpp;
uint32_t lvgl_width;
uint32_t lvgl_height;
uint8_t *panel_fbs[2];
uint8_t back_fb_index;
uint32_t fb_size_aligned;
#if SOC_PPA_SUPPORTED
ppa_client_handle_t ppa_client;
#endif

} mp_lcd_dsi_bus_obj_t;

Expand Down
Loading