Files
micropython/ports/alif/mcu/make-pins.py
Damien George ccc5935234 alif: Add initial port to Alif Ensemble MCUs.
This commit adds the beginning of a new alif port with support for Alif
Ensemble MCUs.  See https://alifsemi.com/

Supported features of this port added by this commit:
- UART REPL.
- TinyUSB support, for REPL and MSC.
- Octal SPI flash support, for filesystem.
- machine.Pin support.

General notes about the port:
- It uses make, similar to other bare-metal ports here.
- The toolchain is the standard arm-none-eabi- toolchain.
- Flashing a board can be done using either the built-in serial bootloader,
  or JLink (both supported here).
- There are two required submodules (one for drivers/SDK, one for security
  tools), both of which are open source and on GitHub.
- No special hardware or software is needed for development, just a board
  connected over USB.

OpenMV have generously sponsored the development of this port.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-04-09 00:22:32 +10:00

65 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python
import os
import re
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../tools"))
import boardgen
NUM_PORTS = 16
NUM_PINS_PER_PORT = 8
class AlifPin(boardgen.Pin):
# Emit the struct which contains the pin instance.
def definition(self):
port, pin = self.name()[1:].split("_")
base = "LPGPIO_BASE" if port == "15" else "GPIO{}_BASE".format(port)
return (
"{{ "
".base = {{ .type = &machine_pin_type }}, "
".gpio = (GPIO_Type *){base}, "
".port = PORT_{port}, "
".pin = PIN_{pin}, "
".name = MP_QSTR_P{port}_{pin} "
"}}".format(port=port, pin=pin, base=base)
)
# Alif cpu names must be "Pn_m".
@staticmethod
def validate_cpu_pin_name(cpu_pin_name):
boardgen.Pin.validate_cpu_pin_name(cpu_pin_name)
if not (m := re.match("P([0-9]){1,2}_([0-9])", cpu_pin_name)):
raise boardgen.PinGeneratorError(
"Invalid cpu pin name '{}', must be 'Pn_m'".format(cpu_pin_name)
)
port = int(m.group(1))
pin = int(m.group(2))
if not (0 <= port < NUM_PORTS and 0 <= pin < NUM_PINS_PER_PORT):
raise boardgen.PinGeneratorError("Unknown cpu pin '{}'".format(cpu_pin_name))
class AlifPinGenerator(boardgen.PinGenerator):
def __init__(self):
# Use custom pin type above.
super().__init__(pin_type=AlifPin)
# Pre-define the pins (i.e. don't require them to be listed in pins.csv).
for i in range(NUM_PORTS):
for j in range(NUM_PINS_PER_PORT):
self.add_cpu_pin("P{}_{}".format(i, j))
# Only use pre-defined cpu pins (do not let board.csv create them).
def find_pin_by_cpu_pin_name(self, cpu_pin_name, create=True):
return super().find_pin_by_cpu_pin_name(cpu_pin_name, create=False)
def cpu_table_size(self):
return "{} * {}".format(NUM_PORTS, NUM_PINS_PER_PORT)
if __name__ == "__main__":
AlifPinGenerator().main()