Merge pull request #7942 from furbrain/main
Add memorymap support to nrf boards
This commit is contained in:
commit
7cd65ffb40
136
ports/nrf/common-hal/memorymap/AddressRange.c
Normal file
136
ports/nrf/common-hal/memorymap/AddressRange.c
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
|
||||
#include "shared-bindings/memorymap/AddressRange.h"
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
|
||||
#ifdef NRF51_SERIES
|
||||
size_t allow_ranges[][2] = {
|
||||
// FLASH
|
||||
{0x00000000, 0x00040000},
|
||||
// FICR & UICR ranges
|
||||
{0x10000000, 0x10002000},
|
||||
// RAM
|
||||
{0x20000000, 0x20010000},
|
||||
// PERIPHERALS
|
||||
{0x40000000, 0x60000000}
|
||||
};
|
||||
#elif defined NRF52_SERIES
|
||||
size_t allow_ranges[][2] = {
|
||||
// FLASH
|
||||
{0x00000000, 0x00100000},
|
||||
// FICR & UICR ranges
|
||||
{0x10000000, 0x10002000},
|
||||
// RAM
|
||||
{0x20000000, 0x20040000},
|
||||
// PERIPHERALS
|
||||
{0x40000000, 0x60000000}
|
||||
};
|
||||
#elif defined NRF53_SERIES
|
||||
size_t allow_ranges[][2] = {
|
||||
// FLASH
|
||||
{0x00000000, 0x00100000},
|
||||
// FICR & UICR ranges
|
||||
{0x00FF0000, 0x01000000},
|
||||
// RAM
|
||||
{0x20000000, 0x20080000},
|
||||
// PERIPHERALS
|
||||
{0x40000000, 0x60000000},
|
||||
{0xE0000000, 0xE0100000}
|
||||
};
|
||||
#else
|
||||
#error "Unsupported nRF variant"
|
||||
#endif
|
||||
|
||||
void common_hal_memorymap_addressrange_construct(memorymap_addressrange_obj_t *self, uint8_t *start_address, size_t length) {
|
||||
bool allowed = false;
|
||||
for (size_t i = 0; i < MP_ARRAY_SIZE(allow_ranges); i++) {
|
||||
uint8_t *allowed_start = (uint8_t *)allow_ranges[i][0];
|
||||
uint8_t *allowed_end = (uint8_t *)allow_ranges[i][1];
|
||||
if (allowed_start <= start_address &&
|
||||
(start_address + length) <= allowed_end) {
|
||||
allowed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowed) {
|
||||
mp_raise_ValueError(translate("Address range not allowed"));
|
||||
}
|
||||
|
||||
self->start_address = start_address;
|
||||
self->len = length;
|
||||
}
|
||||
|
||||
uint32_t common_hal_memorymap_addressrange_get_length(const memorymap_addressrange_obj_t *self) {
|
||||
return self->len;
|
||||
}
|
||||
|
||||
|
||||
bool common_hal_memorymap_addressrange_set_bytes(const memorymap_addressrange_obj_t *self,
|
||||
uint32_t start_index, uint8_t *values, uint32_t len) {
|
||||
uint8_t *address = self->start_address + start_index;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
if (len == 1) {
|
||||
*((uint8_t *)address) = values[0];
|
||||
} else if (len == sizeof(uint16_t) && (((size_t)address) % sizeof(uint16_t)) == 0) {
|
||||
*((uint16_t *)address) = ((uint16_t *)values)[0];
|
||||
} else if (len == sizeof(uint32_t) && (((size_t)address) % sizeof(uint32_t)) == 0) {
|
||||
*((uint32_t *)address) = ((uint32_t *)values)[0];
|
||||
} else if (len == sizeof(uint64_t) && (((size_t)address) % sizeof(uint64_t)) == 0) {
|
||||
*((uint64_t *)address) = ((uint64_t *)values)[0];
|
||||
} else {
|
||||
memcpy(address, values, len);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void common_hal_memorymap_addressrange_get_bytes(const memorymap_addressrange_obj_t *self,
|
||||
uint32_t start_index, uint32_t len, uint8_t *values) {
|
||||
uint8_t *address = self->start_address + start_index;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
if (len == 1) {
|
||||
values[0] = *((uint8_t *)address);
|
||||
} else if (len == sizeof(uint16_t) && (((size_t)address) % sizeof(uint16_t)) == 0) {
|
||||
((uint16_t *)values)[0] = *((uint16_t *)address);
|
||||
} else if (len == sizeof(uint32_t) && (((size_t)address) % sizeof(uint32_t)) == 0) {
|
||||
((uint32_t *)values)[0] = *((uint32_t *)address);
|
||||
} else if (len == sizeof(uint64_t) && (((size_t)address) % sizeof(uint64_t)) == 0) {
|
||||
((uint64_t *)values)[0] = *((uint64_t *)address);
|
||||
} else {
|
||||
memcpy(values, address, len);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
38
ports/nrf/common-hal/memorymap/AddressRange.h
Normal file
38
ports/nrf/common-hal/memorymap/AddressRange.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 microDev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_MEMORYMAP_ADDRESSRANGE_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_MEMORYMAP_ADDRESSRANGE_H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint8_t *start_address;
|
||||
size_t len;
|
||||
} memorymap_addressrange_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_MEMORYMAP_ADDRESSRANGE_H
|
1
ports/nrf/common-hal/memorymap/__init__.c
Normal file
1
ports/nrf/common-hal/memorymap/__init__.c
Normal file
@ -0,0 +1 @@
|
||||
// No memorymap module functions.
|
@ -47,6 +47,7 @@ CIRCUITPY_SERIAL_BLE ?= 1
|
||||
|
||||
CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 1
|
||||
|
||||
|
||||
# nRF52840-specific
|
||||
|
||||
ifeq ($(MCU_CHIP),nrf52840)
|
||||
@ -56,6 +57,7 @@ MCU_SUB_VARIANT = nrf52840
|
||||
|
||||
# Fits on nrf52840 but space is tight on nrf52833.
|
||||
CIRCUITPY_AESIO ?= 1
|
||||
CIRCUITPY_MEMORYMAP ?= 1
|
||||
|
||||
CIRCUITPY_RGBMATRIX ?= 1
|
||||
CIRCUITPY_FRAMEBUFFERIO ?= 1
|
||||
|
Loading…
Reference in New Issue
Block a user