forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9199 from tannewt/renode
Add minimal Renode port
- Loading branch information
Showing
62 changed files
with
1,990 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
"mimxrt10xx", | ||
"nordic", | ||
"raspberrypi", | ||
"renode", | ||
"silabs", | ||
"stm", | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# This file is part of the MicroPython project, http://micropython.org/ | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries | ||
# | ||
# 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 ../../py/circuitpy_mkenv.mk | ||
|
||
CROSS_COMPILE = arm-none-eabi- | ||
|
||
INC += \ | ||
-I. \ | ||
-I../.. \ | ||
-I../lib/mp-readline \ | ||
-I../shared/timeutils \ | ||
-Iboards/$(BOARD) \ | ||
-Iboards/ \ | ||
-isystem ./../../lib/cmsis/inc \ | ||
-I$(BUILD) | ||
|
||
CFLAGS += -ggdb3 -Os | ||
|
||
DISABLE_WARNINGS = -Wno-cast-align | ||
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes | ||
|
||
CFLAGS += \ | ||
-march=armv6-m \ | ||
-mthumb \ | ||
-mabi=aapcs \ | ||
-mcpu=cortex-m0plus \ | ||
-msoft-float \ | ||
-mfloat-abi=soft \ | ||
--specs=nano.specs | ||
|
||
# Use toolchain libm if we're not using our own. | ||
ifndef INTERNAL_LIBM | ||
LIBS += -lm | ||
endif | ||
|
||
LIBS += -lc | ||
|
||
SRC_C += \ | ||
boards/$(BOARD)/board.c \ | ||
boards/$(BOARD)/pins.c \ | ||
background.c \ | ||
mphalport.c \ | ||
|
||
|
||
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ | ||
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ | ||
$(addprefix common-hal/, $(SRC_COMMON_HAL)) | ||
|
||
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ | ||
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ | ||
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) | ||
|
||
# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED, | ||
# because a few modules have files both in common-hal/ and shared-module/. | ||
# Doing a $(sort ...) removes duplicates as part of sorting. | ||
SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)) | ||
|
||
SRC_S = supervisor/$(CPU)_cpu.s | ||
|
||
OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o)) | ||
ifeq ($(INTERNAL_LIBM),1) | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) | ||
endif | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o)) | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o)) | ||
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) | ||
|
||
$(BUILD)/%.o: $(BUILD)/%.S | ||
$(STEPECHO) "CC $<" | ||
$(Q)$(CC) $(CFLAGS) -c -o $@ $< | ||
|
||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(SRC_CIRCUITPY_COMMON) | ||
|
||
all: $(BUILD)/firmware.elf $(BUILD)/circuitpy.img | ||
|
||
BOARD_LD := $(wildcard boards/$(BOARD)/link.ld) | ||
|
||
ifneq ($(BOARD_LD),) | ||
LINKER_SCRIPTS = -Wl,-T,$(BOARD_LD) | ||
endif | ||
|
||
LINKER_SCRIPTS += -Wl,-T,link.ld | ||
|
||
$(BUILD)/circuitpy.img: circuitpy/code.py | ||
$(STEPECHO) "Create $@" | ||
$(Q)dd if=/dev/zero of=$(BUILD)/circuitpy.img bs=1 count=0 seek=512K | ||
$(Q)mkfs.fat -n CIRCUITPY --offset=0 $(BUILD)/circuitpy.img | ||
$(Q)mcopy -i $(BUILD)/circuitpy.img circuitpy/* :: | ||
|
||
ifeq ($(VALID_BOARD),) | ||
$(BUILD)/firmware.elf: invalid-board | ||
else | ||
$(BUILD)/firmware.elf: $(OBJ) $(BOARD_LD) link.ld | ||
$(STEPECHO) "LINK $@" | ||
$(Q)echo $(OBJ) > $(BUILD)/firmware.objs | ||
$(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags | ||
$(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags $(LINKER_SCRIPTS) -Wl,--print-memory-usage -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc | ||
endif | ||
|
||
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf | ||
$(STEPECHO) "Create $@" | ||
$(Q)$(OBJCOPY) -O binary -R .dtcm_bss $^ $@ | ||
|
||
include $(TOP)/py/mkrules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Renode | ||
|
||
Renode is an emulator targeting microcontroller-class devices. This port is a | ||
minimal version of CircuitPython that runs under Renode. Renode is designed to | ||
mimic full microcontrollers but CP uses more peripherals than what Renode has | ||
implemented so far. This port allows us to run on a variety of CPUs without | ||
worrying about peripherals. | ||
|
||
## Running | ||
|
||
1. Get Renode: https://renode.io/#downloads | ||
2. `cd ports/renode` | ||
3. `make BOARD=renode_cortex_m0plus` | ||
4. In another tab: `tio /tmp/cp-uart` | ||
5. `renode` | ||
6. In renode: `include @renode.resc` | ||
7. <Any other setup> | ||
8. `start` | ||
9. `pause` | ||
10. `quit` | ||
|
||
Step 4 sets up `tio` to talk to CircuitPython via UART <-> PTY bridge. | ||
|
||
## Other stuff | ||
|
||
### Emulator logging | ||
Renode modules have debug logging that can be enabled with `logLevel` with an int | ||
between `-1` for `NOISY` and `3` for errors only. | ||
|
||
### GDB | ||
|
||
Renode can provide a GDB server. It is very useful for precisely controlling the | ||
emulator's execution. | ||
|
||
``` | ||
machine StartGdbServer 3333 true | ||
``` | ||
|
||
### Execution profiling | ||
|
||
In renode do `cpu EnableProfiler CollapsedStack $ORIGIN/profile.folded` before starting | ||
the emulation. You can view it using [Speedscope](https://www.speedscope.app/). CircuitPython calls | ||
a lot of functions and may overwhelm speedscope. You can enable this tracing over a specific | ||
section of CircuitPython execution to limit the capture size. | ||
|
||
[Related Renode Docs](https://renode.readthedocs.io/en/latest/advanced/execution-tracing.html) | ||
|
||
### Execution tracing | ||
If you want to see every instruction run you can do: `cpu CreateExecutionTracing "tracer_name" $ORIGIN/instruction_trace.txt Disassembly`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright (c) 2010-2022 Antmicro | ||
// Copyright (c) 2011-2015 Realtime Embedded | ||
// | ||
// This file is licensed under the MIT License. | ||
// Full license text is available in 'licenses/MIT.txt'. | ||
// | ||
// This is modified for CircuitPython to tick at 32kHz like a slow external | ||
// crystal would. | ||
using System; | ||
using Antmicro.Renode.Core; | ||
using Antmicro.Renode.Peripherals.Bus; | ||
using Antmicro.Renode.Time; | ||
using Antmicro.Renode.Logging; | ||
using System.Threading; | ||
|
||
namespace Antmicro.Renode.Peripherals.Timers | ||
{ | ||
public class Simple32kHz : IDoubleWordPeripheral, IKnownSize | ||
{ | ||
public long Size { get { return 0x4; } } | ||
|
||
public Simple32kHz(IMachine machine) | ||
{ | ||
machine.ClockSource.AddClockEntry(new ClockEntry(1, 32768, OnTick, this, String.Empty)); | ||
} | ||
|
||
public virtual uint ReadDoubleWord(long offset) | ||
{ | ||
return (uint)counter; | ||
} | ||
|
||
public virtual void WriteDoubleWord(long offset, uint value) | ||
{ | ||
this.LogUnhandledWrite(offset, value); | ||
} | ||
|
||
public virtual void Reset() | ||
{ | ||
Interlocked.Exchange(ref counter, 0); | ||
} | ||
|
||
private void OnTick() | ||
{ | ||
Interlocked.Increment(ref counter); | ||
} | ||
|
||
private int counter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* This file is part of the MicroPython project, http://micropython.org/ | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries | ||
* | ||
* 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 "supervisor/port.h" | ||
|
||
void port_start_background_tick(void) { | ||
} | ||
|
||
void port_finish_background_tick(void) { | ||
} | ||
|
||
void port_background_tick(void) { | ||
} | ||
|
||
void port_background_task(void) { | ||
} |
Oops, something went wrong.