Viper issues : how to replace ptr8: UNIX port RPI 4 #19341
Replies: 16 comments 26 replies
If plte and palette are declared as bytearrays, then they should be usable almost without a change. > def init_plte(po, pal): # CHANGE
> # po = ptr8(plte)
> # pal = ptr8(palette)
> for i in range(256): |
|
I am confused with "self." or not. |
|
Not trivial ! Palette not byte array ... The ptr8 viper function has no equivalence in micropython ? |
Which version af micropython are you running , and using what commandline ? Note: the outcomes to NOT match the comments 😕 Sample from : viper @ WiKi # File: vp8.py
import array
@micropython.viper
def myfunction( )->int:
int32_array = array.array("l", (1,2,3,4))
x = ptr32( int32_array )
print(x[0], x[1], x[2] ) # this will print 1, 2, 3
ba = bytearray(10)
y = ptr8(ba)
y[0] = 1 # This will change ba[0]
return x[1]
print("viper result:", myfunction())ran using: jos@SB26:~$ micropython ./vp8.py
1 0 2
viper result : 0
|
old version with sdl2 function added from russhughes edit : in this moment Raspberry PI 4 : reason of the issue ? |
|
not clear. |
|
First test on android tablette with termux. Classic build as readme.md from micropython github. |
|
with chatgpt help : Title Viper return value broken on unix ARM32 (Thumb) port Environment
Minimal reproducer Expected: 42 Actual: Illegal instruction @micropython.native works correctly. GDB shows: |
Raspberry Pi OS (32-bit)- cannot reproduceI overlooked that you were using RPIOS64 and focussed on the Based on that I can at least conclude that it works on a 32 bit OS using the below build
I only have a single SD card available currently - so I'll wait A BIT before overwriting it with RPIOS64 and retrying. Details
jos@emst32:~/micropython $ file ports/unix/build-standard/micropython
readelf -h ports/unix/build-standard/micropython | egrep 'Class|Machine'
ports/unix/build-standard/micropython: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=ab41894398a477666378184a5ee6b9a425832222, for GNU/Linux 3.2.0, stripped
Class: ELF32
Machine: ARM
$ uname -a
Linux emst32 6.18.34+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.18.34-1+rpt1 (2026-06-09) aarch64 GNU/Linux
# file: vp42.py
import micropython
print("- Defining @viper function")
@micropython.viper
def g() -> int:
return 42
print("- Calling @viper function")
x = g()
print(" - Result : ",x)
|
|
This is getting kind of weird though - the OS @picpic020960 reported in https://github.com/orgs/micropython/discussions/19341#discussioncomment-17343092 is 32 bits (armv6l, not aarch64). @picpic020960 can you please confirm the exact version of the OS you're experiencing the crash on? If |
|
Uname -m ===> AARCH64 |
I notice that is different from what you reported earlier , are these different devices or a different OS on the same device. Anyway, on Unix/Aarch64 viper does not exist unfortunately. An Aarch32 crosscompiled version does have viper, but does not run viper code stably on Aarch64 so far. See earlier comment. I think there are a few doc and other issues that could be created from this. |
apologies : the above (15 jun) uname is for PI 3 B [+?] |
|
j'ai essayé de produire un MIcropython 32 bit via termux mais j'ai echoué |
|
It's still disappointing, though. |
|
These changes seem to work for me, can you please give this a try and tell me if it works over there? diff --git a/py/emitglue.c b/py/emitglue.c
index 9526acac8..491da8768 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -108,12 +108,16 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, cons
// so that the generated native code which was created in data RAM will
// be available for execution from instruction RAM.
#if defined(__thumb__) || defined(__thumb2__)
+ #if (defined(__linux__) && defined(__GNUC__)) || __ARM_ARCH == 7
+ __builtin___clear_cache((void *)fun_data, (char *)fun_data + fun_len);
+ #else
#if __ICACHE_PRESENT == 1
// Flush D-cache, so the code emitted is stored in RAM.
MP_HAL_CLEAN_DCACHE(fun_data, fun_len);
// Invalidate I-cache, so the newly-created code is reloaded from RAM.
SCB_InvalidateICache();
#endif
+ #endif
#elif defined(__arm__)
#if (defined(__linux__) && defined(__GNUC__)) || __ARM_ARCH == 7
__builtin___clear_cache((void *)fun_data, (char *)fun_data + fun_len); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Bonjour,
I test micropython app on ESP32 TTGO watch : OK
Then the same app on unix port.
But on unix port no viper decorator .
So comment decorator : ok for basic function but on function with ptr8 I am stuck.
Exists some workarround or trick ?
Thank's for help and link
Regards
All reactions