micropython / micropython-lib

Core Python libraries ported to MicroPython
Other
2.4k stars 997 forks source link

Writing to RAM via bytearray_at is broken in ports/esp8266 #514

Closed prandeamus closed 2 years ago

prandeamus commented 2 years ago

The ESP8266 has some memory associated with the RTC which retains contents across reset/deepsleep so long as the power is kept on. It's mapped to address 0x60001200. I can verify that the contents are retained so long as power is kept on. Reads through the uctypes.bytearray_at seem ok, but it seems that writes messed up. Here's an example which defines an array of 256 bytes at 0x60001200 and attempts to assign consecutive values to consecutive bytes

import uctypes

by = uctypes.bytearray_at(0x60001200, 256)
for i in range(0,256):
    by[i] = i

st = ''.join('{:02X} '.format(b) for b in by)
print(st)

I'd expect results 00 01 02 03 etc. but instead

03 03 03 03 07 07 07 07 0B 0B 0B 0B 0F 0F 0F 0F 13 13 13 13 17 17 17 17 1B 1B 1B 1B 1F 1F 1F 1F 23 23 23 23 27 27 27 27 2B 2B 2B 2B 2F 2F 2F 2F 33 33 33 33 37 37 37 37 3B 3B 3B 3B 3F 3F 3F 3F 43 43 43 43 47 47 47 47 4B 4B 4B 4B 4F 4F 4F 4F 53 53 53 53 57 57 57 57 5B 5B 5B 5B 5F 5F 5F 5F 63 63 63 63 67 67 67 67 6B 6B 6B 6B 6F 6F 6F 6F 73 73 73 73 77 77 77 77 7B 7B 7B 7B 7F 7F 7F 7F 83 83 83 83 87 87 87 87 8B 8B 8B 8B 8F 8F 8F 8F 93 93 93 93 97 97 97 97 9B 9B 9B 9B 9F 9F 9F 9F A3 A3 A3 A3 A7 A7 A7 A7 AB AB AB AB AF AF AF AF B3 B3 B3 B3 B7 B7 B7 B7 BB BB BB BB BF BF BF BF C3 C3 C3 C3 C7 C7 C7 C7 CB CB CB CB CF CF CF CF D3 D3 D3 D3 D7 D7 D7 D7 DB DB DB DB DF DF DF DF E3 E3 E3 E3 E7 E7 E7 E7 EB EB EB EB EF EF EF EF F3 F3 F3 F3 F7 F7 F7 F7 FB FB FB FB FF FF FF FF 

Looks like something's not quite right at the 32-bit word boundary? This is official image MicroPython v1.19.1 on 2022-06-18; ESP module with ESP8266

Relative newcomer to Micropython so please accept my apologies if this a rookie error.

prandeamus commented 2 years ago

Apologies, this should be in /micropython, not /micropython-lib. I'll close and re-open it there.