From 1648a3db1efae2554f61d8c472bca6fe581000a5 Mon Sep 17 00:00:00 2001 From: Bob Abeles Date: Fri, 1 Sep 2023 11:23:30 -0700 Subject: [PATCH] Fix IO register stores of multiple words --- .../raspberrypi/common-hal/memorymap/AddressRange.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/raspberrypi/common-hal/memorymap/AddressRange.c b/ports/raspberrypi/common-hal/memorymap/AddressRange.c index 3eac27fa63..6f6731a5ec 100644 --- a/ports/raspberrypi/common-hal/memorymap/AddressRange.c +++ b/ports/raspberrypi/common-hal/memorymap/AddressRange.c @@ -94,9 +94,9 @@ void common_hal_memorymap_addressrange_set_bytes(const memorymap_addressrange_ob } else { // Aligned access and length, use 32-bit writes uint32_t *dest_addr32 = (uint32_t *)dest_addr; - size_t len32 = len >> 2; - for (size_t i = 0; i < len32; i++) { - *dest_addr32++ = ((uint32_t *)values)[i << 2]; + size_t access_count = len >> 2; + for (size_t i = 0; i < access_count; i++) { + *dest_addr32++ = ((uint32_t *)values)[i]; } } break; @@ -124,10 +124,10 @@ void common_hal_memorymap_addressrange_get_bytes(const memorymap_addressrange_ob // Unaligned access or unaligned length not supported by RP2 for IO registers mp_raise_RuntimeError(translate("Unable to access unaliged IO register")); } else { - // Aligned access and length, use 32-bit writes + // Aligned access and length, use 32-bit reads uint32_t *src_addr32 = (uint32_t *)src_addr; - size_t len32 = len >> 2; - for (size_t i = 0; i < len32; i++) { + size_t access_count = len >> 2; + for (size_t i = 0; i < access_count; i++) { ((uint32_t *)values)[i] = *src_addr32++; } }