├── .gitmodules ├── M5531 ├── frozen.mpy ├── boards │ ├── NuMaker-M5531 │ │ ├── mpconfigboard.mk │ │ └── pins.csv │ └── m5531_prefix.c ├── qstrdefsport.h ├── frozentest.py ├── example │ ├── RTC.py │ ├── WDT.py │ ├── ADC.py │ ├── Thread.py │ ├── UART.py │ ├── I2C.py │ ├── RunHorseLed.py │ ├── PWM.py │ ├── DAC.py │ ├── GPIO.py │ ├── CAN.py │ ├── SPI.py │ └── Timer.py ├── mpconfigport.mk ├── hal │ ├── StorIF_SDCard.h │ ├── MSC_VCPDesc.h │ ├── buffer.h │ ├── nu_modutil.c │ ├── nu_miscutil.h │ ├── nu_modutil.h │ ├── M5531_RTC.h │ ├── M5531_DAC.h │ ├── pin_int.h │ ├── M5531_I2C.h │ ├── StorIF.h │ ├── M5531_UART.h │ ├── M5531_PWM.h │ ├── M5531_CANFD.h │ ├── M5531_RTC.c │ ├── M5531_USBD.h │ ├── M5531_SPI.h │ └── M5531_Timer.h ├── mods │ ├── classUART.h │ ├── classDAC.h │ ├── classRTC.h │ ├── classWDT.h │ ├── classCAN.h │ ├── classI2C.h │ ├── classPWM.h │ ├── classSPI.h │ ├── pybflash.h │ ├── classADC.h │ ├── pybsdcard.h │ ├── classTimer.h │ ├── pybirq.h │ ├── modtime.c │ ├── pybirq.c │ ├── modmachine.c │ ├── classPin.h │ └── pin_named_pins.c ├── misc │ ├── mperror.h │ └── mperror.c ├── bufhelper.h ├── mpthreadport.h ├── gccollect.h ├── mphalport.h ├── fatfs_port.c ├── bufhelper.c ├── gccollect.c └── PinAFGen.py ├── M55M1 ├── frozen.mpy ├── boards │ ├── NuMaker-M55M1 │ │ ├── mpconfigboard.mk │ │ └── pins.csv │ └── m55m1_prefix.c ├── qstrdefsport.h ├── frozentest.py ├── example │ ├── RTC.py │ ├── WDT.py │ ├── ADC.py │ ├── Thread.py │ ├── UART.py │ ├── I2C.py │ ├── RunHorseLed.py │ ├── PWM.py │ ├── DAC.py │ ├── GPIO.py │ ├── CAN.py │ ├── SPI.py │ └── Timer.py ├── mpconfigport.mk ├── hal │ ├── StorIF_SDCard.h │ ├── MSC_VCPDesc.h │ ├── buffer.h │ ├── nu_modutil.c │ ├── nu_miscutil.h │ ├── nu_modutil.h │ ├── M55M1_RTC.h │ ├── M55M1_DAC.h │ ├── pin_int.h │ ├── M55M1_I2C.h │ ├── StorIF.h │ ├── M55M1_UART.h │ ├── M55M1_PWM.h │ ├── M55M1_CANFD.h │ ├── M55M1_RTC.c │ ├── M55M1_USBD.h │ ├── M55M1_SPI.h │ └── M55M1_Timer.h ├── mods │ ├── classUART.h │ ├── classDAC.h │ ├── classRTC.h │ ├── classWDT.h │ ├── classCAN.h │ ├── classI2C.h │ ├── classPWM.h │ ├── classSPI.h │ ├── pybflash.h │ ├── classADC.h │ ├── pybsdcard.h │ ├── classTimer.h │ ├── pybirq.h │ ├── modtime.c │ ├── pybirq.c │ ├── modmachine.c │ ├── classPin.h │ └── pin_named_pins.c ├── misc │ ├── mperror.h │ └── mperror.c ├── bufhelper.h ├── mpthreadport.h ├── gccollect.h ├── mphalport.h ├── fatfs_port.c ├── bufhelper.c └── gccollect.c ├── Picture ├── pybflash.jpg ├── NuMicroDisk.jpg ├── upate_code.jpg ├── ExecuteResult.png ├── NuMaker-M55M1.png ├── TermianlSetup_1.jpg └── TerminalSetup_0.jpg ├── UM_NuMicroPy_EN.pdf ├── install.txt └── README.md /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /M5531/frozen.mpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/M5531/frozen.mpy -------------------------------------------------------------------------------- /M55M1/frozen.mpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/M55M1/frozen.mpy -------------------------------------------------------------------------------- /Picture/pybflash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/pybflash.jpg -------------------------------------------------------------------------------- /UM_NuMicroPy_EN.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/UM_NuMicroPy_EN.pdf -------------------------------------------------------------------------------- /Picture/NuMicroDisk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/NuMicroDisk.jpg -------------------------------------------------------------------------------- /Picture/upate_code.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/upate_code.jpg -------------------------------------------------------------------------------- /Picture/ExecuteResult.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/ExecuteResult.png -------------------------------------------------------------------------------- /Picture/NuMaker-M55M1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/NuMaker-M55M1.png -------------------------------------------------------------------------------- /Picture/TermianlSetup_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/TermianlSetup_1.jpg -------------------------------------------------------------------------------- /Picture/TerminalSetup_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenNuvoton/NuMicroPy/HEAD/Picture/TerminalSetup_0.jpg -------------------------------------------------------------------------------- /M5531/boards/NuMaker-M5531/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = M5531 2 | CMSIS_MCU = M5531 3 | SYS_CLOCK = 200000000 4 | AF_FILE = boards/m5531_af.csv 5 | LD_FILES = boards/m5531.ld 6 | -------------------------------------------------------------------------------- /M5531/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | // Entries for sys.path 3 | Q(/flash) 4 | Q(/flash/lib) 5 | Q(/sd) 6 | Q(/sd/lib) 7 | Q(/spiflash) 8 | Q(/spiflash/lib) 9 | -------------------------------------------------------------------------------- /M55M1/boards/NuMaker-M55M1/mpconfigboard.mk: -------------------------------------------------------------------------------- 1 | MCU_SERIES = M55M1 2 | CMSIS_MCU = M55M1 3 | SYS_CLOCK = 200000000 4 | AF_FILE = boards/m55m1_af.csv 5 | LD_FILES = boards/m55m1.ld 6 | -------------------------------------------------------------------------------- /M55M1/qstrdefsport.h: -------------------------------------------------------------------------------- 1 | // qstrs specific to this port 2 | // Entries for sys.path 3 | Q(/flash) 4 | Q(/flash/lib) 5 | Q(/sd) 6 | Q(/sd/lib) 7 | Q(/spiflash) 8 | Q(/spiflash/lib) 9 | -------------------------------------------------------------------------------- /M5531/frozentest.py: -------------------------------------------------------------------------------- 1 | print('uPy') 2 | print('a long string that is not interned') 3 | print('a string that has unicode αβγ chars') 4 | print(b'bytes 1234\x01') 5 | print(123456789) 6 | for i in range(4): 7 | print(i) 8 | 9 | -------------------------------------------------------------------------------- /M55M1/frozentest.py: -------------------------------------------------------------------------------- 1 | print('uPy') 2 | print('a long string that is not interned') 3 | print('a string that has unicode αβγ chars') 4 | print(b'bytes 1234\x01') 5 | print(123456789) 6 | for i in range(4): 7 | print(i) 8 | 9 | -------------------------------------------------------------------------------- /M5531/example/RTC.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | rtc = pyb.RTC() 3 | rtc.datetime((2025, 6, 13, 5, 14, 30, 0, 0)) 4 | print(rtc.datetime()) 5 | 6 | def rtc_cb(): 7 | print("wake up") 8 | 9 | rtc.wakeup(rtc.WAKEUP_1_SEC, rtc_cb) 10 | -------------------------------------------------------------------------------- /M55M1/example/RTC.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | rtc = pyb.RTC() 3 | rtc.datetime((2025, 6, 13, 5, 14, 30, 0, 0)) 4 | print(rtc.datetime()) 5 | 6 | def rtc_cb(): 7 | print("wake up") 8 | 9 | rtc.wakeup(rtc.WAKEUP_1_SEC, rtc_cb) 10 | -------------------------------------------------------------------------------- /M5531/example/WDT.py: -------------------------------------------------------------------------------- 1 | import utime 2 | from pyb import WDT 3 | import time 4 | 5 | wdt = WDT(timeout = 1000) 6 | 7 | while utime.ticks_ms() < 10000: 8 | time.sleep_ms(500) 9 | wdt.feed() 10 | 11 | print('Ready to reset') 12 | -------------------------------------------------------------------------------- /M55M1/example/WDT.py: -------------------------------------------------------------------------------- 1 | import utime 2 | from pyb import WDT 3 | import time 4 | 5 | wdt = WDT(timeout = 1000) 6 | 7 | while utime.ticks_ms() < 10000: 8 | time.sleep_ms(500) 9 | wdt.feed() 10 | 11 | print('Ready to reset') 12 | -------------------------------------------------------------------------------- /M5531/example/ADC.py: -------------------------------------------------------------------------------- 1 | from pyb import ADC, Pin, ADCALL 2 | 3 | adc0 = ADC(Pin.board.A4) 4 | val = adc0.read() 5 | print(val) 6 | 7 | #0x6000000: enable channal 25 (core tempture) and channel 26 (battery voltage) 8 | adc_all = ADCALL(12, 0x6000000) 9 | adc_all.read_core_temp() 10 | adc_all.read_core_vbat() 11 | -------------------------------------------------------------------------------- /M55M1/example/ADC.py: -------------------------------------------------------------------------------- 1 | from pyb import ADC, Pin, ADCALL 2 | 3 | adc0 = ADC(Pin.board.A4) 4 | val = adc0.read() 5 | print(val) 6 | 7 | #0x6000000: enable channal 25 (core tempture) and channel 26 (battery voltage) 8 | adc_all = ADCALL(12, 0x6000000) 9 | adc_all.read_core_temp() 10 | adc_all.read_core_vbat() 11 | -------------------------------------------------------------------------------- /M5531/example/Thread.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | import pyb 3 | import time 4 | 5 | def testThread(): 6 | while True: 7 | print("Hello from thread---1") 8 | time.sleep_ms(1000) 9 | 10 | def testThread2(): 11 | while True: 12 | print("Hello from thread---2") 13 | time.sleep_ms(1000) 14 | 15 | _thread.start_new_thread(testThread, ()) 16 | _thread.start_new_thread(testThread2, ()) 17 | -------------------------------------------------------------------------------- /M55M1/example/Thread.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | import pyb 3 | import time 4 | 5 | def testThread(): 6 | while True: 7 | print("Hello from thread---1") 8 | time.sleep_ms(1000) 9 | 10 | def testThread2(): 11 | while True: 12 | print("Hello from thread---2") 13 | time.sleep_ms(1000) 14 | 15 | _thread.start_new_thread(testThread, ()) 16 | _thread.start_new_thread(testThread2, ()) 17 | -------------------------------------------------------------------------------- /M5531/mpconfigport.mk: -------------------------------------------------------------------------------- 1 | # Enable/disable modules and 3rd-party libs to be included in interpreter 2 | 3 | # _thread module using pthreads 4 | MICROPY_PY_THREAD = 1 5 | 6 | #LittlevGL binding 7 | MICROPY_LVGL = 0 8 | 9 | ifeq ($(MICROPY_PY_THREAD),1) 10 | # socket module using lwip. depend on MICROPY_PY_THREAD 11 | # MICROPY_NVT_LWIP = 1 12 | endif 13 | 14 | #MICROPY_SSL_NVT_MBEDTLS = 1 15 | #MICROPY_SSL_NVT_AXTLS = 1 16 | 17 | -------------------------------------------------------------------------------- /M55M1/mpconfigport.mk: -------------------------------------------------------------------------------- 1 | # Enable/disable modules and 3rd-party libs to be included in interpreter 2 | 3 | # _thread module using pthreads 4 | MICROPY_PY_THREAD = 1 5 | 6 | #LittlevGL binding 7 | MICROPY_LVGL = 0 8 | 9 | ifeq ($(MICROPY_PY_THREAD),1) 10 | # socket module using lwip. depend on MICROPY_PY_THREAD 11 | # MICROPY_NVT_LWIP = 1 12 | endif 13 | 14 | #MICROPY_SSL_NVT_MBEDTLS = 1 15 | #MICROPY_SSL_NVT_AXTLS = 1 16 | 17 | -------------------------------------------------------------------------------- /M5531/example/UART.py: -------------------------------------------------------------------------------- 1 | from pyb import UART 2 | 3 | uart = UART(6, 115200, bits = 8, parity = None, stop = 1) 4 | 5 | uart.writechar(0x55) 6 | uart.writechar(0xaa) 7 | uart.writechar(0x55) 8 | uart.writechar(0xaa) 9 | 10 | uart.write('\r\n') 11 | uart.write('>>') 12 | 13 | read_char = 0 14 | 15 | while (read_char != 113): #exit if received 'q' 16 | if(uart.any() != 0): 17 | read_char = uart.readchar() 18 | print(read_char) 19 | uart.writechar(read_char) 20 | -------------------------------------------------------------------------------- /M55M1/example/UART.py: -------------------------------------------------------------------------------- 1 | from pyb import UART 2 | 3 | uart = UART(6, 115200, bits = 8, parity = None, stop = 1) 4 | 5 | uart.writechar(0x55) 6 | uart.writechar(0xaa) 7 | uart.writechar(0x55) 8 | uart.writechar(0xaa) 9 | 10 | uart.write('\r\n') 11 | uart.write('>>') 12 | 13 | read_char = 0 14 | 15 | while (read_char != 113): #exit if received 'q' 16 | if(uart.any() != 0): 17 | read_char = uart.readchar() 18 | print(read_char) 19 | uart.writechar(read_char) 20 | -------------------------------------------------------------------------------- /M5531/example/I2C.py: -------------------------------------------------------------------------------- 1 | #master mode 2 | from pyb import I2C 3 | i2c3 = I2C(3, I2C.MASTER) 4 | slave_addr = i2c3.scan() 5 | print(slave_addr) 6 | i2c3.send('123', slave_addr[0]) 7 | data = bytearray(3) 8 | i2c3.recv(data, slave_addr[0]) 9 | print(data) 10 | 11 | #slave mode 12 | from pyb import I2C 13 | i2c3 = I2C(3, I2C.SLAVE, addr=0x15) 14 | recv_data = bytearray(3) 15 | send_data = bytearray(1) 16 | i2c3.recv(recv_data) 17 | print(recv_data) 18 | send_data[0] = recv_data[2] 19 | i2c3.send(send_data) 20 | -------------------------------------------------------------------------------- /M55M1/example/I2C.py: -------------------------------------------------------------------------------- 1 | #master mode 2 | from pyb import I2C 3 | i2c3 = I2C(3, I2C.MASTER) 4 | slave_addr = i2c3.scan() 5 | print(slave_addr) 6 | i2c3.send('123', slave_addr[0]) 7 | data = bytearray(3) 8 | i2c3.recv(data, slave_addr[0]) 9 | print(data) 10 | 11 | #slave mode 12 | from pyb import I2C 13 | i2c3 = I2C(3, I2C.SLAVE, addr=0x15) 14 | recv_data = bytearray(3) 15 | send_data = bytearray(1) 16 | i2c3.recv(recv_data) 17 | print(recv_data) 18 | send_data[0] = recv_data[2] 19 | i2c3.send(send_data) 20 | -------------------------------------------------------------------------------- /M5531/example/RunHorseLed.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | import time 3 | 4 | r = pyb.Pin('LEDR', pyb.Pin.OUT) 5 | g = pyb.Pin('LEDG', pyb.Pin.OUT) 6 | y = pyb.Pin('LEDY', pyb.Pin.OUT) 7 | 8 | while True: 9 | time.sleep_ms(1000) 10 | pin_value = r.value() 11 | if pin_value == 0: 12 | r.value(1) 13 | else: 14 | r.value(0) 15 | time.sleep_ms(1000) 16 | pin_value = y.value() 17 | if pin_value == 0: 18 | y.value(1) 19 | else: 20 | y.value(0) 21 | time.sleep_ms(1000) 22 | pin_value = g.value() 23 | if pin_value == 0: 24 | g.value(1) 25 | else: 26 | g.value(0) 27 | -------------------------------------------------------------------------------- /M55M1/example/RunHorseLed.py: -------------------------------------------------------------------------------- 1 | import pyb 2 | import time 3 | 4 | r = pyb.Pin('LEDR', pyb.Pin.OUT) 5 | g = pyb.Pin('LEDG', pyb.Pin.OUT) 6 | y = pyb.Pin('LEDY', pyb.Pin.OUT) 7 | 8 | while True: 9 | time.sleep_ms(1000) 10 | pin_value = r.value() 11 | if pin_value == 0: 12 | r.value(1) 13 | else: 14 | r.value(0) 15 | time.sleep_ms(1000) 16 | pin_value = y.value() 17 | if pin_value == 0: 18 | y.value(1) 19 | else: 20 | y.value(0) 21 | time.sleep_ms(1000) 22 | pin_value = g.value() 23 | if pin_value == 0: 24 | g.value(1) 25 | else: 26 | g.value(0) 27 | -------------------------------------------------------------------------------- /M5531/boards/NuMaker-M5531/pins.csv: -------------------------------------------------------------------------------- 1 | D0,PB2 2 | D1,PB3 3 | D2,PC9 4 | D3,PC10 5 | D4,PC11 6 | D5,PC12 7 | D6,PB4 8 | D7,PB5 9 | D8,PI13 10 | D9,PI12 11 | D10,PA3 12 | D11,PA0 13 | D12,PA1 14 | D13,PA2 15 | SCL,PG0 16 | SDA,PG1 17 | A0,PB6 18 | A1,PB7 19 | A2,PB8 20 | A3,PB9 21 | A4,PB0 22 | A5,PB1 23 | SS,PA11 24 | CLK,PA10 25 | MISO,PA9 26 | MOSI,PA8 27 | 28 | 29 | CCAP_SCL,PH2 30 | CCAP_SDA,PH3 31 | 32 | BTN0,PI11 33 | BTN1,PH1 34 | 35 | LEDR,PH4 36 | LEDY,PD6 37 | LEDG,PD5 38 | 39 | CANFD_RX,PJ11 40 | CANFD_TX,PJ10 41 | 42 | DAC0_OUT,PB12 43 | DAC1_OUT,PB13 44 | 45 | -------------------------------------------------------------------------------- /M55M1/boards/NuMaker-M55M1/pins.csv: -------------------------------------------------------------------------------- 1 | D0,PB2 2 | D1,PB3 3 | D2,PC9 4 | D3,PC10 5 | D4,PC11 6 | D5,PC12 7 | D6,PB4 8 | D7,PB5 9 | D8,PI13 10 | D9,PI12 11 | D10,PA3 12 | D11,PA0 13 | D12,PA1 14 | D13,PA2 15 | SCL,PG0 16 | SDA,PG1 17 | A0,PB6 18 | A1,PB7 19 | A2,PB8 20 | A3,PB9 21 | A4,PB0 22 | A5,PB1 23 | SS,PA11 24 | CLK,PA10 25 | MISO,PA9 26 | MOSI,PA8 27 | 28 | 29 | CCAP_SCL,PH2 30 | CCAP_SDA,PH3 31 | 32 | BTN0,PI11 33 | BTN1,PH1 34 | 35 | LEDR,PH4 36 | LEDY,PD6 37 | LEDG,PD5 38 | 39 | CANFD_RX,PJ11 40 | CANFD_TX,PJ10 41 | 42 | DAC0_OUT,PB12 43 | DAC1_OUT,PB13 44 | 45 | -------------------------------------------------------------------------------- /M5531/hal/StorIF_SDCard.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file StorIF_SDCard.h 3 | * @version V1.00 4 | * @brief M5531 SD card storage interface header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __STORIF_SDCARD_H__ 10 | #define __STORIF_SDCARD_H__ 11 | 12 | extern void SDH_IntHandler(SDH_T *psSDH, SDH_INFO_T *psSDInfo); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /M55M1/hal/StorIF_SDCard.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file StorIF_SDCard.h 3 | * @version V1.00 4 | * @brief M55M1 SD card storage interface header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __STORIF_SDCARD_H__ 10 | #define __STORIF_SDCARD_H__ 11 | 12 | extern void SDH_IntHandler(SDH_T *psSDH, SDH_INFO_T *psSDInfo); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /M5531/example/PWM.py: -------------------------------------------------------------------------------- 1 | from pyb import PWM 2 | from pyb import Pin 3 | 4 | def capture_cb(chan, reason): 5 | if reason == PWM.RISING: 6 | print("rising", chan.capture(PWM.RISING)) 7 | elif reason == PWM.FALLING: 8 | print('falling', chan.capture(PWM.FALLING)) 9 | else: 10 | print('both edge') 11 | 12 | bpwm1 = PWM(1, freq = 2) 13 | epwm1 = PWM(1, PWM.EPWM, freq = 1000000) 14 | 15 | bpwm1ch4 = bpwm1.channel(mode = PWM.OUTPUT, pulse_width_percent = 25, pin = Pin.board.A1) 16 | epwm1ch0 = epwm1.channel(mode = PWM.CAPTURE, capture_edge = PWM.RISING_FALLING, pin = Pin.board.D9, callback = capture_cb) 17 | -------------------------------------------------------------------------------- /M55M1/example/PWM.py: -------------------------------------------------------------------------------- 1 | from pyb import PWM 2 | from pyb import Pin 3 | 4 | def capture_cb(chan, reason): 5 | if reason == PWM.RISING: 6 | print("rising", chan.capture(PWM.RISING)) 7 | elif reason == PWM.FALLING: 8 | print('falling', chan.capture(PWM.FALLING)) 9 | else: 10 | print('both edge') 11 | 12 | bpwm1 = PWM(1, freq = 2) 13 | epwm1 = PWM(1, PWM.EPWM, freq = 1000000) 14 | 15 | bpwm1ch4 = bpwm1.channel(mode = PWM.OUTPUT, pulse_width_percent = 25, pin = Pin.board.A1) 16 | epwm1ch0 = epwm1.channel(mode = PWM.CAPTURE, capture_edge = PWM.RISING_FALLING, pin = Pin.board.D9, callback = capture_cb) 17 | -------------------------------------------------------------------------------- /M5531/example/DAC.py: -------------------------------------------------------------------------------- 1 | import math 2 | from array import array 3 | from pyb import DAC 4 | import time 5 | 6 | 7 | dac = DAC(0, bits = 8) 8 | dac.write(0) 9 | dac.write(64) 10 | dac.write(128) 11 | dac.write(172) 12 | dac.write(255) 13 | dac.deinit() 14 | 15 | # create a buffer containing a sine-wave, using half-word samples 16 | buf = array('H', 2048 + int(2047 * math.sin(2 * math.pi * i / 128)) for i in range(128)) 17 | 18 | #reinit dac to 8bit mode 19 | dac = DAC(0, bits = 12) 20 | 21 | # output the sine-wave at 400Hz 22 | dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR) 23 | time.sleep_ms(5000) 24 | dac.deinit() 25 | 26 | -------------------------------------------------------------------------------- /M55M1/example/DAC.py: -------------------------------------------------------------------------------- 1 | import math 2 | from array import array 3 | from pyb import DAC 4 | import time 5 | 6 | 7 | dac = DAC(0, bits = 8) 8 | dac.write(0) 9 | dac.write(64) 10 | dac.write(128) 11 | dac.write(172) 12 | dac.write(255) 13 | dac.deinit() 14 | 15 | # create a buffer containing a sine-wave, using half-word samples 16 | buf = array('H', 2048 + int(2047 * math.sin(2 * math.pi * i / 128)) for i in range(128)) 17 | 18 | #reinit dac to 8bit mode 19 | dac = DAC(0, bits = 12) 20 | 21 | # output the sine-wave at 400Hz 22 | dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR) 23 | time.sleep_ms(5000) 24 | dac.deinit() 25 | 26 | -------------------------------------------------------------------------------- /M5531/example/GPIO.py: -------------------------------------------------------------------------------- 1 | import time 2 | from pyb import Pin 3 | 4 | def btn1_callback(pin): 5 | print(pin) 6 | 7 | btn1 = Pin.board.BTN1 8 | btn1_af = btn1.af_list() 9 | 10 | #btn1 already in input mode 11 | print(btn1) 12 | print(btn1.af_list()) 13 | 14 | #set pin to alterate function 15 | #d1 = Pin(Pin.board.D1, Pin.ALT, alt = 0) 16 | #d1 = Pin(Pin.board.D1, Pin.ALT, alt = Pin.AF_PB3_EADC0_CH3) 17 | 18 | btn1.irq(handler=btn1_callback, trigger=Pin.IRQ_FALLING) 19 | 20 | #change ledr to output mode 21 | r = Pin('LEDR', Pin.OUT) 22 | #r = Pin('LEDR', Pin.OUT, pull = None, value = 0) #Defalut output low 23 | 24 | print(r) 25 | print(r.af_list()) 26 | 27 | while True: 28 | pin_value = btn1.value() 29 | if pin_value == 0: 30 | print('Button press') 31 | time.sleep_ms(1000) 32 | 33 | print('demo done') 34 | -------------------------------------------------------------------------------- /M55M1/example/GPIO.py: -------------------------------------------------------------------------------- 1 | import time 2 | from pyb import Pin 3 | 4 | def btn1_callback(pin): 5 | print(pin) 6 | 7 | btn1 = Pin.board.BTN1 8 | btn1_af = btn1.af_list() 9 | 10 | #btn1 already in input mode 11 | print(btn1) 12 | print(btn1.af_list()) 13 | 14 | #set pin to alterate function 15 | #d1 = Pin(Pin.board.D1, Pin.ALT, alt = 0) 16 | #d1 = Pin(Pin.board.D1, Pin.ALT, alt = Pin.AF_PB3_EADC0_CH3) 17 | 18 | btn1.irq(handler=btn1_callback, trigger=Pin.IRQ_FALLING) 19 | 20 | #change ledr to output mode 21 | r = Pin('LEDR', Pin.OUT) 22 | #r = Pin('LEDR', Pin.OUT, pull = None, value = 0) #Defalut output low 23 | 24 | print(r) 25 | print(r.af_list()) 26 | 27 | while True: 28 | pin_value = btn1.value() 29 | if pin_value == 0: 30 | print('Button press') 31 | time.sleep_ms(1000) 32 | 33 | print('demo done') 34 | -------------------------------------------------------------------------------- /M5531/hal/MSC_VCPDesc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file MSC_VCPDesc.h 3 | * @brief M5531 series USB class descriptions code for mass storage and VCP 4 | * @version 0.0.1 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | ******************************************************************************/ 9 | #ifndef __MSC_VCPDESC_H__ 10 | #define __MSC_VCPDESC_H__ 11 | 12 | #include "M5531_USBD.h" 13 | 14 | void MSCVCPDesc_SetupDescInfo( 15 | S_USBD_INFO_T *psDescInfo 16 | ); 17 | 18 | void MSCVCPDesc_SetVID( 19 | S_USBD_INFO_T *psDescInfo, 20 | uint16_t u16VID 21 | ); 22 | 23 | void MSCVCPDesc_SetPID( 24 | S_USBD_INFO_T *psDescInfo, 25 | uint16_t u16PID 26 | ); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /M55M1/hal/MSC_VCPDesc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file MSC_VCPDesc.h 3 | * @brief M480 series USB class descriptions code for mass storage and VCP 4 | * @version 0.0.1 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | ******************************************************************************/ 9 | #ifndef __MSC_VCPDESC_H__ 10 | #define __MSC_VCPDESC_H__ 11 | 12 | #include "M55M1_USBD.h" 13 | 14 | void MSCVCPDesc_SetupDescInfo( 15 | S_USBD_INFO_T *psDescInfo 16 | ); 17 | 18 | void MSCVCPDesc_SetVID( 19 | S_USBD_INFO_T *psDescInfo, 20 | uint16_t u16VID 21 | ); 22 | 23 | void MSCVCPDesc_SetPID( 24 | S_USBD_INFO_T *psDescInfo, 25 | uint16_t u16PID 26 | ); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /M5531/hal/buffer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file buffer.h 3 | * @version V0.10 4 | * @brief dma buffer function 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #ifndef NU_BUFFER_H 11 | #define NU_BUFFER_H 12 | 13 | #include 14 | 15 | /** Generic buffer structure 16 | */ 17 | typedef struct buffer_s { 18 | void *buffer; /**< the pointer to a buffer */ 19 | size_t length; /**< the buffer length */ 20 | size_t pos; /**< actual buffer position */ 21 | uint8_t width; /**< The buffer unit width (8, 16, 32, 64), used for proper *buffer casting */ 22 | } buffer_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /M55M1/hal/buffer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file buffer.h 3 | * @version V0.10 4 | * @brief dma buffer function 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #ifndef NU_BUFFER_H 11 | #define NU_BUFFER_H 12 | 13 | #include 14 | 15 | /** Generic buffer structure 16 | */ 17 | typedef struct buffer_s { 18 | void *buffer; /**< the pointer to a buffer */ 19 | size_t length; /**< the buffer length */ 20 | size_t pos; /**< actual buffer position */ 21 | uint8_t width; /**< The buffer unit width (8, 16, 32, 64), used for proper *buffer casting */ 22 | } buffer_t; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /M5531/hal/nu_modutil.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_modutil.c 3 | * @version V0.01 4 | * @brief module utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #include "nu_modutil.h" 11 | 12 | const struct nu_modinit_s *get_modinit(uint32_t modname, const struct nu_modinit_s *modprop_tab) 13 | { 14 | if(modprop_tab == NULL) 15 | return NULL; 16 | 17 | const struct nu_modinit_s *modprop_ind = modprop_tab; 18 | while (modprop_ind->modname != 0) { 19 | if ((int) modname == modprop_ind->modname) { 20 | return modprop_ind; 21 | } else { 22 | modprop_ind ++; 23 | } 24 | } 25 | 26 | return NULL; 27 | } 28 | -------------------------------------------------------------------------------- /M55M1/hal/nu_modutil.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_modutil.c 3 | * @version V0.01 4 | * @brief module utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #include "nu_modutil.h" 11 | 12 | const struct nu_modinit_s *get_modinit(uint32_t modname, const struct nu_modinit_s *modprop_tab) 13 | { 14 | if(modprop_tab == NULL) 15 | return NULL; 16 | 17 | const struct nu_modinit_s *modprop_ind = modprop_tab; 18 | while (modprop_ind->modname != 0) { 19 | if ((int) modname == modprop_ind->modname) { 20 | return modprop_ind; 21 | } else { 22 | modprop_ind ++; 23 | } 24 | } 25 | 26 | return NULL; 27 | } 28 | -------------------------------------------------------------------------------- /M5531/hal/nu_miscutil.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_miscutil.h 3 | * @version V0.01 4 | * @brief misc utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #ifndef NU_MISC_UTIL_H 11 | #define NU_MISC_UTIL_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define NU_MAX(a,b) ((a)>(b)?(a):(b)) 18 | #define NU_MIN(a,b) ((a)<(b)?(a):(b)) 19 | #define NU_CLAMP(x, min, max) NU_MIN(NU_MAX((x), (min)), (max)) 20 | #define NU_ALIGN_DOWN(X, ALIGN) ((X) & ~((ALIGN) - 1)) 21 | #define NU_ALIGN_UP(X, ALIGN) (((X) + (ALIGN) - 1) & ~((ALIGN) - 1)) 22 | 23 | void nu_nop(uint32_t n); 24 | 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /M55M1/hal/nu_miscutil.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_miscutil.h 3 | * @version V0.01 4 | * @brief misc utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #ifndef NU_MISC_UTIL_H 11 | #define NU_MISC_UTIL_H 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define NU_MAX(a,b) ((a)>(b)?(a):(b)) 18 | #define NU_MIN(a,b) ((a)<(b)?(a):(b)) 19 | #define NU_CLAMP(x, min, max) NU_MIN(NU_MAX((x), (min)), (max)) 20 | #define NU_ALIGN_DOWN(X, ALIGN) ((X) & ~((ALIGN) - 1)) 21 | #define NU_ALIGN_UP(X, ALIGN) (((X) + (ALIGN) - 1) & ~((ALIGN) - 1)) 22 | 23 | void nu_nop(uint32_t n); 24 | 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /M5531/hal/nu_modutil.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_modutil.h 3 | * @version V0.01 4 | * @brief module utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef NU_MODULE_UTIL_H 10 | #define NU_MODULE_UTIL_H 11 | 12 | #include "NuMicro.h" 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct nu_modinit_s { 18 | int modname; 19 | uint64_t clkidx; 20 | uint32_t clksrc; 21 | uint32_t clkdiv; 22 | uint32_t rsetidx; 23 | 24 | IRQn_Type irq_n; 25 | //int irq_n; 26 | 27 | void *var; 28 | }; 29 | 30 | const struct nu_modinit_s *get_modinit(uint32_t modname, const struct nu_modinit_s *modprop_tab); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /M55M1/hal/nu_modutil.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file nu_modutil.h 3 | * @version V0.01 4 | * @brief module utility 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef NU_MODULE_UTIL_H 10 | #define NU_MODULE_UTIL_H 11 | 12 | #include "NuMicro.h" 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct nu_modinit_s { 18 | int modname; 19 | uint64_t clkidx; 20 | uint32_t clksrc; 21 | uint32_t clkdiv; 22 | uint32_t rsetidx; 23 | 24 | IRQn_Type irq_n; 25 | //int irq_n; 26 | 27 | void *var; 28 | }; 29 | 30 | const struct nu_modinit_s *get_modinit(uint32_t modname, const struct nu_modinit_s *modprop_tab); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /M5531/example/CAN.py: -------------------------------------------------------------------------------- 1 | from pyb import CAN 2 | from pyb import Pin 3 | import time 4 | 5 | can0 = CAN(0, mode = CAN.NORMAL, extframe=True, baudrate = 1000000) 6 | 7 | #Master, Send Data 8 | can0.send(data = 'mess 01!', id = 0x3333) 9 | 10 | #Slave, Receive Data 11 | btn1 = Pin.board.BTN1 12 | 13 | buf = bytearray(8) 14 | data_lst = [0, 0, 0, memoryview(buf)] 15 | 16 | def can0_cb(bus, reason, fifo_num): 17 | if reason == CAN.CB_REASON_RX: 18 | bus.recv(list = data_lst) 19 | print(data_lst) 20 | print(buf) 21 | if reason == CAN.CB_REASON_ERROR_WARNING: 22 | print('Error Warning') 23 | if reason == CAN.CB_REASON_ERROR_PASSIVE: 24 | print('Error Passive') 25 | if reason == CAN.CB_REASON_ERROR_BUS_OFF: 26 | print('Bus off') 27 | 28 | can0.setfilter(id = 0x333, mask = 0x7FF) 29 | can0.rxcallback(can0_cb) 30 | 31 | while True: 32 | pin_value = btn1.value() 33 | time.sleep_ms(1000) 34 | if pin_value == 0: 35 | print('break main.py') 36 | break 37 | -------------------------------------------------------------------------------- /M55M1/example/CAN.py: -------------------------------------------------------------------------------- 1 | from pyb import CAN 2 | from pyb import Pin 3 | import time 4 | 5 | can0 = CAN(0, mode = CAN.NORMAL, extframe=True, baudrate = 1000000) 6 | 7 | #Master, Send Data 8 | can0.send(data = 'mess 01!', id = 0x3333) 9 | 10 | #Slave, Receive Data 11 | btn1 = Pin.board.BTN1 12 | 13 | buf = bytearray(8) 14 | data_lst = [0, 0, 0, memoryview(buf)] 15 | 16 | def can0_cb(bus, reason, fifo_num): 17 | if reason == CAN.CB_REASON_RX: 18 | bus.recv(list = data_lst) 19 | print(data_lst) 20 | print(buf) 21 | if reason == CAN.CB_REASON_ERROR_WARNING: 22 | print('Error Warning') 23 | if reason == CAN.CB_REASON_ERROR_PASSIVE: 24 | print('Error Passive') 25 | if reason == CAN.CB_REASON_ERROR_BUS_OFF: 26 | print('Bus off') 27 | 28 | can0.setfilter(id = 0x333, mask = 0x7FF) 29 | can0.rxcallback(can0_cb) 30 | 31 | while True: 32 | pin_value = btn1.value() 33 | time.sleep_ms(1000) 34 | if pin_value == 0: 35 | print('break main.py') 36 | break 37 | -------------------------------------------------------------------------------- /M5531/example/SPI.py: -------------------------------------------------------------------------------- 1 | import array 2 | import time 3 | from pyb import Pin 4 | from pyb import SPI 5 | 6 | send_buf = array.array('i', [0xAA0000, 0xAA0001, 0xAA0002, 0xAA0003, 0xAA0004, 0xAA0005, 0xAA0006, 0xAA0007, 0xAA0008, 0xAA0009, 0xAA000A, 0xAA000B, 0xAA000C, 0xAA000D, 0xAA000E, 0xAA000F]) 7 | recv_buf = array.array('i', [0x000000, 0x000001, 0x000002, 0x000003, 0x000004, 0x000005, 0x000006, 0x000007, 0x000008, 0x000009, 0x00000A, 0x00000B, 0x00000C, 0x00000D, 0x00000E, 0xAA000F]) 8 | print(send_buf) 9 | 10 | #Master code. When SPI slave device ready, press BTN1 to start SPI transfer 11 | btn1 = Pin.board.BTN1 12 | spi0=SPI(0, SPI.MASTER, baudrate=200000, bits=32) 13 | 14 | while True: 15 | pin_value = btn1.value() 16 | if pin_value == 0: 17 | print('Start SPI transfer') 18 | spi0.write_readinto(send_buf, recv_buf) 19 | print(recv_buf) 20 | time.sleep_ms(1000) 21 | 22 | #Slave 23 | #spi0=SPI(0, SPI.SLAVE, bits=32) 24 | #spi0.write_readinto(send_buf, recv_buf) 25 | #print(recv_buf) 26 | -------------------------------------------------------------------------------- /M55M1/example/SPI.py: -------------------------------------------------------------------------------- 1 | import array 2 | import time 3 | from pyb import Pin 4 | from pyb import SPI 5 | 6 | send_buf = array.array('i', [0xAA0000, 0xAA0001, 0xAA0002, 0xAA0003, 0xAA0004, 0xAA0005, 0xAA0006, 0xAA0007, 0xAA0008, 0xAA0009, 0xAA000A, 0xAA000B, 0xAA000C, 0xAA000D, 0xAA000E, 0xAA000F]) 7 | recv_buf = array.array('i', [0x000000, 0x000001, 0x000002, 0x000003, 0x000004, 0x000005, 0x000006, 0x000007, 0x000008, 0x000009, 0x00000A, 0x00000B, 0x00000C, 0x00000D, 0x00000E, 0xAA000F]) 8 | print(send_buf) 9 | 10 | #Master code. When SPI slave device ready, press BTN1 to start SPI transfer 11 | btn1 = Pin.board.BTN1 12 | spi0=SPI(0, SPI.MASTER, baudrate=200000, bits=32) 13 | 14 | while True: 15 | pin_value = btn1.value() 16 | if pin_value == 0: 17 | print('Start SPI transfer') 18 | spi0.write_readinto(send_buf, recv_buf) 19 | print(recv_buf) 20 | time.sleep_ms(1000) 21 | 22 | #Slave 23 | #spi0=SPI(0, SPI.SLAVE, bits=32) 24 | #spi0.write_readinto(send_buf, recv_buf) 25 | #print(recv_buf) 26 | -------------------------------------------------------------------------------- /install.txt: -------------------------------------------------------------------------------- 1 | 1. Packages Requirement 2 | The following packages will need to be installed before you can compile and run MicroPython 3 | 4 | git 5 | python3-pip 6 | To install these packages using the following command. 7 | 8 | #sudo apt-get install build-essential libreadline-dev libffi-dev git pkg-config python3-pip 9 | #pip3 install gitpython 10 | #pip3 install rich 11 | 12 | 2. Install GNU Arm Toolchain 13 | Download GNU Arm toolchain linux 64-bit version(arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi.tar.xz)from Arm Developer. Next use the tar command to extract the file to your favor directory (ex. /usr/local) 14 | 15 | #mv arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi.tar.xz /usr/local/ 16 | #cd /usr/local 17 | #tar -xvf arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi.tar.xz 18 | 19 | Now, modify your PATH environment variable to access the bin directory of toolchain. Edit ~/.profile 20 | PATH="/usr/local/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin:$PATH" 21 | 22 | 3. Download micropython and BSP source 23 | #python3 download_src.py --board NuMaker-M55M1 24 | -------------------------------------------------------------------------------- /M5531/hal/M5531_RTC.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_RTC.h 3 | * @version V1.00 4 | * @brief M5531 RTC HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_RTC_H__ 10 | #define __M5531_RTC_H__ 11 | 12 | typedef void (*PFN_RTC_INT_HANDLER)(void *obj); 13 | 14 | typedef struct { 15 | RTC_T *rtc; 16 | PFN_RTC_INT_HANDLER pfnRTCIntHandler; 17 | } rtc_t; 18 | 19 | typedef struct { 20 | S_RTC_TIME_DATA_T *psRTCTimeDate; 21 | } RTC_InitTypeDef; 22 | 23 | int32_t RTC_Init( 24 | rtc_t *psObj, 25 | RTC_InitTypeDef *psInitDef 26 | ); 27 | 28 | int32_t RTC_EnableIntFlag( 29 | rtc_t *psObj, 30 | uint32_t u32IntFlagMask, 31 | PFN_RTC_INT_HANDLER pfnHandler 32 | ); 33 | 34 | int32_t RTC_DisableIntFlag( 35 | rtc_t *psObj, 36 | uint32_t u32IntFlagMask 37 | ); 38 | 39 | void Handle_RTC_Irq(RTC_T *rtc); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_RTC.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_RTC.h 3 | * @version V1.00 4 | * @brief M55M1 RTC HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_RTC_H__ 10 | #define __M55M1_RTC_H__ 11 | 12 | typedef void (*PFN_RTC_INT_HANDLER)(void *obj); 13 | 14 | typedef struct { 15 | RTC_T *rtc; 16 | PFN_RTC_INT_HANDLER pfnRTCIntHandler; 17 | } rtc_t; 18 | 19 | typedef struct { 20 | S_RTC_TIME_DATA_T *psRTCTimeDate; 21 | } RTC_InitTypeDef; 22 | 23 | int32_t RTC_Init( 24 | rtc_t *psObj, 25 | RTC_InitTypeDef *psInitDef 26 | ); 27 | 28 | int32_t RTC_EnableIntFlag( 29 | rtc_t *psObj, 30 | uint32_t u32IntFlagMask, 31 | PFN_RTC_INT_HANDLER pfnHandler 32 | ); 33 | 34 | int32_t RTC_DisableIntFlag( 35 | rtc_t *psObj, 36 | uint32_t u32IntFlagMask 37 | ); 38 | 39 | void Handle_RTC_Irq(RTC_T *rtc); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /M5531/example/Timer.py: -------------------------------------------------------------------------------- 1 | from pyb import Pin 2 | from pyb import Timer 3 | from pyb import PWM 4 | 5 | ############################################################## 6 | ## General timer function 7 | ############################################################## 8 | def tick(timer): 9 | print(timer.counter()) 10 | 11 | tim = Timer(3, freq = 2000) 12 | #tim.callback(tick) 13 | 14 | #PWM channel test 15 | chan = tim.channel(Timer.PWM, pin = Pin.board.D0, pulse_width_percent = 20) 16 | 17 | #output toggle channel test 18 | chan = tim.channel(Timer.OC_TOGGLE, pin = Pin.board.D0) 19 | 20 | ############################################################## 21 | ## Timer input capture function 22 | ############################################################## 23 | def tick(chan): 24 | print(chan.capture()) 25 | 26 | tim = Timer(3, freq = 100000) 27 | 28 | #source signal: NuMaker baord UNO A1 pin 29 | bpwm1 = PWM(1, freq = 2) 30 | bpwm1ch4 = bpwm1.channel(mode = PWM.OUTPUT, pulse_width_percent = 50, pin = Pin.board.A1) 31 | 32 | #capture pin: NuMaker board UNO MOSI ---> A1 33 | chan = tim.channel(Timer.IC, pin = Pin.board.MOSI, polarity = Timer.RISING) 34 | chan.callback(tick) 35 | -------------------------------------------------------------------------------- /M55M1/example/Timer.py: -------------------------------------------------------------------------------- 1 | from pyb import Pin 2 | from pyb import Timer 3 | from pyb import PWM 4 | 5 | ############################################################## 6 | ## General timer function 7 | ############################################################## 8 | def tick(timer): 9 | print(timer.counter()) 10 | 11 | tim = Timer(3, freq = 2000) 12 | #tim.callback(tick) 13 | 14 | #PWM channel test 15 | chan = tim.channel(Timer.PWM, pin = Pin.board.D0, pulse_width_percent = 20) 16 | 17 | #output toggle channel test 18 | chan = tim.channel(Timer.OC_TOGGLE, pin = Pin.board.D0) 19 | 20 | ############################################################## 21 | ## Timer input capture function 22 | ############################################################## 23 | def tick(chan): 24 | print(chan.capture()) 25 | 26 | tim = Timer(3, freq = 100000) 27 | 28 | #source signal: NuMaker baord UNO A1 pin 29 | bpwm1 = PWM(1, freq = 2) 30 | bpwm1ch4 = bpwm1.channel(mode = PWM.OUTPUT, pulse_width_percent = 50, pin = Pin.board.A1) 31 | 32 | #capture pin: NuMaker board UNO MOSI ---> A1 33 | chan = tim.channel(Timer.IC, pin = Pin.board.MOSI, polarity = Timer.RISING) 34 | chan.callback(tick) 35 | -------------------------------------------------------------------------------- /M5531/boards/m5531_prefix.c: -------------------------------------------------------------------------------- 1 | // m5531_prefix.c becomes the initial portion of the generated pins file. 2 | 3 | #include 4 | 5 | #include "py/obj.h" 6 | #include "py/mphal.h" 7 | #include "mods/classPin.h" 8 | 9 | #undef __PC 10 | #define __PC() 0 11 | 12 | #define AF(p_port, p_pin, p_mfp, af_idx, af_fn, af_unit, af_type, af_ptr) \ 13 | { \ 14 | { &pin_af_type }, \ 15 | .name = MP_QSTR_AF_P##p_port##p_pin##_ ## af_fn ## af_unit ##_ ## af_type, \ 16 | .idx = (af_idx), \ 17 | .fn = AF_FN_ ## af_fn, \ 18 | .unit = (af_unit), \ 19 | .type = AF_PIN_TYPE_ ## af_fn ## _ ## af_type, \ 20 | .reg = (af_ptr), \ 21 | .mfp_val = SYS_GP##p_port##_##p_mfp##_P##p_port##p_pin##MFP_## af_fn ## af_unit##_##af_type, \ 22 | } 23 | 24 | #define PIN(p_port, p_pin, p_mfp, p_af, p_adc_num, p_adc_channel) \ 25 | { \ 26 | { &pin_type }, \ 27 | .name = MP_QSTR_ ## p_port ## p_pin, \ 28 | .port = PORT_ ## p_port, \ 29 | .pin = (p_pin), \ 30 | .num_af = (sizeof(p_af) / sizeof(pin_af_obj_t)), \ 31 | .pin_mask = (1 << ((p_pin) & 0x0f)), \ 32 | .gpio = P ## p_port, \ 33 | .af = p_af, \ 34 | .adc_num = p_adc_num, \ 35 | .adc_channel = p_adc_channel, \ 36 | .mfp_reg = &SYS->GP##p_port##_##p_mfp, \ 37 | .mfos_reg = &SYS->GP##p_port##_MFOS, \ 38 | } 39 | -------------------------------------------------------------------------------- /M55M1/boards/m55m1_prefix.c: -------------------------------------------------------------------------------- 1 | // m55m1_prefix.c becomes the initial portion of the generated pins file. 2 | 3 | #include 4 | 5 | #include "py/obj.h" 6 | #include "py/mphal.h" 7 | #include "mods/classPin.h" 8 | 9 | #undef __PC 10 | #define __PC() 0 11 | 12 | #define AF(p_port, p_pin, p_mfp, af_idx, af_fn, af_unit, af_type, af_ptr) \ 13 | { \ 14 | { &pin_af_type }, \ 15 | .name = MP_QSTR_AF_P##p_port##p_pin##_ ## af_fn ## af_unit ##_ ## af_type, \ 16 | .idx = (af_idx), \ 17 | .fn = AF_FN_ ## af_fn, \ 18 | .unit = (af_unit), \ 19 | .type = AF_PIN_TYPE_ ## af_fn ## _ ## af_type, \ 20 | .reg = (af_ptr), \ 21 | .mfp_val = SYS_GP##p_port##_##p_mfp##_P##p_port##p_pin##MFP_## af_fn ## af_unit##_##af_type, \ 22 | } 23 | 24 | #define PIN(p_port, p_pin, p_mfp, p_af, p_adc_num, p_adc_channel) \ 25 | { \ 26 | { &pin_type }, \ 27 | .name = MP_QSTR_ ## p_port ## p_pin, \ 28 | .port = PORT_ ## p_port, \ 29 | .pin = (p_pin), \ 30 | .num_af = (sizeof(p_af) / sizeof(pin_af_obj_t)), \ 31 | .pin_mask = (1 << ((p_pin) & 0x0f)), \ 32 | .gpio = P ## p_port, \ 33 | .af = p_af, \ 34 | .adc_num = p_adc_num, \ 35 | .adc_channel = p_adc_channel, \ 36 | .mfp_reg = &SYS->GP##p_port##_##p_mfp, \ 37 | .mfos_reg = &SYS->GP##p_port##_MFOS, \ 38 | } 39 | -------------------------------------------------------------------------------- /M5531/hal/M5531_DAC.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_DAC.h 3 | * @version V1.00 4 | * @brief M5531 DAC HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_DAC_H__ 10 | #define __M5531_DAC_H__ 11 | 12 | typedef enum { 13 | eDAC_BITWIDTH_8 = 8, 14 | eDAC_BITWIDTH_12 = 12, 15 | } E_DAC_BITWIDTH; 16 | 17 | typedef struct { 18 | DAC_T *dac; 19 | } dac_t; 20 | 21 | typedef struct { 22 | uint32_t u32TriggerMode; // DAC_SOFTWARE_TRIGGER/DAC_TIMER0_TRIGGER/DAC_TIMER1_TRIGGER/DAC_TIMER2_TRIGGER/DAC_TIMER3_TRIGGER 23 | E_DAC_BITWIDTH eBitWidth; 24 | } DAC_InitTypeDef; 25 | 26 | int32_t DAC_Init( 27 | dac_t *psObj, 28 | DAC_InitTypeDef *psInitDef 29 | ); 30 | 31 | void DAC_Final( 32 | dac_t *psObj 33 | ); 34 | 35 | int32_t DAC_SingleConv( 36 | dac_t *psObj, 37 | uint32_t u32Data 38 | ); 39 | 40 | int32_t DAC_TimerPDMAConv( 41 | dac_t *psObj, 42 | TIMER_T *timer, 43 | uint32_t u32TriggerMode, 44 | E_DAC_BITWIDTH eBitWidth, 45 | uint8_t *pu8Buf, 46 | uint32_t u32BufLen, 47 | bool bCircular 48 | ); 49 | 50 | int32_t DAC_StopTimerPDMAConv( 51 | dac_t *psObj, 52 | TIMER_T *timer 53 | ); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_DAC.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_DAC.h 3 | * @version V1.00 4 | * @brief M55M1 DAC HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_DAC_H__ 10 | #define __M55M1_DAC_H__ 11 | 12 | typedef enum { 13 | eDAC_BITWIDTH_8 = 8, 14 | eDAC_BITWIDTH_12 = 12, 15 | } E_DAC_BITWIDTH; 16 | 17 | typedef struct { 18 | DAC_T *dac; 19 | } dac_t; 20 | 21 | typedef struct { 22 | uint32_t u32TriggerMode; // DAC_SOFTWARE_TRIGGER/DAC_TIMER0_TRIGGER/DAC_TIMER1_TRIGGER/DAC_TIMER2_TRIGGER/DAC_TIMER3_TRIGGER 23 | E_DAC_BITWIDTH eBitWidth; 24 | } DAC_InitTypeDef; 25 | 26 | int32_t DAC_Init( 27 | dac_t *psObj, 28 | DAC_InitTypeDef *psInitDef 29 | ); 30 | 31 | void DAC_Final( 32 | dac_t *psObj 33 | ); 34 | 35 | int32_t DAC_SingleConv( 36 | dac_t *psObj, 37 | uint32_t u32Data 38 | ); 39 | 40 | int32_t DAC_TimerPDMAConv( 41 | dac_t *psObj, 42 | TIMER_T *timer, 43 | uint32_t u32TriggerMode, 44 | E_DAC_BITWIDTH eBitWidth, 45 | uint8_t *pu8Buf, 46 | uint32_t u32BufLen, 47 | bool bCircular 48 | ); 49 | 50 | int32_t DAC_StopTimerPDMAConv( 51 | dac_t *psObj, 52 | TIMER_T *timer 53 | ); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /M5531/mods/classUART.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_UART_H 28 | #define MICROPY_INCLUDED_CLASS_UART_H 29 | 30 | extern const mp_obj_type_t machine_uart_type; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /M55M1/mods/classUART.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_UART_H 28 | #define MICROPY_INCLUDED_CLASS_UART_H 29 | 30 | extern const mp_obj_type_t machine_uart_type; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /M5531/mods/classDAC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_DAC_H 28 | #define MICROPY_INCLUDED_CLASS_DAC_H 29 | 30 | extern const mp_obj_type_t machine_dac_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_DAC_H 33 | -------------------------------------------------------------------------------- /M5531/mods/classRTC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_RTC_H 28 | #define MICROPY_INCLUDED_CLASS_RTC_H 29 | 30 | extern const mp_obj_type_t machine_rtc_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_RTC_H 33 | -------------------------------------------------------------------------------- /M5531/mods/classWDT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_WDT_H 28 | #define MICROPY_INCLUDED_CLASS_WDT_H 29 | 30 | extern const mp_obj_type_t machine_wdt_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_WDT_H 33 | -------------------------------------------------------------------------------- /M55M1/mods/classDAC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_DAC_H 28 | #define MICROPY_INCLUDED_CLASS_DAC_H 29 | 30 | extern const mp_obj_type_t machine_dac_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_DAC_H 33 | -------------------------------------------------------------------------------- /M55M1/mods/classRTC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_RTC_H 28 | #define MICROPY_INCLUDED_CLASS_RTC_H 29 | 30 | extern const mp_obj_type_t machine_rtc_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_RTC_H 33 | -------------------------------------------------------------------------------- /M55M1/mods/classWDT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_WDT_H 28 | #define MICROPY_INCLUDED_CLASS_WDT_H 29 | 30 | extern const mp_obj_type_t machine_wdt_type; 31 | 32 | #endif // MICROPY_INCLUDED_CLASS_WDT_H 33 | -------------------------------------------------------------------------------- /M5531/mods/classCAN.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_CAN_H 28 | #define MICROPY_INCLUDED_CLASS_CAN_H 29 | 30 | 31 | extern const mp_obj_type_t machine_can_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_CAN_H 35 | -------------------------------------------------------------------------------- /M5531/mods/classI2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_I2C_H 28 | #define MICROPY_INCLUDED_CLASS_I2C_H 29 | 30 | 31 | extern const mp_obj_type_t machine_i2c_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_I2C_H 35 | -------------------------------------------------------------------------------- /M5531/mods/classPWM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_PWM_H 28 | #define MICROPY_INCLUDED_CLASS_PWM_H 29 | 30 | 31 | extern const mp_obj_type_t machine_pwm_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_PWM_H 35 | -------------------------------------------------------------------------------- /M5531/mods/classSPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_SPI_H 28 | #define MICROPY_INCLUDED_CLASS_SPI_H 29 | 30 | 31 | extern const mp_obj_type_t machine_spi_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_SPI_H 35 | -------------------------------------------------------------------------------- /M55M1/mods/classCAN.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_CAN_H 28 | #define MICROPY_INCLUDED_CLASS_CAN_H 29 | 30 | 31 | extern const mp_obj_type_t machine_can_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_CAN_H 35 | -------------------------------------------------------------------------------- /M55M1/mods/classI2C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_I2C_H 28 | #define MICROPY_INCLUDED_CLASS_I2C_H 29 | 30 | 31 | extern const mp_obj_type_t machine_i2c_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_I2C_H 35 | -------------------------------------------------------------------------------- /M55M1/mods/classPWM.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_PWM_H 28 | #define MICROPY_INCLUDED_CLASS_PWM_H 29 | 30 | 31 | extern const mp_obj_type_t machine_pwm_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_PWM_H 35 | -------------------------------------------------------------------------------- /M55M1/mods/classSPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_SPI_H 28 | #define MICROPY_INCLUDED_CLASS_SPI_H 29 | 30 | 31 | extern const mp_obj_type_t machine_spi_type; 32 | 33 | 34 | #endif // MICROPY_INCLUDED_CLASS_SPI_H 35 | -------------------------------------------------------------------------------- /M5531/mods/pybflash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_PYB_FLASH_H 27 | #define MICROPY_INCLUDED_PYB_FLASH_H 28 | 29 | void flash_init(void); 30 | 31 | extern const struct _mp_obj_type_t pyb_flash_type; 32 | void pyb_flash_init_vfs(fs_user_mount_t *vfs); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /M55M1/mods/pybflash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_PYB_FLASH_H 27 | #define MICROPY_INCLUDED_PYB_FLASH_H 28 | 29 | void flash_init(void); 30 | 31 | extern const struct _mp_obj_type_t pyb_flash_type; 32 | void pyb_flash_init_vfs(fs_user_mount_t *vfs); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /M5531/mods/classADC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_ADC_H 28 | #define MICROPY_INCLUDED_CLASS_ADC_H 29 | 30 | 31 | extern const mp_obj_type_t machine_adc_type; 32 | extern const mp_obj_type_t machine_adc_all_type; 33 | 34 | 35 | #endif // MICROPY_INCLUDED_CLASS_ADC_H 36 | -------------------------------------------------------------------------------- /M55M1/mods/classADC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_ADC_H 28 | #define MICROPY_INCLUDED_CLASS_ADC_H 29 | 30 | 31 | extern const mp_obj_type_t machine_adc_type; 32 | extern const mp_obj_type_t machine_adc_all_type; 33 | 34 | 35 | #endif // MICROPY_INCLUDED_CLASS_ADC_H 36 | -------------------------------------------------------------------------------- /M5531/misc/mperror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * Copyright (c) 2015 Daniel Campora 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | #ifndef MICROPY_INCLUDED_M48X_MISC_MPERROR_H 28 | #define MICROPY_INCLUDED_M48X_MISC_MPERROR_H 29 | 30 | extern void NORETURN __fatal_error(const char *msg); 31 | 32 | 33 | #endif // MICROPY_INCLUDED_M48X_MISC_MPERROR_H 34 | -------------------------------------------------------------------------------- /M55M1/misc/mperror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * Copyright (c) 2015 Daniel Campora 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | #ifndef MICROPY_INCLUDED_M48X_MISC_MPERROR_H 28 | #define MICROPY_INCLUDED_M48X_MISC_MPERROR_H 29 | 30 | extern void NORETURN __fatal_error(const char *msg); 31 | 32 | 33 | #endif // MICROPY_INCLUDED_M48X_MISC_MPERROR_H 34 | -------------------------------------------------------------------------------- /M5531/bufhelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_BUFHELPER_H 27 | #define MICROPY_INCLUDED_BUFHELPER_H 28 | 29 | void pyb_buf_get_for_send(mp_obj_t o, mp_buffer_info_t *bufinfo, byte *tmp_data); 30 | mp_obj_t pyb_buf_get_for_recv(mp_obj_t o, vstr_t *vstr); 31 | 32 | #endif // MICROPY_INCLUDED_BUFHELPER_H 33 | -------------------------------------------------------------------------------- /M55M1/bufhelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_BUFHELPER_H 27 | #define MICROPY_INCLUDED_BUFHELPER_H 28 | 29 | void pyb_buf_get_for_send(mp_obj_t o, mp_buffer_info_t *bufinfo, byte *tmp_data); 30 | mp_obj_t pyb_buf_get_for_recv(mp_obj_t o, vstr_t *vstr); 31 | 32 | #endif // MICROPY_INCLUDED_BUFHELPER_H 33 | -------------------------------------------------------------------------------- /M5531/mods/pybsdcard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_PYB_SDCARD_H 27 | #define MICROPY_INCLUDED_PYB_SDCARD_H 28 | 29 | void sdcard_init(void); 30 | bool sdcard_is_present(void); 31 | 32 | 33 | extern const struct _mp_obj_type_t pyb_sdcard_type; 34 | void sdcard_init_vfs(fs_user_mount_t *vfs, int part); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /M55M1/mods/pybsdcard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_PYB_SDCARD_H 27 | #define MICROPY_INCLUDED_PYB_SDCARD_H 28 | 29 | void sdcard_init(void); 30 | bool sdcard_is_present(void); 31 | 32 | 33 | extern const struct _mp_obj_type_t pyb_sdcard_type; 34 | void sdcard_init_vfs(fs_user_mount_t *vfs, int part); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /M5531/hal/pin_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M5531_PININT_H 27 | #define MICROPY_INCLUDED_M5531_PININT_H 28 | 29 | 30 | extern void extint_init0(void); 31 | extern void Handle_GPIO_Irq(uint32_t line); 32 | extern void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj); 33 | 34 | #endif // MICROPY_INCLUDED_M5531_PININT_H 35 | 36 | -------------------------------------------------------------------------------- /M55M1/hal/pin_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M55M1_PININT_H 27 | #define MICROPY_INCLUDED_M55M1_PININT_H 28 | 29 | 30 | extern void extint_init0(void); 31 | extern void Handle_GPIO_Irq(uint32_t line); 32 | extern void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_obj_t callback_obj); 33 | 34 | #endif // MICROPY_INCLUDED_M55M1_PININT_H 35 | 36 | -------------------------------------------------------------------------------- /M5531/mpthreadport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef __MPTHREADPORT_H__ 28 | #define __MPTHREADPORT_H__ 29 | 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | #include "queue.h" 34 | 35 | typedef struct _mp_thread_mutex_t { 36 | SemaphoreHandle_t handle; 37 | StaticSemaphore_t buffer; 38 | } mp_thread_mutex_t; 39 | 40 | void mp_thread_init(void *stack, uint32_t stack_len); 41 | void mp_thread_gc_others(void); 42 | void mp_thread_deinit(void); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /M55M1/mpthreadport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef __MPTHREADPORT_H__ 28 | #define __MPTHREADPORT_H__ 29 | 30 | #include "FreeRTOS.h" 31 | #include "task.h" 32 | #include "semphr.h" 33 | #include "queue.h" 34 | 35 | typedef struct _mp_thread_mutex_t { 36 | SemaphoreHandle_t handle; 37 | StaticSemaphore_t buffer; 38 | } mp_thread_mutex_t; 39 | 40 | void mp_thread_init(void *stack, uint32_t stack_len); 41 | void mp_thread_gc_others(void); 42 | void mp_thread_deinit(void); 43 | 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /M5531/mods/classTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_TIMER_H 28 | #define MICROPY_INCLUDED_CLASS_TIMER_H 29 | 30 | 31 | extern const mp_obj_type_t machine_timer_type; 32 | extern const mp_obj_type_t machine_timer_channel_type; 33 | 34 | MP_DECLARE_CONST_FUN_OBJ_KW(pyb_timer_init_obj); 35 | MP_DECLARE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj); 36 | 37 | 38 | mp_obj_t pytimer_get_timerobj( 39 | int timer_id 40 | ); 41 | 42 | TIMER_T *pyb_timer_get_handle(mp_obj_t timer); 43 | 44 | 45 | #endif // MICROPY_INCLUDED_CLASS_TIMER_H 46 | -------------------------------------------------------------------------------- /M55M1/mods/classTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #ifndef MICROPY_INCLUDED_CLASS_TIMER_H 28 | #define MICROPY_INCLUDED_CLASS_TIMER_H 29 | 30 | 31 | extern const mp_obj_type_t machine_timer_type; 32 | extern const mp_obj_type_t machine_timer_channel_type; 33 | 34 | MP_DECLARE_CONST_FUN_OBJ_KW(pyb_timer_init_obj); 35 | MP_DECLARE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj); 36 | 37 | 38 | mp_obj_t pytimer_get_timerobj( 39 | int timer_id 40 | ); 41 | 42 | TIMER_T *pyb_timer_get_handle(mp_obj_t timer); 43 | 44 | 45 | #endif // MICROPY_INCLUDED_CLASS_TIMER_H 46 | -------------------------------------------------------------------------------- /M5531/gccollect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M48X_GCCOLLECT_H 27 | #define MICROPY_INCLUDED_M48X_GCCOLLECT_H 28 | 29 | // variables defining memory layout 30 | // (these probably belong somewhere else...) 31 | extern uint32_t _etext; 32 | extern uint32_t _sidata; 33 | extern uint32_t _ram_start; 34 | extern uint32_t _sdata; 35 | extern uint32_t _edata; 36 | extern uint32_t _sbss; 37 | extern uint32_t _ebss; 38 | extern uint32_t _heap_start; 39 | extern uint32_t _heap_end; 40 | extern uint32_t _estack; 41 | extern uint32_t _ram_end; 42 | 43 | #endif // MICROPY_INCLUDED_M48X_GCCOLLECT_H 44 | -------------------------------------------------------------------------------- /M55M1/gccollect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M48X_GCCOLLECT_H 27 | #define MICROPY_INCLUDED_M48X_GCCOLLECT_H 28 | 29 | // variables defining memory layout 30 | // (these probably belong somewhere else...) 31 | extern uint32_t _etext; 32 | extern uint32_t _sidata; 33 | extern uint32_t _ram_start; 34 | extern uint32_t _sdata; 35 | extern uint32_t _edata; 36 | extern uint32_t _sbss; 37 | extern uint32_t _ebss; 38 | extern uint32_t _heap_start; 39 | extern uint32_t _heap_end; 40 | extern uint32_t _estack; 41 | extern uint32_t _ram_end; 42 | 43 | #endif // MICROPY_INCLUDED_M48X_GCCOLLECT_H 44 | -------------------------------------------------------------------------------- /M5531/mphalport.h: -------------------------------------------------------------------------------- 1 | 2 | typedef enum { 3 | HAL_OK = 0x00U, 4 | HAL_ERROR = 0x01U, 5 | HAL_BUSY = 0x02U, 6 | HAL_TIMEOUT = 0x03U 7 | } HAL_StatusTypeDef; 8 | 9 | NORETURN void mp_hal_raise(HAL_StatusTypeDef status); 10 | 11 | #if MICROPY_KBD_EXCEPTION 12 | #include "shared/runtime/interrupt_char.h" 13 | #else 14 | static inline void mp_hal_set_interrupt_char(char c) {} 15 | #endif 16 | 17 | #define mp_hal_delay_us_fast(us) mp_hal_delay_us(us) 18 | 19 | #include "mods/classPin.h" 20 | 21 | #define MP_HAL_PIN_FMT "%q" 22 | #define mp_hal_pin_name(p) (p) 23 | 24 | #define MP_HAL_PIN_MODE_INPUT GPIO_MODE_INPUT 25 | #define MP_HAL_PIN_MODE_OUTPUT GPIO_MODE_OUTPUT 26 | #define MP_HAL_PIN_MODE_OPEN_DRAIN GPIO_MODE_OPEN_DRAIN 27 | #define MP_HAL_PIN_MODE_ALT_OPEN_DRAIN GPIO_MODE_AF_OD 28 | #define MP_HAL_PIN_MODE_ALT_PUSH_PULL GPIO_MODE_AF_PP 29 | 30 | #define mp_hal_pin_obj_t const pin_obj_t* 31 | #define mp_hal_pin_open_drain(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OPEN_DRAIN, 0) 32 | #define mp_hal_get_pin_obj(o) pin_find(o) 33 | #define mp_hal_pin_od_low(p) mp_hal_pin_low(p) 34 | #define mp_hal_pin_od_high(p) mp_hal_pin_high(p) 35 | 36 | void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, const pin_af_obj_t *af_obj); 37 | bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint8_t fn, uint8_t unit); 38 | 39 | #define mp_hal_pin_output(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OUTPUT, 0) 40 | #define mp_hal_pin_input(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_INPUT, 0) 41 | 42 | void mp_hal_ticks_cpu_enable(void); 43 | static inline mp_uint_t mp_hal_ticks_cpu(void) 44 | { 45 | if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { 46 | mp_hal_ticks_cpu_enable(); 47 | } 48 | return DWT->CYCCNT; 49 | } 50 | 51 | // Atomic section helpers. 52 | #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() 53 | #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) 54 | 55 | -------------------------------------------------------------------------------- /M55M1/mphalport.h: -------------------------------------------------------------------------------- 1 | 2 | typedef enum { 3 | HAL_OK = 0x00U, 4 | HAL_ERROR = 0x01U, 5 | HAL_BUSY = 0x02U, 6 | HAL_TIMEOUT = 0x03U 7 | } HAL_StatusTypeDef; 8 | 9 | NORETURN void mp_hal_raise(HAL_StatusTypeDef status); 10 | 11 | #if MICROPY_KBD_EXCEPTION 12 | #include "shared/runtime/interrupt_char.h" 13 | #else 14 | static inline void mp_hal_set_interrupt_char(char c) {} 15 | #endif 16 | 17 | #define mp_hal_delay_us_fast(us) mp_hal_delay_us(us) 18 | 19 | #include "mods/classPin.h" 20 | 21 | #define MP_HAL_PIN_FMT "%q" 22 | #define mp_hal_pin_name(p) (p) 23 | 24 | #define MP_HAL_PIN_MODE_INPUT GPIO_MODE_INPUT 25 | #define MP_HAL_PIN_MODE_OUTPUT GPIO_MODE_OUTPUT 26 | #define MP_HAL_PIN_MODE_OPEN_DRAIN GPIO_MODE_OPEN_DRAIN 27 | #define MP_HAL_PIN_MODE_ALT_OPEN_DRAIN GPIO_MODE_AF_OD 28 | #define MP_HAL_PIN_MODE_ALT_PUSH_PULL GPIO_MODE_AF_PP 29 | 30 | #define mp_hal_pin_obj_t const pin_obj_t* 31 | #define mp_hal_pin_open_drain(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OPEN_DRAIN, 0) 32 | #define mp_hal_get_pin_obj(o) pin_find(o) 33 | #define mp_hal_pin_od_low(p) mp_hal_pin_low(p) 34 | #define mp_hal_pin_od_high(p) mp_hal_pin_high(p) 35 | 36 | void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, const pin_af_obj_t *af_obj); 37 | bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint8_t fn, uint8_t unit); 38 | 39 | #define mp_hal_pin_output(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OUTPUT, 0) 40 | #define mp_hal_pin_input(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_INPUT, 0) 41 | 42 | void mp_hal_ticks_cpu_enable(void); 43 | static inline mp_uint_t mp_hal_ticks_cpu(void) 44 | { 45 | if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { 46 | mp_hal_ticks_cpu_enable(); 47 | } 48 | return DWT->CYCCNT; 49 | } 50 | 51 | // Atomic section helpers. 52 | #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() 53 | #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) 54 | 55 | -------------------------------------------------------------------------------- /M5531/fatfs_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * Development of the code in this file was sponsored by Microbric Pty Ltd 5 | * 6 | * The MIT License (MIT) 7 | * 8 | * Copyright (c) 2013, 2014, 2016 Damien P. George 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | #include "py/obj.h" 30 | #include "lib/oofatfs/ff.h" 31 | #include "shared/timeutils/timeutils.h" 32 | 33 | DWORD get_fattime(void) 34 | { 35 | 36 | // TODO: 37 | //uint32_t secs = (uint32_t)(pyb_rtc_get_us_since_2000() / 1000000); 38 | #if 0 39 | uint32_t secs = 0; 40 | 41 | timeutils_struct_time_t tm; 42 | timeutils_seconds_since_2000_to_struct_time(secs, &tm); 43 | 44 | return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) | 45 | ((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1)); 46 | #else 47 | return (((DWORD)(2018 - 1980) << 25) | ((DWORD)9 << 21) | ((DWORD)4 << 16) | 48 | ((DWORD)18 << 11) | ((DWORD)0 << 5) | ((DWORD)0 >> 1)); 49 | #endif 50 | } 51 | -------------------------------------------------------------------------------- /M55M1/fatfs_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * Development of the code in this file was sponsored by Microbric Pty Ltd 5 | * 6 | * The MIT License (MIT) 7 | * 8 | * Copyright (c) 2013, 2014, 2016 Damien P. George 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in 18 | * all copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 | * THE SOFTWARE. 27 | */ 28 | 29 | #include "py/obj.h" 30 | #include "lib/oofatfs/ff.h" 31 | #include "shared/timeutils/timeutils.h" 32 | 33 | DWORD get_fattime(void) 34 | { 35 | 36 | // TODO: 37 | //uint32_t secs = (uint32_t)(pyb_rtc_get_us_since_2000() / 1000000); 38 | #if 0 39 | uint32_t secs = 0; 40 | 41 | timeutils_struct_time_t tm; 42 | timeutils_seconds_since_2000_to_struct_time(secs, &tm); 43 | 44 | return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) | 45 | ((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1)); 46 | #else 47 | return (((DWORD)(2018 - 1980) << 25) | ((DWORD)9 << 21) | ((DWORD)4 << 16) | 48 | ((DWORD)18 << 11) | ((DWORD)0 << 5) | ((DWORD)0 >> 1)); 49 | #endif 50 | } 51 | -------------------------------------------------------------------------------- /M5531/hal/M5531_I2C.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_I2C.h 3 | * @version V1.00 4 | * @brief M5531 I2C HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_I2C_H__ 10 | #define __M5531_I2C_H__ 11 | 12 | #define I2C_MODE_MASTER (0) 13 | #define I2C_MODE_SLAVE (1) 14 | 15 | typedef struct { 16 | union { 17 | I2C_T *i2c; 18 | LPI2C_T *lpi2c; 19 | } u_i2c; 20 | bool bLPI2C; 21 | } i2c_t; 22 | 23 | typedef struct { 24 | uint32_t Mode; //Master/Slave mode: I2C_MODE_MASTER/I2C_MODE_SLAVE 25 | uint32_t BaudRate; //Baud rate 26 | uint8_t GeneralCallMode; //Support general call mode: I2C_GCMODE_ENABLE/I2C_GCMODE_DISABLE 27 | uint8_t OwnAddress; //Slave own address 28 | } I2C_InitTypeDef; 29 | 30 | typedef struct { 31 | uint8_t u8SlaveAddr; //Used by master 32 | uint8_t *pu8DataAddr; //Used by master data address access, it can be one/two bytes 33 | uint8_t u8DataAddrLen; //Used by master 34 | uint8_t *pu8Data; 35 | uint32_t u32DataLen; 36 | } I2C_TRANS_PARAM; 37 | 38 | int32_t I2C_Init( 39 | i2c_t *psI2CObj, 40 | I2C_InitTypeDef *psInitDef 41 | ); 42 | 43 | void I2C_Final( 44 | i2c_t *psI2CObj 45 | ); 46 | 47 | 48 | #define I2C_DEVICE_OK (0) 49 | #define I2C_DEVICE_BUSY (1) 50 | #define I2C_DEVICE_ERROR (2) 51 | 52 | int32_t I2C_DeviceReady( 53 | i2c_t *psI2CObj, 54 | uint8_t u8SlaveAddr 55 | ); 56 | 57 | void Handle_I2C_Irq(I2C_T *i2c, uint32_t u32Status); 58 | void Handle_LPI2C_Irq(LPI2C_T *lpi2c, uint32_t u32Status); 59 | 60 | int I2C_MaterSendRecv( 61 | i2c_t *psI2CObj, 62 | uint8_t u8Recv, 63 | I2C_TRANS_PARAM *psParam, 64 | uint32_t u32TimeOut 65 | ); 66 | 67 | int I2C_SlaveSendRecv( 68 | i2c_t *psI2CObj, 69 | uint8_t u8Recv, 70 | I2C_TRANS_PARAM *psParam, 71 | uint32_t u32TimeOut 72 | ); 73 | 74 | int32_t I2C_HookIRQHandler( 75 | i2c_t *psI2CObj, 76 | uint8_t u8Recv, 77 | uint8_t u8Master 78 | ); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_I2C.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_I2C.h 3 | * @version V1.00 4 | * @brief M55M1 I2C HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_I2C_H__ 10 | #define __M55M1_I2C_H__ 11 | 12 | #define I2C_MODE_MASTER (0) 13 | #define I2C_MODE_SLAVE (1) 14 | 15 | typedef struct { 16 | union { 17 | I2C_T *i2c; 18 | LPI2C_T *lpi2c; 19 | } u_i2c; 20 | bool bLPI2C; 21 | } i2c_t; 22 | 23 | typedef struct { 24 | uint32_t Mode; //Master/Slave mode: I2C_MODE_MASTER/I2C_MODE_SLAVE 25 | uint32_t BaudRate; //Baud rate 26 | uint8_t GeneralCallMode; //Support general call mode: I2C_GCMODE_ENABLE/I2C_GCMODE_DISABLE 27 | uint8_t OwnAddress; //Slave own address 28 | } I2C_InitTypeDef; 29 | 30 | typedef struct { 31 | uint8_t u8SlaveAddr; //Used by master 32 | uint8_t *pu8DataAddr; //Used by master data address access, it can be one/two bytes 33 | uint8_t u8DataAddrLen; //Used by master 34 | uint8_t *pu8Data; 35 | uint32_t u32DataLen; 36 | } I2C_TRANS_PARAM; 37 | 38 | int32_t I2C_Init( 39 | i2c_t *psI2CObj, 40 | I2C_InitTypeDef *psInitDef 41 | ); 42 | 43 | void I2C_Final( 44 | i2c_t *psI2CObj 45 | ); 46 | 47 | 48 | #define I2C_DEVICE_OK (0) 49 | #define I2C_DEVICE_BUSY (1) 50 | #define I2C_DEVICE_ERROR (2) 51 | 52 | int32_t I2C_DeviceReady( 53 | i2c_t *psI2CObj, 54 | uint8_t u8SlaveAddr 55 | ); 56 | 57 | void Handle_I2C_Irq(I2C_T *i2c, uint32_t u32Status); 58 | void Handle_LPI2C_Irq(LPI2C_T *lpi2c, uint32_t u32Status); 59 | 60 | int I2C_MaterSendRecv( 61 | i2c_t *psI2CObj, 62 | uint8_t u8Recv, 63 | I2C_TRANS_PARAM *psParam, 64 | uint32_t u32TimeOut 65 | ); 66 | 67 | int I2C_SlaveSendRecv( 68 | i2c_t *psI2CObj, 69 | uint8_t u8Recv, 70 | I2C_TRANS_PARAM *psParam, 71 | uint32_t u32TimeOut 72 | ); 73 | 74 | int32_t I2C_HookIRQHandler( 75 | i2c_t *psI2CObj, 76 | uint8_t u8Recv, 77 | uint8_t u8Master 78 | ); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /M5531/bufhelper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "bufhelper.h" 29 | 30 | void pyb_buf_get_for_send(mp_obj_t o, mp_buffer_info_t *bufinfo, byte *tmp_data) 31 | { 32 | if (MP_OBJ_IS_INT(o)) { 33 | tmp_data[0] = mp_obj_get_int(o); 34 | bufinfo->buf = tmp_data; 35 | bufinfo->len = 1; 36 | bufinfo->typecode = 'B'; 37 | } else { 38 | mp_get_buffer_raise(o, bufinfo, MP_BUFFER_READ); 39 | } 40 | } 41 | 42 | mp_obj_t pyb_buf_get_for_recv(mp_obj_t o, vstr_t *vstr) 43 | { 44 | if (MP_OBJ_IS_INT(o)) { 45 | // allocate a new bytearray of given length 46 | vstr_init_len(vstr, mp_obj_get_int(o)); 47 | return MP_OBJ_NULL; 48 | } else { 49 | // get the existing buffer 50 | mp_buffer_info_t bufinfo; 51 | mp_get_buffer_raise(o, &bufinfo, MP_BUFFER_WRITE); 52 | vstr->buf = bufinfo.buf; 53 | vstr->len = bufinfo.len; 54 | return o; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /M55M1/bufhelper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "bufhelper.h" 29 | 30 | void pyb_buf_get_for_send(mp_obj_t o, mp_buffer_info_t *bufinfo, byte *tmp_data) 31 | { 32 | if (MP_OBJ_IS_INT(o)) { 33 | tmp_data[0] = mp_obj_get_int(o); 34 | bufinfo->buf = tmp_data; 35 | bufinfo->len = 1; 36 | bufinfo->typecode = 'B'; 37 | } else { 38 | mp_get_buffer_raise(o, bufinfo, MP_BUFFER_READ); 39 | } 40 | } 41 | 42 | mp_obj_t pyb_buf_get_for_recv(mp_obj_t o, vstr_t *vstr) 43 | { 44 | if (MP_OBJ_IS_INT(o)) { 45 | // allocate a new bytearray of given length 46 | vstr_init_len(vstr, mp_obj_get_int(o)); 47 | return MP_OBJ_NULL; 48 | } else { 49 | // get the existing buffer 50 | mp_buffer_info_t bufinfo; 51 | mp_get_buffer_raise(o, &bufinfo, MP_BUFFER_WRITE); 52 | vstr->buf = bufinfo.buf; 53 | vstr->len = bufinfo.len; 54 | return o; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NuMicroPy 2 | NuMicroPy is Nuvoton microcontroller porting for MicroPython. MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments. See [MicroPython](http://micropython.org/) 3 | 4 | ---- 5 | ## Major components in this repository 6 | - M55M1/ -- M55M1 porting of MicroPython 7 | - M5531/ -- M5531 porting of MicroPython 8 | - build/ -- Prebuilt frimware 9 | ---- 10 | ## Supported target 11 | Board |MCU |Required ROM size |Required RAM size 12 | :----------------|---------|----------------------|------------------ 13 | NuMaker-M55M1 |M55M1 |342KB |350KB 14 | NuMaker-M5531 |M5531 |342KB |350KB 15 | ---- 16 | ## How to run NuMicroPy 17 | 1. Download and install [NuMicro ICP Programming Tool v3.20](https://www.nuvoton.com/tool-and-software/software-tool/programmer-tool/) 18 | 2. Hardware setup steps 19 | a. Turn on ICE function switch pin 1 and 2 20 | ![NuMaker-M55M1](Picture/NuMaker-M55M1.png) 21 | b. Connect ICE USB port to PC 22 | 3. Burn firmware 23 | Nu-Link-Me exported a "NuMicro MCU" disk, just Copy and Paste prebuilt firmware.bin into "NuMicro MCU" disk. 24 | ![CopyPasteFirmware](Picture/NuMicroDisk.jpg) 25 | a. Connected FSUSB port to PC. 26 | b. Setup your terminal program 27 | ![TeraTerm_setup1](Picture/TerminalSetup_0.jpg) 28 | ![TeraTerm_setup2](Picture/TermianlSetup_1.jpg) 29 | c. Press the BTN0 + RESET button. Firmware will export a PYBFLASH disk. 30 | ![PYBFLASH disk](Picture/pybflash.jpg) 31 | d. Update your python code to boot.py or main.py 32 | ![Main Code](Picture/upate_code.jpg) 33 | e. Press the RESET button. 34 | ![Execute Result](Picture/ExecuteResult.png) 35 | ---- 36 | ## How to build firmware 37 | To develop firmware for MicroPython, it is best to use a Unix-like machine. (preferred on Unubtu 22.04). 38 | 1. Packages and toolchain installation 39 | Please following [install.txt](install.txt) instructions 40 | 2. Build firmware 41 | To build NuMicroPy firmare for M55M1, use the following command 42 | ``` 43 | cd M55M1 44 | make V=1 45 | ``` 46 | For M5531 47 | ``` 48 | cd M5531 49 | make V=1 50 | ``` 51 | -------------------------------------------------------------------------------- /M5531/hal/StorIF.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file StorIF.h 3 | * @brief Storage access interface 4 | * @version 0.0.1 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved. 8 | ******************************************************************************/ 9 | #ifndef __STORIF_H__ 10 | #define __STORIF_H__ 11 | 12 | #include 13 | 14 | #define STORIF_SECTOR_SIZE 512 15 | 16 | typedef enum { 17 | eSTORIF_ERRNO_NONE = 0, 18 | eSTORIF_ERRNO_NULL_PTR = -1, 19 | eSTORIF_ERRNO_MALLOC = -2, 20 | eSTORIF_ERRNO_IO = -3, 21 | eSTORIF_ERRNO_SIZE = -4, 22 | eSTORIF_ERRNO_NOT_READY = -5, 23 | eSTORIF_ERRNO_STOR_OPEN = -6, 24 | eSTORIF_ERRNO_DEVICE = -7, 25 | } E_STORIF_ERRNO; 26 | 27 | 28 | typedef E_STORIF_ERRNO 29 | (*PFN_STORIF_INIT)( 30 | int32_t i32Inst, 31 | void **ppStorRes 32 | ); 33 | 34 | typedef int32_t 35 | (*PFN_STORIF_READ_SECTOR)( 36 | uint8_t *pu8Buff, /* Data buffer to store read data */ 37 | uint32_t u32Sector, /* Sector address (LBA) */ 38 | uint32_t u32Count, /* Number of sectors to read (1..128) */ 39 | void *pvStorRes 40 | ); 41 | 42 | typedef int32_t 43 | (*PFN_STORIF_WRITE_SECTOR)( 44 | uint8_t *pu8Buff, /* Data buffer to store read data */ 45 | uint32_t u32Sector, /* Sector address (LBA) */ 46 | uint32_t u32Count, /* Number of sectors to read (1..128) */ 47 | void *pvStorRes 48 | ); 49 | 50 | typedef int32_t 51 | (*PFN_STORIF_DETECT)( 52 | void *pvStorRes 53 | ); 54 | 55 | typedef struct { 56 | uint32_t u32TotalSector; 57 | uint32_t u32DiskSize; //K Bytes 58 | uint32_t u32SectorSize; // Bytes 59 | uint32_t u32SubType; 60 | } S_STORIF_INFO; 61 | 62 | 63 | typedef E_STORIF_ERRNO 64 | (*PFN_STORIF_GET_INFO)( 65 | S_STORIF_INFO *psInfo, 66 | void *pvStorRes 67 | ); 68 | 69 | 70 | typedef struct { 71 | PFN_STORIF_INIT pfnStorInit; 72 | PFN_STORIF_READ_SECTOR pfnReadSector; 73 | PFN_STORIF_WRITE_SECTOR pfnWriteSector; 74 | PFN_STORIF_DETECT pfnDetect; 75 | PFN_STORIF_GET_INFO pfnGetInfo; 76 | void *pvStorPriv; 77 | } S_STORIF_IF; 78 | 79 | extern S_STORIF_IF g_STORIF_sFlash; 80 | extern S_STORIF_IF g_STORIF_sSPIFlash; 81 | extern S_STORIF_IF g_STORIF_sSDCard; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /M55M1/hal/StorIF.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************//** 2 | * @file StorIF.h 3 | * @brief Storage access interface 4 | * @version 0.0.1 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved. 8 | ******************************************************************************/ 9 | #ifndef __STORIF_H__ 10 | #define __STORIF_H__ 11 | 12 | #include 13 | 14 | #define STORIF_SECTOR_SIZE 512 15 | 16 | typedef enum { 17 | eSTORIF_ERRNO_NONE = 0, 18 | eSTORIF_ERRNO_NULL_PTR = -1, 19 | eSTORIF_ERRNO_MALLOC = -2, 20 | eSTORIF_ERRNO_IO = -3, 21 | eSTORIF_ERRNO_SIZE = -4, 22 | eSTORIF_ERRNO_NOT_READY = -5, 23 | eSTORIF_ERRNO_STOR_OPEN = -6, 24 | eSTORIF_ERRNO_DEVICE = -7, 25 | } E_STORIF_ERRNO; 26 | 27 | 28 | typedef E_STORIF_ERRNO 29 | (*PFN_STORIF_INIT)( 30 | int32_t i32Inst, 31 | void **ppStorRes 32 | ); 33 | 34 | typedef int32_t 35 | (*PFN_STORIF_READ_SECTOR)( 36 | uint8_t *pu8Buff, /* Data buffer to store read data */ 37 | uint32_t u32Sector, /* Sector address (LBA) */ 38 | uint32_t u32Count, /* Number of sectors to read (1..128) */ 39 | void *pvStorRes 40 | ); 41 | 42 | typedef int32_t 43 | (*PFN_STORIF_WRITE_SECTOR)( 44 | uint8_t *pu8Buff, /* Data buffer to store read data */ 45 | uint32_t u32Sector, /* Sector address (LBA) */ 46 | uint32_t u32Count, /* Number of sectors to read (1..128) */ 47 | void *pvStorRes 48 | ); 49 | 50 | typedef int32_t 51 | (*PFN_STORIF_DETECT)( 52 | void *pvStorRes 53 | ); 54 | 55 | typedef struct { 56 | uint32_t u32TotalSector; 57 | uint32_t u32DiskSize; //K Bytes 58 | uint32_t u32SectorSize; // Bytes 59 | uint32_t u32SubType; 60 | } S_STORIF_INFO; 61 | 62 | 63 | typedef E_STORIF_ERRNO 64 | (*PFN_STORIF_GET_INFO)( 65 | S_STORIF_INFO *psInfo, 66 | void *pvStorRes 67 | ); 68 | 69 | 70 | typedef struct { 71 | PFN_STORIF_INIT pfnStorInit; 72 | PFN_STORIF_READ_SECTOR pfnReadSector; 73 | PFN_STORIF_WRITE_SECTOR pfnWriteSector; 74 | PFN_STORIF_DETECT pfnDetect; 75 | PFN_STORIF_GET_INFO pfnGetInfo; 76 | void *pvStorPriv; 77 | } S_STORIF_IF; 78 | 79 | extern S_STORIF_IF g_STORIF_sFlash; 80 | extern S_STORIF_IF g_STORIF_sSPIFlash; 81 | extern S_STORIF_IF g_STORIF_sSDCard; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /M5531/misc/mperror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * Copyright (c) 2015 Daniel Campora 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #include "py/nlr.h" 33 | #include "py/compile.h" 34 | #include "py/mphal.h" 35 | 36 | 37 | void NORETURN __fatal_error(const char *msg) 38 | { 39 | for (volatile uint delay = 0; delay < 10000000; delay++) { 40 | } 41 | // led_state(1, 1); 42 | // led_state(2, 1); 43 | // led_state(3, 1); 44 | // led_state(4, 1); 45 | mp_hal_stdout_tx_strn("\nFATAL ERROR:\n", 14); 46 | mp_hal_stdout_tx_strn(msg, strlen(msg)); 47 | for (uint i = 0;;) { 48 | // led_toggle(((i++) & 3) + 1); 49 | for (volatile uint delay = 0; delay < 10000000; delay++) { 50 | } 51 | if (i >= 16) { 52 | // to conserve power 53 | __WFI(); 54 | } 55 | } 56 | } 57 | 58 | 59 | void nlr_jump_fail(void *val) 60 | { 61 | printf("FATAL: uncaught exception %p\n", val); 62 | mp_obj_print_exception(&mp_plat_print, (mp_obj_t)val); 63 | __fatal_error(""); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /M55M1/misc/mperror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * Copyright (c) 2015 Daniel Campora 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | */ 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #include "py/nlr.h" 33 | #include "py/compile.h" 34 | #include "py/mphal.h" 35 | 36 | 37 | void NORETURN __fatal_error(const char *msg) 38 | { 39 | for (volatile uint delay = 0; delay < 10000000; delay++) { 40 | } 41 | // led_state(1, 1); 42 | // led_state(2, 1); 43 | // led_state(3, 1); 44 | // led_state(4, 1); 45 | mp_hal_stdout_tx_strn("\nFATAL ERROR:\n", 14); 46 | mp_hal_stdout_tx_strn(msg, strlen(msg)); 47 | for (uint i = 0;;) { 48 | // led_toggle(((i++) & 3) + 1); 49 | for (volatile uint delay = 0; delay < 10000000; delay++) { 50 | } 51 | if (i >= 16) { 52 | // to conserve power 53 | __WFI(); 54 | } 55 | } 56 | } 57 | 58 | 59 | void nlr_jump_fail(void *val) 60 | { 61 | printf("FATAL: uncaught exception %p\n", val); 62 | mp_obj_print_exception(&mp_plat_print, (mp_obj_t)val); 63 | __fatal_error(""); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /M5531/hal/M5531_UART.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_UART.h 3 | * @version V1.00 4 | * @brief M5531 UART HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_UART_H__ 10 | #define __M5531_UART_H__ 11 | 12 | #include "buffer.h" 13 | #include "drv_pdma.h" 14 | 15 | typedef enum { 16 | eUART_HWCONTROL_NONE = 0, 17 | eUART_HWCONTROL_CTS = 1, 18 | eUART_HWCONTROL_RTS = 2, 19 | } E_UART_HWCONTROL; 20 | 21 | typedef struct { 22 | uint32_t u32BaudRate; 23 | uint32_t u32DataWidth; 24 | uint32_t u32Parity; 25 | uint32_t u32StopBits; 26 | E_UART_HWCONTROL eFlowControl; 27 | } UART_InitTypeDef; 28 | 29 | typedef void(*PFN_HDLR_DMA_TX)(void *, int); 30 | typedef void(*PFN_HDLR_DMA_RX)(void *, int); 31 | 32 | 33 | typedef struct { 34 | union { 35 | UART_T *uart; 36 | LPUART_T *lpuart; 37 | } u_uart; 38 | bool bLPUART; 39 | E_PDMAUsage dma_usage; 40 | int dma_chn_id_tx; 41 | int dma_chn_id_rx; 42 | uint32_t event; 43 | uint32_t hdlr_async; 44 | PFN_HDLR_DMA_TX hdlr_dma_tx; 45 | PFN_HDLR_DMA_RX hdlr_dma_rx; 46 | struct buffer_s tx_buff; /**< Tx buffer */ 47 | struct buffer_s rx_buff; /**< Rx buffer */ 48 | } uart_t; 49 | 50 | 51 | int32_t UART_Init( 52 | uart_t *psObj, 53 | UART_InitTypeDef *psInitDef, 54 | uint32_t IRQHandler 55 | ); 56 | 57 | void UART_Final(uart_t *psObj); 58 | 59 | void Handle_UART_Irq(UART_T *uart); 60 | void Handle_LPUART_Irq(LPUART_T *lpuart); 61 | 62 | int32_t UART_DMA_TXRX_Enable( 63 | uart_t *psObj, 64 | PFN_HDLR_DMA_TX pfnHandlerDMATx, 65 | PFN_HDLR_DMA_RX pfnHandlerDMARx 66 | ); 67 | 68 | int32_t UART_DMA_TXRX_Disable( 69 | uart_t *psObj 70 | ); 71 | 72 | int32_t UART_DMA_RX_Start( 73 | uart_t *psObj, 74 | uint8_t *pu8DestBuf, 75 | int32_t i32TriggerLen 76 | ); 77 | 78 | int32_t UART_DMA_RX_Stop( 79 | uart_t *psObj 80 | ); 81 | 82 | int32_t UART_DMA_TX_Start( 83 | uart_t *psObj, 84 | uint8_t *pu8SrcBuf, 85 | int32_t i32TriggerLen 86 | ); 87 | 88 | int32_t UART_DMA_TX_Stop( 89 | uart_t *psObj 90 | ); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_UART.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_UART.h 3 | * @version V1.00 4 | * @brief M55M1 UART HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_UART_H__ 10 | #define __M55M1_UART_H__ 11 | 12 | #include "buffer.h" 13 | #include "drv_pdma.h" 14 | 15 | typedef enum { 16 | eUART_HWCONTROL_NONE = 0, 17 | eUART_HWCONTROL_CTS = 1, 18 | eUART_HWCONTROL_RTS = 2, 19 | } E_UART_HWCONTROL; 20 | 21 | typedef struct { 22 | uint32_t u32BaudRate; 23 | uint32_t u32DataWidth; 24 | uint32_t u32Parity; 25 | uint32_t u32StopBits; 26 | E_UART_HWCONTROL eFlowControl; 27 | } UART_InitTypeDef; 28 | 29 | typedef void(*PFN_HDLR_DMA_TX)(void *, int); 30 | typedef void(*PFN_HDLR_DMA_RX)(void *, int); 31 | 32 | 33 | typedef struct { 34 | union { 35 | UART_T *uart; 36 | LPUART_T *lpuart; 37 | } u_uart; 38 | bool bLPUART; 39 | E_PDMAUsage dma_usage; 40 | int dma_chn_id_tx; 41 | int dma_chn_id_rx; 42 | uint32_t event; 43 | uint32_t hdlr_async; 44 | PFN_HDLR_DMA_TX hdlr_dma_tx; 45 | PFN_HDLR_DMA_RX hdlr_dma_rx; 46 | struct buffer_s tx_buff; /**< Tx buffer */ 47 | struct buffer_s rx_buff; /**< Rx buffer */ 48 | } uart_t; 49 | 50 | 51 | int32_t UART_Init( 52 | uart_t *psObj, 53 | UART_InitTypeDef *psInitDef, 54 | uint32_t IRQHandler 55 | ); 56 | 57 | void UART_Final(uart_t *psObj); 58 | 59 | void Handle_UART_Irq(UART_T *uart); 60 | void Handle_LPUART_Irq(LPUART_T *lpuart); 61 | 62 | int32_t UART_DMA_TXRX_Enable( 63 | uart_t *psObj, 64 | PFN_HDLR_DMA_TX pfnHandlerDMATx, 65 | PFN_HDLR_DMA_RX pfnHandlerDMARx 66 | ); 67 | 68 | int32_t UART_DMA_TXRX_Disable( 69 | uart_t *psObj 70 | ); 71 | 72 | int32_t UART_DMA_RX_Start( 73 | uart_t *psObj, 74 | uint8_t *pu8DestBuf, 75 | int32_t i32TriggerLen 76 | ); 77 | 78 | int32_t UART_DMA_RX_Stop( 79 | uart_t *psObj 80 | ); 81 | 82 | int32_t UART_DMA_TX_Start( 83 | uart_t *psObj, 84 | uint8_t *pu8SrcBuf, 85 | int32_t i32TriggerLen 86 | ); 87 | 88 | int32_t UART_DMA_TX_Stop( 89 | uart_t *psObj 90 | ); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /M5531/hal/M5531_PWM.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_PWM.h 3 | * @version V1.00 4 | * @brief M5531 pWM HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_PWM_H__ 10 | #define __M5531_PWM_H__ 11 | 12 | typedef enum { 13 | eCAPTURE_RISING_LATCH = 1, 14 | eCAPTURE_FALLING_LATCH, 15 | eCAPTURE_RISING_FALLING_LATCH, 16 | } E_CAPTURE_EDGE_LATCH_TYPE; 17 | 18 | typedef void (*PFN_CAPTURE_INT_HANDLER)(void *obj, uint32_t u32ChannelGroup); 19 | 20 | typedef struct { 21 | union { 22 | BPWM_T *bpwm; 23 | EPWM_T *epwm; 24 | } u_pwm; 25 | bool bEPWM; 26 | PFN_CAPTURE_INT_HANDLER pfnCaptureHandler; 27 | } pwm_t; 28 | 29 | int32_t PWM_Init( 30 | pwm_t *psPWMObj 31 | ); 32 | 33 | void PWM_Final( 34 | pwm_t *psPWMObj 35 | ); 36 | 37 | int32_t PWM_TriggerOutputChannel( 38 | pwm_t *psPWMObj, 39 | uint32_t u32Channel, 40 | bool bComplementary, //Complentary support. Only for EPWM 41 | uint32_t u32ComplementaryChannel, 42 | uint32_t u32Freq, 43 | uint32_t u32Duty 44 | ); 45 | 46 | int32_t PWM_StopOutputChannel( 47 | pwm_t *psPWMObj, 48 | uint32_t u32Channel 49 | ); 50 | 51 | int32_t PWM_TriggerCaptureChannel( 52 | pwm_t *psPWMObj, 53 | uint32_t u32Channel, 54 | uint32_t u32Freq, 55 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 56 | ); 57 | 58 | int32_t PWM_StopCaptureChannel( 59 | pwm_t *psPWMObj, 60 | uint32_t u32Channel, 61 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 62 | ); 63 | 64 | int32_t PWM_CaptureEnableInt( 65 | pwm_t *psPWMObj, 66 | uint32_t u32Channel, 67 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge, 68 | PFN_CAPTURE_INT_HANDLER pfnHandler 69 | ); 70 | 71 | int32_t PWM_CaptureDisableInt( 72 | pwm_t *psPWMObj, 73 | uint32_t u32Channel, 74 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 75 | ); 76 | 77 | int32_t PWM_CaptureClearInt( 78 | pwm_t *psPWMObj, 79 | uint32_t u32Channel, 80 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 81 | ); 82 | 83 | int32_t PWM_ChangeChannelDuty( 84 | pwm_t *psPWMObj, 85 | uint32_t u32Channel, 86 | uint32_t u32Duty 87 | ); 88 | 89 | void Handle_BPWM_Irq(BPWM_T *bpwm); 90 | void Handle_EPWM_Irq(EPWM_T *epwm, uint32_t u32ChannGroup); 91 | 92 | 93 | #endif 94 | 95 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_PWM.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_PWM.h 3 | * @version V1.00 4 | * @brief M55M1 I2C HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_PWM_H__ 10 | #define __M55M1_PWM_H__ 11 | 12 | typedef enum { 13 | eCAPTURE_RISING_LATCH = 1, 14 | eCAPTURE_FALLING_LATCH, 15 | eCAPTURE_RISING_FALLING_LATCH, 16 | } E_CAPTURE_EDGE_LATCH_TYPE; 17 | 18 | typedef void (*PFN_CAPTURE_INT_HANDLER)(void *obj, uint32_t u32ChannelGroup); 19 | 20 | typedef struct { 21 | union { 22 | BPWM_T *bpwm; 23 | EPWM_T *epwm; 24 | } u_pwm; 25 | bool bEPWM; 26 | PFN_CAPTURE_INT_HANDLER pfnCaptureHandler; 27 | } pwm_t; 28 | 29 | int32_t PWM_Init( 30 | pwm_t *psPWMObj 31 | ); 32 | 33 | void PWM_Final( 34 | pwm_t *psPWMObj 35 | ); 36 | 37 | int32_t PWM_TriggerOutputChannel( 38 | pwm_t *psPWMObj, 39 | uint32_t u32Channel, 40 | bool bComplementary, //Complentary support. Only for EPWM 41 | uint32_t u32ComplementaryChannel, 42 | uint32_t u32Freq, 43 | uint32_t u32Duty 44 | ); 45 | 46 | int32_t PWM_StopOutputChannel( 47 | pwm_t *psPWMObj, 48 | uint32_t u32Channel 49 | ); 50 | 51 | int32_t PWM_TriggerCaptureChannel( 52 | pwm_t *psPWMObj, 53 | uint32_t u32Channel, 54 | uint32_t u32Freq, 55 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 56 | ); 57 | 58 | int32_t PWM_StopCaptureChannel( 59 | pwm_t *psPWMObj, 60 | uint32_t u32Channel, 61 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 62 | ); 63 | 64 | int32_t PWM_CaptureEnableInt( 65 | pwm_t *psPWMObj, 66 | uint32_t u32Channel, 67 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge, 68 | PFN_CAPTURE_INT_HANDLER pfnHandler 69 | ); 70 | 71 | int32_t PWM_CaptureDisableInt( 72 | pwm_t *psPWMObj, 73 | uint32_t u32Channel, 74 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 75 | ); 76 | 77 | int32_t PWM_CaptureClearInt( 78 | pwm_t *psPWMObj, 79 | uint32_t u32Channel, 80 | E_CAPTURE_EDGE_LATCH_TYPE eCaptureEdge 81 | ); 82 | 83 | int32_t PWM_ChangeChannelDuty( 84 | pwm_t *psPWMObj, 85 | uint32_t u32Channel, 86 | uint32_t u32Duty 87 | ); 88 | 89 | void Handle_BPWM_Irq(BPWM_T *bpwm); 90 | void Handle_EPWM_Irq(EPWM_T *epwm, uint32_t u32ChannGroup); 91 | 92 | 93 | #endif 94 | 95 | -------------------------------------------------------------------------------- /M5531/mods/pybirq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M5531_PYBIRQ_H 27 | #define MICROPY_INCLUDED_M5531_PYBIRQ_H 28 | 29 | #include "py/obj.h" 30 | 31 | #if 0 32 | // Use this macro together with NVIC_SetPriority to indicate that an IRQn is non-negative, 33 | // which helps the compiler optimise the resulting inline function. 34 | #define IRQn_NONNEG(pri) ((pri) & 0x7f) 35 | 36 | // these states correspond to values from query_irq, enable_irq and disable_irq 37 | #define IRQ_STATE_DISABLED (0x00000001) 38 | #define IRQ_STATE_ENABLED (0x00000000) 39 | 40 | // Enable this to get a count for the number of times each irq handler is called, 41 | // accessible via pyb.irq_stats(). 42 | #define IRQ_ENABLE_STATS (0) 43 | 44 | #if IRQ_ENABLE_STATS 45 | extern uint32_t irq_stats[TOTAL_IRQn_CNT + 1]; 46 | #define IRQ_ENTER(irq) ++irq_stats[irq] 47 | #define IRQ_EXIT(irq) 48 | #else 49 | #define IRQ_ENTER(irq) 50 | #define IRQ_EXIT(irq) 51 | #endif 52 | 53 | 54 | static inline mp_uint_t query_irq(void) 55 | { 56 | return __get_PRIMASK(); 57 | } 58 | #endif 59 | 60 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_wfi_obj); 61 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_disable_irq_obj); 62 | MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj); 63 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj); 64 | 65 | #endif // MICROPY_INCLUDED_M5531_IRQ_H 66 | -------------------------------------------------------------------------------- /M55M1/mods/pybirq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_M55M1_PYBIRQ_H 27 | #define MICROPY_INCLUDED_M55M1_PYBIRQ_H 28 | 29 | #include "py/obj.h" 30 | 31 | #if 0 32 | // Use this macro together with NVIC_SetPriority to indicate that an IRQn is non-negative, 33 | // which helps the compiler optimise the resulting inline function. 34 | #define IRQn_NONNEG(pri) ((pri) & 0x7f) 35 | 36 | // these states correspond to values from query_irq, enable_irq and disable_irq 37 | #define IRQ_STATE_DISABLED (0x00000001) 38 | #define IRQ_STATE_ENABLED (0x00000000) 39 | 40 | // Enable this to get a count for the number of times each irq handler is called, 41 | // accessible via pyb.irq_stats(). 42 | #define IRQ_ENABLE_STATS (0) 43 | 44 | #if IRQ_ENABLE_STATS 45 | extern uint32_t irq_stats[TOTAL_IRQn_CNT + 1]; 46 | #define IRQ_ENTER(irq) ++irq_stats[irq] 47 | #define IRQ_EXIT(irq) 48 | #else 49 | #define IRQ_ENTER(irq) 50 | #define IRQ_EXIT(irq) 51 | #endif 52 | 53 | 54 | static inline mp_uint_t query_irq(void) 55 | { 56 | return __get_PRIMASK(); 57 | } 58 | #endif 59 | 60 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_wfi_obj); 61 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_disable_irq_obj); 62 | MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj); 63 | MP_DECLARE_CONST_FUN_OBJ_0(pyb_irq_stats_obj); 64 | 65 | #endif // MICROPY_INCLUDED_M55M1_IRQ_H 66 | -------------------------------------------------------------------------------- /M5531/hal/M5531_CANFD.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_CANFD.h 3 | * @version V1.00 4 | * @brief M5531 CANFD HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_CANFD_H__ 10 | #define __M5531_CANFD_H__ 11 | 12 | typedef void (*PFN_STATUS_INT_HANDLER)(void *obj, uint32_t u32Status); 13 | 14 | typedef struct { 15 | CANFD_T *canfd; 16 | int32_t i32FIFOIdx; //assigned >=0 17 | uint32_t u32StdFilterIdx; //filter index. start from 0; 18 | uint32_t u32ExtFilterIdx; //filter index. start from 0; 19 | PFN_STATUS_INT_HANDLER pfnStatusHandler; 20 | } canfd_t; 21 | 22 | typedef struct { 23 | bool FDMode; //can/canfd mode 24 | bool LoopBack; //loopback 25 | uint32_t NormalBitRate; //Normal bit rate 26 | uint32_t DataBitRate; //Data bit rate 27 | } CANFD_InitTypeDef; 28 | 29 | //Init CANFD object 30 | int32_t CANFD_Init( 31 | canfd_t *psCANFDObj, 32 | CANFD_InitTypeDef *psInitDef 33 | ); 34 | 35 | //Final CANFD object 36 | void CANFD_Final( 37 | canfd_t *psCANFDObj 38 | ); 39 | 40 | //Restart CANFD object. Force a software restart of the controller, to allow transmission after a bus error 41 | void CANFD_Restart( 42 | canfd_t *psCANFDObj 43 | ); 44 | 45 | //Return amount of data in receive fifo 46 | uint32_t CANFD_AmountDataRecv( 47 | canfd_t *psCANFDObj 48 | ); 49 | 50 | //Get available message object index. available: 0~31 51 | int32_t CANFD_GetFreeMsgObjIdx( 52 | canfd_t *psCANFDObj, 53 | uint32_t u32Timeout //millisecond 54 | ); 55 | 56 | //Set receive filter 57 | int32_t CANFD_SetRecvFilter( 58 | canfd_t *psCANFDObj, 59 | E_CANFD_ID_TYPE eIDType, 60 | uint32_t u32ID, 61 | uint32_t u32Mask 62 | ); 63 | 64 | //Receive message with timeout 65 | int32_t CANFD_RecvMsg( 66 | canfd_t *psCANFDObj, 67 | CANFD_FD_MSG_T *psMsgFrame, 68 | uint32_t u32Timeout //millisecond 69 | ); 70 | 71 | //Enable status interrupt 72 | int32_t CANFD_EnableStatusInt( 73 | canfd_t *psCANFDObj, 74 | PFN_STATUS_INT_HANDLER pfnHandler, 75 | uint32_t u32INTMask 76 | ); 77 | 78 | //Disable status interrupt 79 | void CANFD_DisableStatusInt( 80 | canfd_t *psCANFDObj, 81 | uint32_t u32INTMask 82 | ); 83 | 84 | /** 85 | * Handle the CANFD interrupt 86 | * @param[in] obj The CANFD peripheral that generated the interrupt 87 | * @return 88 | */ 89 | 90 | void Handle_CANFD_Irq(CANFD_T *canfd, uint32_t u32Status); 91 | 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_CANFD.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_CANFD.h 3 | * @version V1.00 4 | * @brief M55M1 CANFD HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_CANFD_H__ 10 | #define __M55M1_CANFD_H__ 11 | 12 | typedef void (*PFN_STATUS_INT_HANDLER)(void *obj, uint32_t u32Status); 13 | 14 | typedef struct { 15 | CANFD_T *canfd; 16 | int32_t i32FIFOIdx; //assigned >=0 17 | uint32_t u32StdFilterIdx; //filter index. start from 0; 18 | uint32_t u32ExtFilterIdx; //filter index. start from 0; 19 | PFN_STATUS_INT_HANDLER pfnStatusHandler; 20 | } canfd_t; 21 | 22 | typedef struct { 23 | bool FDMode; //can/canfd mode 24 | bool LoopBack; //loopback 25 | uint32_t NormalBitRate; //Normal bit rate 26 | uint32_t DataBitRate; //Data bit rate 27 | } CANFD_InitTypeDef; 28 | 29 | //Init CANFD object 30 | int32_t CANFD_Init( 31 | canfd_t *psCANFDObj, 32 | CANFD_InitTypeDef *psInitDef 33 | ); 34 | 35 | //Final CANFD object 36 | void CANFD_Final( 37 | canfd_t *psCANFDObj 38 | ); 39 | 40 | //Restart CANFD object. Force a software restart of the controller, to allow transmission after a bus error 41 | void CANFD_Restart( 42 | canfd_t *psCANFDObj 43 | ); 44 | 45 | //Return amount of data in receive fifo 46 | uint32_t CANFD_AmountDataRecv( 47 | canfd_t *psCANFDObj 48 | ); 49 | 50 | //Get available message object index. available: 0~31 51 | int32_t CANFD_GetFreeMsgObjIdx( 52 | canfd_t *psCANFDObj, 53 | uint32_t u32Timeout //millisecond 54 | ); 55 | 56 | //Set receive filter 57 | int32_t CANFD_SetRecvFilter( 58 | canfd_t *psCANFDObj, 59 | E_CANFD_ID_TYPE eIDType, 60 | uint32_t u32ID, 61 | uint32_t u32Mask 62 | ); 63 | 64 | //Receive message with timeout 65 | int32_t CANFD_RecvMsg( 66 | canfd_t *psCANFDObj, 67 | CANFD_FD_MSG_T *psMsgFrame, 68 | uint32_t u32Timeout //millisecond 69 | ); 70 | 71 | //Enable status interrupt 72 | int32_t CANFD_EnableStatusInt( 73 | canfd_t *psCANFDObj, 74 | PFN_STATUS_INT_HANDLER pfnHandler, 75 | uint32_t u32INTMask 76 | ); 77 | 78 | //Disable status interrupt 79 | void CANFD_DisableStatusInt( 80 | canfd_t *psCANFDObj, 81 | uint32_t u32INTMask 82 | ); 83 | 84 | /** 85 | * Handle the CANFD interrupt 86 | * @param[in] obj The CANFD peripheral that generated the interrupt 87 | * @return 88 | */ 89 | 90 | void Handle_CANFD_Irq(CANFD_T *canfd, uint32_t u32Status); 91 | 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /M5531/gccollect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/obj.h" 31 | #include "py/gc.h" 32 | #include "py/mpthread.h" 33 | #include "py/mpstate.h" 34 | #include "gccollect.h" 35 | 36 | mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs); 37 | 38 | extern const volatile unsigned int __StackTop; 39 | 40 | void gc_collect(void) 41 | { 42 | // start the GC 43 | gc_collect_start(); 44 | 45 | // get the registers and the sp 46 | mp_uint_t regs[10]; 47 | mp_uint_t sp = gc_helper_get_regs_and_sp(regs); 48 | 49 | // trace the stack, including the registers (since they live on the stack in this function) 50 | #if MICROPY_PY_THREAD 51 | gc_collect_root((void**)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); 52 | #else 53 | gc_collect_root((void**)sp, ((uint32_t)&__StackTop - sp) / sizeof(uint32_t)); 54 | #endif 55 | 56 | // trace root pointers from any threads 57 | #if MICROPY_PY_THREAD 58 | mp_thread_gc_others(); 59 | #endif 60 | 61 | // end the GC 62 | gc_collect_end(); 63 | 64 | #if 0 65 | // print GC info 66 | uint32_t ticks = mp_hal_ticks_us() - start; 67 | gc_info_t info; 68 | gc_info(&info); 69 | printf("GC@%lu %lums\n", start, ticks); 70 | printf(" " UINT_FMT " total\n", info.total); 71 | printf(" " UINT_FMT " : " UINT_FMT "\n", info.used, info.free); 72 | printf(" 1=" UINT_FMT " 2=" UINT_FMT " m=" UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block); 73 | #endif 74 | 75 | } 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /M55M1/gccollect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/obj.h" 31 | #include "py/gc.h" 32 | #include "py/mpthread.h" 33 | #include "py/mpstate.h" 34 | #include "gccollect.h" 35 | 36 | mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs); 37 | 38 | extern const volatile unsigned int __StackTop; 39 | 40 | void gc_collect(void) 41 | { 42 | // start the GC 43 | gc_collect_start(); 44 | 45 | // get the registers and the sp 46 | mp_uint_t regs[10]; 47 | mp_uint_t sp = gc_helper_get_regs_and_sp(regs); 48 | 49 | // trace the stack, including the registers (since they live on the stack in this function) 50 | #if MICROPY_PY_THREAD 51 | gc_collect_root((void**)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); 52 | #else 53 | gc_collect_root((void**)sp, ((uint32_t)&__StackTop - sp) / sizeof(uint32_t)); 54 | #endif 55 | 56 | // trace root pointers from any threads 57 | #if MICROPY_PY_THREAD 58 | mp_thread_gc_others(); 59 | #endif 60 | 61 | // end the GC 62 | gc_collect_end(); 63 | 64 | #if 0 65 | // print GC info 66 | uint32_t ticks = mp_hal_ticks_us() - start; 67 | gc_info_t info; 68 | gc_info(&info); 69 | printf("GC@%lu %lums\n", start, ticks); 70 | printf(" " UINT_FMT " total\n", info.total); 71 | printf(" " UINT_FMT " : " UINT_FMT "\n", info.used, info.free); 72 | printf(" 1=" UINT_FMT " 2=" UINT_FMT " m=" UINT_FMT "\n", info.num_1block, info.num_2block, info.max_block); 73 | #endif 74 | 75 | } 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /M5531/mods/modtime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013-2023 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "shared/timeutils/timeutils.h" 29 | #include "rtc.h" 30 | 31 | // This file is never compiled standalone, it's included directly from 32 | // extmod/modtime.c via MICROPY_PY_TIME_INCLUDEFILE. 33 | 34 | static bool bRTCEnabled = false; 35 | 36 | static void EnableRTCClock(void) 37 | { 38 | CLK_EnableModuleClock(RTC0_MODULE); 39 | /* Set LXT as RTC clock source */ 40 | RTC_SetClockSource(RTC_CLOCK_SOURCE_LXT); 41 | 42 | RTC_Open(NULL); 43 | bRTCEnabled = true; 44 | } 45 | 46 | // Return the localtime as an 8-tuple. 47 | static mp_obj_t mp_time_localtime_get(void) 48 | { 49 | // get current date and time 50 | // note: need to call get time then get date to correctly access the registers 51 | S_RTC_TIME_DATA_T sRTCTimeData; 52 | 53 | if(!bRTCEnabled) 54 | EnableRTCClock(); 55 | 56 | RTC_GetDateAndTime(&sRTCTimeData); 57 | mp_obj_t tuple[8]; 58 | 59 | tuple[0] = mp_obj_new_int(sRTCTimeData.u32Year); 60 | tuple[1] = mp_obj_new_int(sRTCTimeData.u32Month); 61 | tuple[2] = mp_obj_new_int(sRTCTimeData.u32Day); 62 | if(sRTCTimeData.u32DayOfWeek == RTC_SUNDAY) 63 | tuple[3] = mp_obj_new_int(7); 64 | else 65 | tuple[3] = mp_obj_new_int(sRTCTimeData.u32DayOfWeek); 66 | tuple[4] = mp_obj_new_int(sRTCTimeData.u32Hour); 67 | tuple[5] = mp_obj_new_int(sRTCTimeData.u32Minute); 68 | tuple[6] = mp_obj_new_int(sRTCTimeData.u32Second); 69 | tuple[7] = mp_obj_new_int(0); 70 | 71 | return mp_obj_new_tuple(8, tuple); 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /M55M1/mods/modtime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013-2023 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "shared/timeutils/timeutils.h" 29 | #include "rtc.h" 30 | 31 | // This file is never compiled standalone, it's included directly from 32 | // extmod/modtime.c via MICROPY_PY_TIME_INCLUDEFILE. 33 | 34 | static bool bRTCEnabled = false; 35 | 36 | static void EnableRTCClock(void) 37 | { 38 | CLK_EnableModuleClock(RTC0_MODULE); 39 | /* Set LXT as RTC clock source */ 40 | RTC_SetClockSource(RTC_CLOCK_SOURCE_LXT); 41 | 42 | RTC_Open(NULL); 43 | bRTCEnabled = true; 44 | } 45 | 46 | // Return the localtime as an 8-tuple. 47 | static mp_obj_t mp_time_localtime_get(void) 48 | { 49 | // get current date and time 50 | // note: need to call get time then get date to correctly access the registers 51 | S_RTC_TIME_DATA_T sRTCTimeData; 52 | 53 | if(!bRTCEnabled) 54 | EnableRTCClock(); 55 | 56 | RTC_GetDateAndTime(&sRTCTimeData); 57 | mp_obj_t tuple[8]; 58 | 59 | tuple[0] = mp_obj_new_int(sRTCTimeData.u32Year); 60 | tuple[1] = mp_obj_new_int(sRTCTimeData.u32Month); 61 | tuple[2] = mp_obj_new_int(sRTCTimeData.u32Day); 62 | if(sRTCTimeData.u32DayOfWeek == RTC_SUNDAY) 63 | tuple[3] = mp_obj_new_int(7); 64 | else 65 | tuple[3] = mp_obj_new_int(sRTCTimeData.u32DayOfWeek); 66 | tuple[4] = mp_obj_new_int(sRTCTimeData.u32Hour); 67 | tuple[5] = mp_obj_new_int(sRTCTimeData.u32Minute); 68 | tuple[6] = mp_obj_new_int(sRTCTimeData.u32Second); 69 | tuple[7] = mp_obj_new_int(0); 70 | 71 | return mp_obj_new_tuple(8, tuple); 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /M5531/hal/M5531_RTC.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_RTC.c 3 | * @version V0.01 4 | * @brief M5531 series RTC HAL source file 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #include "NuMicro.h" 11 | 12 | #include "M5531_RTC.h" 13 | #include "nu_modutil.h" 14 | 15 | struct nu_rtc_var { 16 | rtc_t * psObj; 17 | }; 18 | 19 | static struct nu_rtc_var rtc0_var = { 20 | .psObj = NULL, 21 | }; 22 | 23 | static const struct nu_modinit_s rtc_modinit_tab[] = { 24 | {(uint32_t)RTC, RTC0_MODULE, MODULE_NoMsk, MODULE_NoMsk, SYS_RTC0RST, RTC_IRQn, &rtc0_var}, 25 | 26 | {0, 0, 0, 0, 0, (IRQn_Type) 0, NULL} 27 | }; 28 | 29 | int32_t RTC_Init( 30 | rtc_t *psObj, 31 | RTC_InitTypeDef *psInitDef 32 | ) 33 | { 34 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 35 | 36 | if(modinit == NULL) 37 | return -1; 38 | 39 | struct nu_rtc_var *var = (struct nu_rtc_var *) modinit->var; 40 | 41 | // Reset this module 42 | SYS_ResetModule(modinit->rsetidx); 43 | /* Set LXT as RTC clock source */ 44 | RTC_SetClockSource(RTC_CLOCK_SOURCE_LXT); 45 | // Enable IP clock 46 | CLK_EnableModuleClock(modinit->clkidx); 47 | var->psObj = psObj; 48 | return RTC_Open(psInitDef->psRTCTimeDate); 49 | } 50 | 51 | int32_t RTC_EnableIntFlag( 52 | rtc_t *psObj, 53 | uint32_t u32IntFlagMask, 54 | PFN_RTC_INT_HANDLER pfnHandler 55 | ) 56 | { 57 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 58 | 59 | if(modinit == NULL) 60 | return -1; 61 | 62 | psObj->pfnRTCIntHandler = pfnHandler; 63 | 64 | /* Enable RTC interrupt */ 65 | RTC_EnableInt(u32IntFlagMask); 66 | 67 | /* Enable RTC NVIC */ 68 | NVIC_EnableIRQ(modinit->irq_n); 69 | 70 | return 0; 71 | } 72 | 73 | int32_t RTC_DisableIntFlag( 74 | rtc_t *psObj, 75 | uint32_t u32IntFlagMask 76 | ) 77 | { 78 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 79 | 80 | if(modinit == NULL) 81 | return -1; 82 | 83 | /* Disable RTC NVIC */ 84 | NVIC_DisableIRQ(modinit->irq_n); 85 | /* Disable RTC interrupt */ 86 | RTC_DisableInt(u32IntFlagMask); 87 | psObj->pfnRTCIntHandler = NULL; 88 | 89 | return 0; 90 | } 91 | 92 | void Handle_RTC_Irq(RTC_T *rtc) 93 | { 94 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)rtc, rtc_modinit_tab); 95 | struct nu_rtc_var *var = NULL; 96 | rtc_t *psRTCObj = NULL; 97 | 98 | if(modinit) { 99 | var = (struct nu_rtc_var *) modinit->var; 100 | psRTCObj = var->psObj; 101 | } 102 | 103 | if((psRTCObj) && (psRTCObj->pfnRTCIntHandler)) { 104 | psRTCObj->pfnRTCIntHandler(psRTCObj); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_RTC.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_RTC.c 3 | * @version V0.01 4 | * @brief M55M1 series RTC HAL source file 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | 10 | #include "NuMicro.h" 11 | 12 | #include "M55M1_RTC.h" 13 | #include "nu_modutil.h" 14 | 15 | struct nu_rtc_var { 16 | rtc_t * psObj; 17 | }; 18 | 19 | static struct nu_rtc_var rtc0_var = { 20 | .psObj = NULL, 21 | }; 22 | 23 | static const struct nu_modinit_s rtc_modinit_tab[] = { 24 | {(uint32_t)RTC, RTC0_MODULE, MODULE_NoMsk, MODULE_NoMsk, SYS_RTC0RST, RTC_IRQn, &rtc0_var}, 25 | 26 | {0, 0, 0, 0, 0, (IRQn_Type) 0, NULL} 27 | }; 28 | 29 | int32_t RTC_Init( 30 | rtc_t *psObj, 31 | RTC_InitTypeDef *psInitDef 32 | ) 33 | { 34 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 35 | 36 | if(modinit == NULL) 37 | return -1; 38 | 39 | struct nu_rtc_var *var = (struct nu_rtc_var *) modinit->var; 40 | 41 | // Reset this module 42 | SYS_ResetModule(modinit->rsetidx); 43 | /* Set LXT as RTC clock source */ 44 | RTC_SetClockSource(RTC_CLOCK_SOURCE_LXT); 45 | // Enable IP clock 46 | CLK_EnableModuleClock(modinit->clkidx); 47 | var->psObj = psObj; 48 | return RTC_Open(psInitDef->psRTCTimeDate); 49 | } 50 | 51 | int32_t RTC_EnableIntFlag( 52 | rtc_t *psObj, 53 | uint32_t u32IntFlagMask, 54 | PFN_RTC_INT_HANDLER pfnHandler 55 | ) 56 | { 57 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 58 | 59 | if(modinit == NULL) 60 | return -1; 61 | 62 | psObj->pfnRTCIntHandler = pfnHandler; 63 | 64 | /* Enable RTC interrupt */ 65 | RTC_EnableInt(u32IntFlagMask); 66 | 67 | /* Enable RTC NVIC */ 68 | NVIC_EnableIRQ(modinit->irq_n); 69 | 70 | return 0; 71 | } 72 | 73 | int32_t RTC_DisableIntFlag( 74 | rtc_t *psObj, 75 | uint32_t u32IntFlagMask 76 | ) 77 | { 78 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)psObj->rtc, rtc_modinit_tab); 79 | 80 | if(modinit == NULL) 81 | return -1; 82 | 83 | /* Disable RTC NVIC */ 84 | NVIC_DisableIRQ(modinit->irq_n); 85 | /* Disable RTC interrupt */ 86 | RTC_DisableInt(u32IntFlagMask); 87 | psObj->pfnRTCIntHandler = NULL; 88 | 89 | return 0; 90 | } 91 | 92 | void Handle_RTC_Irq(RTC_T *rtc) 93 | { 94 | const struct nu_modinit_s *modinit = get_modinit((uint32_t)rtc, rtc_modinit_tab); 95 | struct nu_rtc_var *var = NULL; 96 | rtc_t *psRTCObj = NULL; 97 | 98 | if(modinit) { 99 | var = (struct nu_rtc_var *) modinit->var; 100 | psRTCObj = var->psObj; 101 | } 102 | 103 | if((psRTCObj) && (psRTCObj->pfnRTCIntHandler)) { 104 | psRTCObj->pfnRTCIntHandler(psRTCObj); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /M5531/mods/pybirq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "py/mphal.h" 29 | #include "pybirq.h" 30 | /// \moduleref pyb 31 | 32 | #include "hal/M5531_IRQ.h" 33 | 34 | /// \function wfi() 35 | /// Wait for an interrupt. 36 | /// This executies a `wfi` instruction which reduces power consumption 37 | /// of the MCU until an interrupt occurs, at which point execution continues. 38 | static mp_obj_t pyb_wfi(void) 39 | { 40 | __WFI(); 41 | return mp_const_none; 42 | } 43 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi); 44 | 45 | /// \function disable_irq() 46 | /// Disable interrupt requests. 47 | /// Returns the previous IRQ state: `False`/`True` for disabled/enabled IRQs 48 | /// respectively. This return value can be passed to enable_irq to restore 49 | /// the IRQ to its original state. 50 | static mp_obj_t pyb_disable_irq(void) 51 | { 52 | return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED); 53 | } 54 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq); 55 | 56 | /// \function enable_irq(state=True) 57 | /// Enable interrupt requests. 58 | /// If `state` is `True` (the default value) then IRQs are enabled. 59 | /// If `state` is `False` then IRQs are disabled. The most common use of 60 | /// this function is to pass it the value returned by `disable_irq` to 61 | /// exit a critical section. 62 | static mp_obj_t pyb_enable_irq(uint n_args, const mp_obj_t *arg) 63 | { 64 | enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED); 65 | return mp_const_none; 66 | } 67 | MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj, 0, 1, pyb_enable_irq); 68 | 69 | #if IRQ_ENABLE_STATS 70 | // return a memoryview of the irq statistics array 71 | static mp_obj_t pyb_irq_stats(void) 72 | { 73 | return mp_obj_new_memoryview(0x80 | 'I', MP_ARRAY_SIZE(irq_stats), &irq_stats[0]); 74 | } 75 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_irq_stats_obj, pyb_irq_stats); 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /M55M1/mods/pybirq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include "py/obj.h" 28 | #include "py/mphal.h" 29 | #include "pybirq.h" 30 | /// \moduleref pyb 31 | 32 | #include "hal/M55M1_IRQ.h" 33 | 34 | /// \function wfi() 35 | /// Wait for an interrupt. 36 | /// This executies a `wfi` instruction which reduces power consumption 37 | /// of the MCU until an interrupt occurs, at which point execution continues. 38 | static mp_obj_t pyb_wfi(void) 39 | { 40 | __WFI(); 41 | return mp_const_none; 42 | } 43 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi); 44 | 45 | /// \function disable_irq() 46 | /// Disable interrupt requests. 47 | /// Returns the previous IRQ state: `False`/`True` for disabled/enabled IRQs 48 | /// respectively. This return value can be passed to enable_irq to restore 49 | /// the IRQ to its original state. 50 | static mp_obj_t pyb_disable_irq(void) 51 | { 52 | return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED); 53 | } 54 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq); 55 | 56 | /// \function enable_irq(state=True) 57 | /// Enable interrupt requests. 58 | /// If `state` is `True` (the default value) then IRQs are enabled. 59 | /// If `state` is `False` then IRQs are disabled. The most common use of 60 | /// this function is to pass it the value returned by `disable_irq` to 61 | /// exit a critical section. 62 | static mp_obj_t pyb_enable_irq(uint n_args, const mp_obj_t *arg) 63 | { 64 | enable_irq((n_args == 0 || mp_obj_is_true(arg[0])) ? IRQ_STATE_ENABLED : IRQ_STATE_DISABLED); 65 | return mp_const_none; 66 | } 67 | MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_enable_irq_obj, 0, 1, pyb_enable_irq); 68 | 69 | #if IRQ_ENABLE_STATS 70 | // return a memoryview of the irq statistics array 71 | static mp_obj_t pyb_irq_stats(void) 72 | { 73 | return mp_obj_new_memoryview(0x80 | 'I', MP_ARRAY_SIZE(irq_stats), &irq_stats[0]); 74 | } 75 | MP_DEFINE_CONST_FUN_OBJ_0(pyb_irq_stats_obj, pyb_irq_stats); 76 | #endif 77 | 78 | -------------------------------------------------------------------------------- /M5531/hal/M5531_USBD.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_USB.h 3 | * @version V1.00 4 | * @brief M5531 USB HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_USB_H__ 10 | #define __M5531_USB_H__ 11 | 12 | #include 13 | 14 | /* Define the vendor id and product id */ 15 | #define USBD_VID 0x0416 16 | #define USBD_VCP_HID_PID 0xDC00 17 | #define USBD_MSC_PID 0x501F 18 | #define USBD_MSC_VCP_PID 0xDC01 19 | 20 | /* Define Descriptor information */ 21 | #define USBD_SELF_POWERED 0 22 | #define USBD_REMOTE_WAKEUP 0 23 | #define USBD_MAX_POWER 50 /* The unit is in 2mA. ex: 50 * 2mA = 100mA */ 24 | 25 | 26 | typedef enum { 27 | eUSBDEV_MODE_NONE = 0, 28 | eUSBDEV_MODE_HID = 0x01, 29 | eUSBDEV_MODE_VCP = 0x02, 30 | eUSBDEV_MODE_HID_VCP = 0x03, 31 | eUSBDEV_MODE_MSC = 0x04, 32 | eUSBDEV_MODE_MSC_VCP = 0x06, 33 | eUSBDEV_MODE_MSC_WP_VCP = 0x16, //MSC write protect and VCP 34 | } E_USBDEV_MODE; 35 | 36 | typedef struct { 37 | E_USBDEV_MODE eUSBMode; 38 | int bConnected; 39 | } S_USBDEV_STATE; 40 | 41 | typedef int32_t (*PFN_USBDEV_VCPRecvSignal)(uint8_t *pu8Buf, uint32_t u32Size); 42 | 43 | E_USBDEV_MODE USBDEV_GetMode(S_USBDEV_STATE *psUSBDevState); 44 | 45 | S_USBDEV_STATE *USBDEV_Init( 46 | uint16_t u16VID, 47 | uint16_t u16PID, 48 | E_USBDEV_MODE eUSBMode 49 | ); 50 | 51 | S_USBDEV_STATE *USBDEV_UpdateState(void); 52 | 53 | int32_t USBDEV_Start( 54 | S_USBDEV_STATE *psUSBDevState 55 | ); 56 | 57 | void USBDEV_Deinit( 58 | S_USBDEV_STATE *psUSBDevState 59 | ); 60 | 61 | void Handle_USBDEV_Irq( 62 | uint32_t u32IntStatus, 63 | uint32_t u32BusState 64 | ); 65 | 66 | int32_t USBDEV_HIDCanRecv( 67 | S_USBDEV_STATE *psUSBDevState 68 | ); 69 | 70 | int32_t USBDEV_VCPCanRecv( 71 | S_USBDEV_STATE *psUSBDevState 72 | ); 73 | 74 | int32_t USBDEV_HIDRecvData( 75 | uint8_t *pu8DataBuf, 76 | uint32_t u32DataBufLen, 77 | uint32_t u32Timeout, 78 | S_USBDEV_STATE *psUSBDevState 79 | ); 80 | 81 | int32_t USBDEV_VCPRecvData( 82 | uint8_t *pu8DataBuf, 83 | uint32_t u32DataBufLen, 84 | uint32_t u32Timeout, 85 | S_USBDEV_STATE *psUSBDevState 86 | ); 87 | 88 | 89 | int32_t USBDEV_HIDCanSend( 90 | S_USBDEV_STATE *psUSBDevState 91 | ); 92 | 93 | int32_t USBDEV_VCPCanSend( 94 | S_USBDEV_STATE *psUSBDevState 95 | ); 96 | 97 | int32_t USBDEV_HIDSendData( 98 | uint8_t *pu8DataBuf, 99 | uint32_t u32DataBufLen, 100 | uint32_t u32Timeout, 101 | S_USBDEV_STATE *psUSBDevState 102 | ); 103 | 104 | int32_t USBDEV_VCPSendData( 105 | uint8_t *pu8DataBuf, 106 | uint32_t u32DataBufLen, 107 | uint32_t u32Timeout, 108 | S_USBDEV_STATE *psUSBDevState 109 | ); 110 | 111 | 112 | int32_t USBDEV_HIDInReportPacketSize(); 113 | int32_t USBDEV_HIDOutReportPacketSize(); 114 | 115 | void USBDEV_MSCEnDisable( 116 | int32_t i32EnDisable 117 | ); 118 | 119 | int32_t USBDEV_DataBusConnect(void); 120 | 121 | 122 | void USBDEV_VCPRegisterSingal( 123 | PFN_USBDEV_VCPRecvSignal pfnSignal 124 | ); 125 | 126 | #endif 127 | 128 | 129 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_USBD.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_USB.h 3 | * @version V1.00 4 | * @brief M55M1 USB HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_USB_H__ 10 | #define __M55M1_USB_H__ 11 | 12 | #include 13 | 14 | /* Define the vendor id and product id */ 15 | #define USBD_VID 0x0416 16 | #define USBD_VCP_HID_PID 0xDC00 17 | #define USBD_MSC_PID 0x501F 18 | #define USBD_MSC_VCP_PID 0xDC01 19 | 20 | /* Define Descriptor information */ 21 | #define USBD_SELF_POWERED 0 22 | #define USBD_REMOTE_WAKEUP 0 23 | #define USBD_MAX_POWER 50 /* The unit is in 2mA. ex: 50 * 2mA = 100mA */ 24 | 25 | 26 | typedef enum { 27 | eUSBDEV_MODE_NONE = 0, 28 | eUSBDEV_MODE_HID = 0x01, 29 | eUSBDEV_MODE_VCP = 0x02, 30 | eUSBDEV_MODE_HID_VCP = 0x03, 31 | eUSBDEV_MODE_MSC = 0x04, 32 | eUSBDEV_MODE_MSC_VCP = 0x06, 33 | eUSBDEV_MODE_MSC_WP_VCP = 0x16, //MSC write protect and VCP 34 | } E_USBDEV_MODE; 35 | 36 | typedef struct { 37 | E_USBDEV_MODE eUSBMode; 38 | int bConnected; 39 | } S_USBDEV_STATE; 40 | 41 | typedef int32_t (*PFN_USBDEV_VCPRecvSignal)(uint8_t *pu8Buf, uint32_t u32Size); 42 | 43 | E_USBDEV_MODE USBDEV_GetMode(S_USBDEV_STATE *psUSBDevState); 44 | 45 | S_USBDEV_STATE *USBDEV_Init( 46 | uint16_t u16VID, 47 | uint16_t u16PID, 48 | E_USBDEV_MODE eUSBMode 49 | ); 50 | 51 | S_USBDEV_STATE *USBDEV_UpdateState(void); 52 | 53 | int32_t USBDEV_Start( 54 | S_USBDEV_STATE *psUSBDevState 55 | ); 56 | 57 | void USBDEV_Deinit( 58 | S_USBDEV_STATE *psUSBDevState 59 | ); 60 | 61 | void Handle_USBDEV_Irq( 62 | uint32_t u32IntStatus, 63 | uint32_t u32BusState 64 | ); 65 | 66 | int32_t USBDEV_HIDCanRecv( 67 | S_USBDEV_STATE *psUSBDevState 68 | ); 69 | 70 | int32_t USBDEV_VCPCanRecv( 71 | S_USBDEV_STATE *psUSBDevState 72 | ); 73 | 74 | int32_t USBDEV_HIDRecvData( 75 | uint8_t *pu8DataBuf, 76 | uint32_t u32DataBufLen, 77 | uint32_t u32Timeout, 78 | S_USBDEV_STATE *psUSBDevState 79 | ); 80 | 81 | int32_t USBDEV_VCPRecvData( 82 | uint8_t *pu8DataBuf, 83 | uint32_t u32DataBufLen, 84 | uint32_t u32Timeout, 85 | S_USBDEV_STATE *psUSBDevState 86 | ); 87 | 88 | 89 | int32_t USBDEV_HIDCanSend( 90 | S_USBDEV_STATE *psUSBDevState 91 | ); 92 | 93 | int32_t USBDEV_VCPCanSend( 94 | S_USBDEV_STATE *psUSBDevState 95 | ); 96 | 97 | int32_t USBDEV_HIDSendData( 98 | uint8_t *pu8DataBuf, 99 | uint32_t u32DataBufLen, 100 | uint32_t u32Timeout, 101 | S_USBDEV_STATE *psUSBDevState 102 | ); 103 | 104 | int32_t USBDEV_VCPSendData( 105 | uint8_t *pu8DataBuf, 106 | uint32_t u32DataBufLen, 107 | uint32_t u32Timeout, 108 | S_USBDEV_STATE *psUSBDevState 109 | ); 110 | 111 | 112 | int32_t USBDEV_HIDInReportPacketSize(); 113 | int32_t USBDEV_HIDOutReportPacketSize(); 114 | 115 | void USBDEV_MSCEnDisable( 116 | int32_t i32EnDisable 117 | ); 118 | 119 | int32_t USBDEV_DataBusConnect(void); 120 | 121 | 122 | void USBDEV_VCPRegisterSingal( 123 | PFN_USBDEV_VCPRecvSignal pfnSignal 124 | ); 125 | 126 | #endif 127 | 128 | 129 | -------------------------------------------------------------------------------- /M5531/mods/modmachine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013-2015 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/runtime.h" 31 | #include "py/mphal.h" 32 | #include "extmod/modmachine.h" 33 | 34 | #include "classUART.h" 35 | #include "classI2C.h" 36 | #include "classSPI.h" 37 | #include "classCAN.h" 38 | #include "classPWM.h" 39 | #include "classADC.h" 40 | #include "classTimer.h" 41 | #include "classDAC.h" 42 | #include "classRTC.h" 43 | #include "classWDT.h" 44 | 45 | 46 | // This file is never compiled standalone, it's included directly from 47 | // extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE. 48 | 49 | #if MICROPY_HW_ENABLE_CAN 50 | #define MACHINE_CAN_CLASS { MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&machine_can_type) }, 51 | #else 52 | #define MACHINE_CAN_CLASS 53 | #endif 54 | 55 | #if MICROPY_HW_ENABLE_HW_EADC 56 | #define MACHINE_ADC_CLASS { MP_ROM_QSTR(MP_QSTR_ADCALL), MP_ROM_PTR(&machine_adc_all_type) }, \ 57 | { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) }, 58 | #else 59 | #define MACHINE_ADC_CLASS 60 | #endif 61 | 62 | #if MICROPY_HW_ENABLE_HW_DAC 63 | #define MACHINE_DAC_CLASS { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) }, 64 | #else 65 | #define MACHINE_DAC_CLASS 66 | #endif 67 | 68 | 69 | 70 | #define MICROPY_PY_MACHINE_EXTRA_GLOBALS \ 71 | \ 72 | { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \ 73 | { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \ 74 | \ 75 | { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \ 76 | { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, \ 77 | { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, \ 78 | { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) }, \ 79 | { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&machine_pwm_type) }, \ 80 | { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \ 81 | { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \ 82 | { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, \ 83 | MACHINE_CAN_CLASS \ 84 | MACHINE_ADC_CLASS \ 85 | MACHINE_DAC_CLASS \ 86 | \ 87 | 88 | 89 | static void mp_machine_idle(void) 90 | { 91 | __WFI(); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /M55M1/mods/modmachine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013-2015 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/runtime.h" 31 | #include "py/mphal.h" 32 | #include "extmod/modmachine.h" 33 | 34 | #include "classUART.h" 35 | #include "classI2C.h" 36 | #include "classSPI.h" 37 | #include "classCAN.h" 38 | #include "classPWM.h" 39 | #include "classADC.h" 40 | #include "classTimer.h" 41 | #include "classDAC.h" 42 | #include "classRTC.h" 43 | #include "classWDT.h" 44 | 45 | 46 | // This file is never compiled standalone, it's included directly from 47 | // extmod/modmachine.c via MICROPY_PY_MACHINE_INCLUDEFILE. 48 | 49 | #if MICROPY_HW_ENABLE_CAN 50 | #define MACHINE_CAN_CLASS { MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&machine_can_type) }, 51 | #else 52 | #define MACHINE_CAN_CLASS 53 | #endif 54 | 55 | #if MICROPY_HW_ENABLE_HW_EADC 56 | #define MACHINE_ADC_CLASS { MP_ROM_QSTR(MP_QSTR_ADCALL), MP_ROM_PTR(&machine_adc_all_type) }, \ 57 | { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) }, 58 | #else 59 | #define MACHINE_ADC_CLASS 60 | #endif 61 | 62 | #if MICROPY_HW_ENABLE_HW_DAC 63 | #define MACHINE_DAC_CLASS { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) }, 64 | #else 65 | #define MACHINE_DAC_CLASS 66 | #endif 67 | 68 | 69 | 70 | #define MICROPY_PY_MACHINE_EXTRA_GLOBALS \ 71 | \ 72 | { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \ 73 | { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \ 74 | \ 75 | { MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \ 76 | { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, \ 77 | { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, \ 78 | { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) }, \ 79 | { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&machine_pwm_type) }, \ 80 | { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) }, \ 81 | { MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&machine_rtc_type) }, \ 82 | { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, \ 83 | MACHINE_CAN_CLASS \ 84 | MACHINE_ADC_CLASS \ 85 | MACHINE_DAC_CLASS \ 86 | \ 87 | 88 | 89 | static void mp_machine_idle(void) 90 | { 91 | __WFI(); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /M5531/hal/M5531_SPI.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_SPI.h 3 | * @version V1.00 4 | * @brief M5531 SPI HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_SPI_H__ 10 | #define __M5531_SPI_H__ 11 | 12 | #include "buffer.h" 13 | #include "drv_pdma.h" 14 | 15 | #define SPI_DIRECTION_2LINES 0x00000000U 16 | #define SPI_DIRECTION_2LINES_RXONLY SPI_CTL_RXONLY_Msk 17 | #define SPI_DIRECTION_1LINE SPI_CTL_HALFDPX_Msk 18 | 19 | /** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission 20 | * @{ 21 | */ 22 | #define SPI_FIRSTBIT_MSB 0x00000000U 23 | #define SPI_FIRSTBIT_LSB SPI_CTL_LSB_Msk 24 | 25 | /** @defgroup SPI_Clock_Phase SPI Clock Phase 26 | * @{ 27 | */ 28 | #define SPI_PHASE_1EDGE 0x00000000U 29 | #define SPI_PHASE_2EDGE 0x00000001U 30 | 31 | #define SPI_EVENT_ERROR (1 << 1) 32 | #define SPI_EVENT_COMPLETE (1 << 2) 33 | #define SPI_EVENT_RX_OVERFLOW (1 << 3) 34 | #define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW) 35 | 36 | #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred 37 | 38 | 39 | typedef struct { 40 | uint32_t Mode; //Master/Slave mode 41 | uint32_t BaudRate; //Baud rate 42 | uint32_t ClockPolarity; //Closk polarity 43 | uint32_t Direction; //SPI_DIRECTION_2LINES/SPI_DIRECTION_2LINES_RXONLY/SPI_DIRECTION_1LINE 44 | uint32_t Bits; //Data width 45 | uint32_t FirstBit; //First bit LSB/MSB 46 | uint32_t ClockPhase; //Data sampling at SPI_PHASE_1EDGE/SPI_PHASE_2EDGE. ClockPolarity + ClockPhase = SPI mode 47 | 48 | } SPI_InitTypeDef; 49 | 50 | typedef struct { 51 | union { 52 | SPI_T *spi; 53 | LPSPI_T *lpspi; 54 | } u_spi; 55 | bool bLPSPI; 56 | int dma_usage; 57 | int dma_chn_id_tx; 58 | int dma_chn_id_rx; 59 | uint32_t event; 60 | uint32_t hdlr_async; 61 | struct buffer_s tx_buff; /**< Tx buffer */ 62 | struct buffer_s rx_buff; /**< Rx buffer */ 63 | } spi_t; 64 | 65 | int32_t SPI_Init( 66 | spi_t *Obj, 67 | SPI_InitTypeDef *psInitDef 68 | ); 69 | 70 | void SPI_Final(spi_t *obj); 71 | 72 | 73 | int SPI_MasterBlockWriteRead( 74 | spi_t *obj, 75 | const char *tx_buffer, 76 | int tx_length, 77 | char *rx_buffer, 78 | int rx_length, 79 | char write_fill 80 | ); 81 | 82 | int SPI_SlaveBlockWriteRead( 83 | spi_t *obj, 84 | const char *tx_buffer, 85 | int tx_length, 86 | char *rx_buffer, 87 | int rx_length, 88 | char write_fill 89 | ); 90 | 91 | int SPI_SetDataWidth( 92 | spi_t *obj, 93 | int data_width_bits 94 | ); 95 | 96 | 97 | void spi_master_transfer( 98 | spi_t *obj, 99 | const void *tx, 100 | size_t tx_length, 101 | void *rx, 102 | size_t rx_length, 103 | uint8_t bit_width, 104 | uint32_t handler, 105 | uint32_t event, 106 | E_PDMAUsage hint 107 | ); 108 | 109 | void spi_irq_handler_asynch(spi_t *obj); 110 | 111 | int is_spi_trans_done(spi_t *obj); 112 | 113 | void Handle_SPI_Irq(SPI_T *spi); 114 | void Handle_LPSPI_Irq(LPSPI_T *lpspi); 115 | 116 | 117 | int SPI_MasterWriteThenRead(spi_t *obj, const char *tx_buffer, int tx_length, 118 | char *rx_buffer, int rx_length, char write_fill); 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_SPI.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_SPI.h 3 | * @version V1.00 4 | * @brief M55M1 SPI HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_SPI_H__ 10 | #define __M55M1_SPI_H__ 11 | 12 | #include "buffer.h" 13 | #include "drv_pdma.h" 14 | 15 | #define SPI_DIRECTION_2LINES 0x00000000U 16 | #define SPI_DIRECTION_2LINES_RXONLY SPI_CTL_RXONLY_Msk 17 | #define SPI_DIRECTION_1LINE SPI_CTL_HALFDPX_Msk 18 | 19 | /** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission 20 | * @{ 21 | */ 22 | #define SPI_FIRSTBIT_MSB 0x00000000U 23 | #define SPI_FIRSTBIT_LSB SPI_CTL_LSB_Msk 24 | 25 | /** @defgroup SPI_Clock_Phase SPI Clock Phase 26 | * @{ 27 | */ 28 | #define SPI_PHASE_1EDGE 0x00000000U 29 | #define SPI_PHASE_2EDGE 0x00000001U 30 | 31 | #define SPI_EVENT_ERROR (1 << 1) 32 | #define SPI_EVENT_COMPLETE (1 << 2) 33 | #define SPI_EVENT_RX_OVERFLOW (1 << 3) 34 | #define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW) 35 | 36 | #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred 37 | 38 | 39 | typedef struct { 40 | uint32_t Mode; //Master/Slave mode 41 | uint32_t BaudRate; //Baud rate 42 | uint32_t ClockPolarity; //Closk polarity 43 | uint32_t Direction; //SPI_DIRECTION_2LINES/SPI_DIRECTION_2LINES_RXONLY/SPI_DIRECTION_1LINE 44 | uint32_t Bits; //Data width 45 | uint32_t FirstBit; //First bit LSB/MSB 46 | uint32_t ClockPhase; //Data sampling at SPI_PHASE_1EDGE/SPI_PHASE_2EDGE. ClockPolarity + ClockPhase = SPI mode 47 | 48 | } SPI_InitTypeDef; 49 | 50 | typedef struct { 51 | union { 52 | SPI_T *spi; 53 | LPSPI_T *lpspi; 54 | } u_spi; 55 | bool bLPSPI; 56 | int dma_usage; 57 | int dma_chn_id_tx; 58 | int dma_chn_id_rx; 59 | uint32_t event; 60 | uint32_t hdlr_async; 61 | struct buffer_s tx_buff; /**< Tx buffer */ 62 | struct buffer_s rx_buff; /**< Rx buffer */ 63 | } spi_t; 64 | 65 | int32_t SPI_Init( 66 | spi_t *Obj, 67 | SPI_InitTypeDef *psInitDef 68 | ); 69 | 70 | void SPI_Final(spi_t *obj); 71 | 72 | 73 | int SPI_MasterBlockWriteRead( 74 | spi_t *obj, 75 | const char *tx_buffer, 76 | int tx_length, 77 | char *rx_buffer, 78 | int rx_length, 79 | char write_fill 80 | ); 81 | 82 | int SPI_SlaveBlockWriteRead( 83 | spi_t *obj, 84 | const char *tx_buffer, 85 | int tx_length, 86 | char *rx_buffer, 87 | int rx_length, 88 | char write_fill 89 | ); 90 | 91 | int SPI_SetDataWidth( 92 | spi_t *obj, 93 | int data_width_bits 94 | ); 95 | 96 | 97 | void spi_master_transfer( 98 | spi_t *obj, 99 | const void *tx, 100 | size_t tx_length, 101 | void *rx, 102 | size_t rx_length, 103 | uint8_t bit_width, 104 | uint32_t handler, 105 | uint32_t event, 106 | E_PDMAUsage hint 107 | ); 108 | 109 | void spi_irq_handler_asynch(spi_t *obj); 110 | 111 | int is_spi_trans_done(spi_t *obj); 112 | 113 | void Handle_SPI_Irq(SPI_T *spi); 114 | void Handle_LPSPI_Irq(LPSPI_T *lpspi); 115 | 116 | 117 | int SPI_MasterWriteThenRead(spi_t *obj, const char *tx_buffer, int tx_length, 118 | char *rx_buffer, int rx_length, char write_fill); 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /M5531/mods/classPin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_CLASS_PIN_H 27 | #define MICROPY_INCLUDED_CLASS_PIN_H 28 | 29 | // This file requires pin_defs_xxx.h (which has port specific enums and 30 | // defines, so we include it here. It should never be included directly 31 | #include "py/obj.h" 32 | //#include "mpconfigboard_common.h" 33 | #include MICROPY_PIN_DEFS_PORT_H 34 | 35 | typedef struct { 36 | mp_obj_base_t base; 37 | qstr name; 38 | uint8_t idx; 39 | uint8_t fn; 40 | uint8_t unit; 41 | uint8_t type; 42 | void *reg; // The peripheral associated with this AF 43 | uint32_t mfp_val; 44 | } pin_af_obj_t; 45 | 46 | typedef struct { 47 | mp_obj_base_t base; 48 | qstr name; 49 | uint32_t port : 4; 50 | uint32_t pin : 5; // Some ARM processors use 32 bits/PORT 51 | uint32_t num_af : 6; 52 | uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT 53 | uint32_t adc_num : 3; // 1 bit per ADC 54 | uint32_t pin_mask; 55 | volatile uint32_t *mfp_reg; 56 | volatile uint32_t *mfos_reg; 57 | pin_gpio_t *gpio; 58 | const pin_af_obj_t *af; 59 | } pin_obj_t; 60 | 61 | extern const mp_obj_type_t pin_type; 62 | extern const mp_obj_type_t pin_af_type; 63 | 64 | // Include all of the individual pin objects 65 | #include "genhdr/pins.h" 66 | 67 | extern const mp_obj_type_t pin_board_pins_obj_type; 68 | extern const mp_obj_type_t pin_cpu_pins_obj_type; 69 | 70 | 71 | extern const mp_obj_dict_t pin_cpu_pins_locals_dict; 72 | extern const mp_obj_dict_t pin_board_pins_locals_dict; 73 | 74 | 75 | extern uint32_t pin_get_mode(const pin_obj_t *pin); 76 | extern uint32_t pin_get_pull(const pin_obj_t *pin); 77 | extern void pin_set_pull(const pin_obj_t *pin, uint32_t mode); 78 | extern uint32_t pin_get_af(const pin_obj_t *pin); 79 | extern void pin_set_af(const pin_obj_t *pin, const pin_af_obj_t *af_obj, int mode); 80 | 81 | extern const pin_obj_t *pin_find(mp_obj_t user_obj); 82 | extern const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name); 83 | extern const pin_af_obj_t *pin_find_af_by_mfp_value(const pin_obj_t *pin, mp_uint_t af_value); 84 | extern const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit); 85 | extern const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx); 86 | extern const pin_af_obj_t *pin_find_af_by_fn_type(const pin_obj_t *pin, uint8_t af_fn, uint8_t af_type); 87 | 88 | extern void pin_init0(void); 89 | 90 | MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /M55M1/mods/classPin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_CLASS_PIN_H 27 | #define MICROPY_INCLUDED_CLASS_PIN_H 28 | 29 | // This file requires pin_defs_xxx.h (which has port specific enums and 30 | // defines, so we include it here. It should never be included directly 31 | #include "py/obj.h" 32 | //#include "mpconfigboard_common.h" 33 | #include MICROPY_PIN_DEFS_PORT_H 34 | 35 | typedef struct { 36 | mp_obj_base_t base; 37 | qstr name; 38 | uint8_t idx; 39 | uint8_t fn; 40 | uint8_t unit; 41 | uint8_t type; 42 | void *reg; // The peripheral associated with this AF 43 | uint32_t mfp_val; 44 | } pin_af_obj_t; 45 | 46 | typedef struct { 47 | mp_obj_base_t base; 48 | qstr name; 49 | uint32_t port : 4; 50 | uint32_t pin : 5; // Some ARM processors use 32 bits/PORT 51 | uint32_t num_af : 6; 52 | uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT 53 | uint32_t adc_num : 3; // 1 bit per ADC 54 | uint32_t pin_mask; 55 | volatile uint32_t *mfp_reg; 56 | volatile uint32_t *mfos_reg; 57 | pin_gpio_t *gpio; 58 | const pin_af_obj_t *af; 59 | } pin_obj_t; 60 | 61 | extern const mp_obj_type_t pin_type; 62 | extern const mp_obj_type_t pin_af_type; 63 | 64 | // Include all of the individual pin objects 65 | #include "genhdr/pins.h" 66 | 67 | extern const mp_obj_type_t pin_board_pins_obj_type; 68 | extern const mp_obj_type_t pin_cpu_pins_obj_type; 69 | 70 | 71 | extern const mp_obj_dict_t pin_cpu_pins_locals_dict; 72 | extern const mp_obj_dict_t pin_board_pins_locals_dict; 73 | 74 | 75 | extern uint32_t pin_get_mode(const pin_obj_t *pin); 76 | extern uint32_t pin_get_pull(const pin_obj_t *pin); 77 | extern void pin_set_pull(const pin_obj_t *pin, uint32_t mode); 78 | extern uint32_t pin_get_af(const pin_obj_t *pin); 79 | extern void pin_set_af(const pin_obj_t *pin, const pin_af_obj_t *af_obj, int mode); 80 | 81 | extern const pin_obj_t *pin_find(mp_obj_t user_obj); 82 | extern const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name); 83 | extern const pin_af_obj_t *pin_find_af_by_mfp_value(const pin_obj_t *pin, mp_uint_t af_value); 84 | extern const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit); 85 | extern const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx); 86 | extern const pin_af_obj_t *pin_find_af_by_fn_type(const pin_obj_t *pin, uint8_t af_fn, uint8_t af_type); 87 | 88 | extern void pin_init0(void); 89 | 90 | MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /M5531/hal/M5531_Timer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M5531_Timer.h 3 | * @version V1.00 4 | * @brief M5531 Timer HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M5531_TIMER_H__ 10 | #define __M5531_TIMER_H__ 11 | 12 | typedef void (*PFN_INT_STATUS_HANDLER)(void *obj, uint32_t u32Status); 13 | 14 | typedef struct { 15 | union { 16 | TIMER_T *timer; 17 | LPTMR_T *lptimer; 18 | } u_timer; 19 | bool bLPTimer; 20 | PFN_INT_STATUS_HANDLER pfnStatusHandler; 21 | } hw_timer_t; 22 | 23 | typedef struct { 24 | uint32_t u32Mode; //TTMR_ONESHOT_MODE, TTMR_PERIODIC_MODE, TTMR_CONTINUOUS_MODE 25 | uint32_t u32Prescaler; //Prescale 26 | uint32_t u32Period; //Period 27 | } Timer_InitTypeDef; 28 | 29 | int32_t Timer_Init( 30 | hw_timer_t *psObj, 31 | Timer_InitTypeDef *psInitDef 32 | ); 33 | 34 | void Timer_Final( 35 | hw_timer_t *psObj 36 | ); 37 | 38 | int32_t Timer_Trigger( 39 | hw_timer_t *psObj 40 | ); 41 | 42 | int32_t Timer_Suspend( 43 | hw_timer_t *psObj 44 | ); 45 | 46 | int32_t Timer_EnableInt( 47 | hw_timer_t *psObj, 48 | PFN_INT_STATUS_HANDLER pfnHandler 49 | ); 50 | 51 | int32_t Timer_DisableInt( 52 | hw_timer_t *psObj 53 | ); 54 | 55 | bool Timer_IsActivate( 56 | hw_timer_t *psObj 57 | ); 58 | 59 | int32_t Timer_EnablePWMPeriodInt( 60 | hw_timer_t *psObj 61 | ); 62 | 63 | int32_t Timer_DisablePWMPeriodInt( 64 | hw_timer_t *psObj 65 | ); 66 | 67 | int32_t Timer_EnableCaptureInt( 68 | hw_timer_t *psObj 69 | ); 70 | 71 | //u32Mode: TIMER_CAPTURE_FREE_COUNTING_MODE 72 | // TIMER_CAPTURE_COUNTER_RESET_MODE 73 | //u32Edge: TIMER_CAPTURE_EVENT_FALLING 74 | // TIMER_CAPTURE_EVENT_RISING 75 | // TIMER_CAPTURE_EVENT_FALLING_RISING 76 | // TIMER_CAPTURE_EVENT_RISING_FALLING 77 | // TIMER_CAPTURE_EVENT_GET_LOW_PERIOD 78 | // TIMER_CAPTURE_EVENT_GET_HIGH_PERIOD 79 | 80 | int32_t Timer_EnableCapture( 81 | hw_timer_t *psObj, 82 | uint32_t u32Mode, 83 | uint32_t u32Edge 84 | ); 85 | 86 | int32_t Timer_DisableCaptureInt( 87 | hw_timer_t *psObj 88 | ); 89 | 90 | int32_t Timer_SetPWMMode( 91 | hw_timer_t *psObj, 92 | uint32_t u32Freq, 93 | uint32_t u32Duty 94 | ); 95 | 96 | int32_t Timer_PWMTrigger( 97 | hw_timer_t *psObj 98 | ); 99 | 100 | int32_t Timer_PWMSuspend( 101 | hw_timer_t *psObj 102 | ); 103 | 104 | int32_t Timer_UpdatePrescaler( 105 | hw_timer_t *psObj, 106 | uint32_t u32Prescaler 107 | ); 108 | 109 | int32_t Timer_UpdatePeriod( 110 | hw_timer_t *psObj, 111 | uint32_t u32Period 112 | ); 113 | 114 | uint32_t Timer_GetModuleClock( 115 | hw_timer_t *psObj 116 | ); 117 | 118 | int32_t Timer_SetPWMMode( 119 | hw_timer_t *psObj, 120 | uint32_t u32Freq, 121 | uint32_t u32Duty 122 | ); 123 | 124 | int32_t Timer_EnablePWMOutputChannel( 125 | hw_timer_t *psObj, 126 | uint32_t u32Channel //TPWM_CH0/TPWM_CH1 127 | ); 128 | 129 | uint32_t Timer_GetCounter( 130 | hw_timer_t *psObj 131 | ); 132 | 133 | uint32_t Timer_GetPWMPeriod( 134 | hw_timer_t *psObj 135 | ); 136 | 137 | int32_t Timer_UpdatePWMPeriod( 138 | hw_timer_t *psObj, 139 | uint32_t u32Period 140 | ); 141 | 142 | uint32_t Timer_GetCaptureData( 143 | hw_timer_t *psObj 144 | ); 145 | 146 | uint32_t Timer_GetCompareData( 147 | hw_timer_t *psObj 148 | ); 149 | 150 | uint32_t Timer_GetPWMCompareData( 151 | hw_timer_t *psObj 152 | ); 153 | 154 | void Handle_Timer_Irq(TIMER_T *timer); 155 | void Handle_LPTimer_Irq(LPTMR_T *lptimer); 156 | 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /M55M1/hal/M55M1_Timer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file M55M1_Timer.h 3 | * @version V1.00 4 | * @brief M55M1 Timer HAL header file for micropython 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | * @copyright (C) 2025 Nuvoton Technology Corp. All rights reserved. 8 | *****************************************************************************/ 9 | #ifndef __M55M1_TIMER_H__ 10 | #define __M55M1_TIMER_H__ 11 | 12 | typedef void (*PFN_INT_STATUS_HANDLER)(void *obj, uint32_t u32Status); 13 | 14 | typedef struct { 15 | union { 16 | TIMER_T *timer; 17 | LPTMR_T *lptimer; 18 | } u_timer; 19 | bool bLPTimer; 20 | PFN_INT_STATUS_HANDLER pfnStatusHandler; 21 | } hw_timer_t; 22 | 23 | typedef struct { 24 | uint32_t u32Mode; //TTMR_ONESHOT_MODE, TTMR_PERIODIC_MODE, TTMR_CONTINUOUS_MODE 25 | uint32_t u32Prescaler; //Prescale 26 | uint32_t u32Period; //Period 27 | } Timer_InitTypeDef; 28 | 29 | int32_t Timer_Init( 30 | hw_timer_t *psObj, 31 | Timer_InitTypeDef *psInitDef 32 | ); 33 | 34 | void Timer_Final( 35 | hw_timer_t *psObj 36 | ); 37 | 38 | int32_t Timer_Trigger( 39 | hw_timer_t *psObj 40 | ); 41 | 42 | int32_t Timer_Suspend( 43 | hw_timer_t *psObj 44 | ); 45 | 46 | int32_t Timer_EnableInt( 47 | hw_timer_t *psObj, 48 | PFN_INT_STATUS_HANDLER pfnHandler 49 | ); 50 | 51 | int32_t Timer_DisableInt( 52 | hw_timer_t *psObj 53 | ); 54 | 55 | bool Timer_IsActivate( 56 | hw_timer_t *psObj 57 | ); 58 | 59 | int32_t Timer_EnablePWMPeriodInt( 60 | hw_timer_t *psObj 61 | ); 62 | 63 | int32_t Timer_DisablePWMPeriodInt( 64 | hw_timer_t *psObj 65 | ); 66 | 67 | int32_t Timer_EnableCaptureInt( 68 | hw_timer_t *psObj 69 | ); 70 | 71 | //u32Mode: TIMER_CAPTURE_FREE_COUNTING_MODE 72 | // TIMER_CAPTURE_COUNTER_RESET_MODE 73 | //u32Edge: TIMER_CAPTURE_EVENT_FALLING 74 | // TIMER_CAPTURE_EVENT_RISING 75 | // TIMER_CAPTURE_EVENT_FALLING_RISING 76 | // TIMER_CAPTURE_EVENT_RISING_FALLING 77 | // TIMER_CAPTURE_EVENT_GET_LOW_PERIOD 78 | // TIMER_CAPTURE_EVENT_GET_HIGH_PERIOD 79 | 80 | int32_t Timer_EnableCapture( 81 | hw_timer_t *psObj, 82 | uint32_t u32Mode, 83 | uint32_t u32Edge 84 | ); 85 | 86 | int32_t Timer_DisableCaptureInt( 87 | hw_timer_t *psObj 88 | ); 89 | 90 | int32_t Timer_SetPWMMode( 91 | hw_timer_t *psObj, 92 | uint32_t u32Freq, 93 | uint32_t u32Duty 94 | ); 95 | 96 | int32_t Timer_PWMTrigger( 97 | hw_timer_t *psObj 98 | ); 99 | 100 | int32_t Timer_PWMSuspend( 101 | hw_timer_t *psObj 102 | ); 103 | 104 | int32_t Timer_UpdatePrescaler( 105 | hw_timer_t *psObj, 106 | uint32_t u32Prescaler 107 | ); 108 | 109 | int32_t Timer_UpdatePeriod( 110 | hw_timer_t *psObj, 111 | uint32_t u32Period 112 | ); 113 | 114 | uint32_t Timer_GetModuleClock( 115 | hw_timer_t *psObj 116 | ); 117 | 118 | int32_t Timer_SetPWMMode( 119 | hw_timer_t *psObj, 120 | uint32_t u32Freq, 121 | uint32_t u32Duty 122 | ); 123 | 124 | int32_t Timer_EnablePWMOutputChannel( 125 | hw_timer_t *psObj, 126 | uint32_t u32Channel //TPWM_CH0/TPWM_CH1 127 | ); 128 | 129 | uint32_t Timer_GetCounter( 130 | hw_timer_t *psObj 131 | ); 132 | 133 | uint32_t Timer_GetPWMPeriod( 134 | hw_timer_t *psObj 135 | ); 136 | 137 | int32_t Timer_UpdatePWMPeriod( 138 | hw_timer_t *psObj, 139 | uint32_t u32Period 140 | ); 141 | 142 | uint32_t Timer_GetCaptureData( 143 | hw_timer_t *psObj 144 | ); 145 | 146 | uint32_t Timer_GetCompareData( 147 | hw_timer_t *psObj 148 | ); 149 | 150 | uint32_t Timer_GetPWMCompareData( 151 | hw_timer_t *psObj 152 | ); 153 | 154 | void Handle_Timer_Irq(TIMER_T *timer); 155 | void Handle_LPTimer_Irq(LPTMR_T *lptimer); 156 | 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /M5531/mods/pin_named_pins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/runtime.h" 31 | #include "py/mphal.h" 32 | #include "classPin.h" 33 | 34 | MP_DEFINE_CONST_OBJ_TYPE( 35 | pin_cpu_pins_obj_type, 36 | MP_QSTR_cpu, 37 | MP_TYPE_FLAG_NONE, 38 | locals_dict, &pin_cpu_pins_locals_dict 39 | ); 40 | 41 | MP_DEFINE_CONST_OBJ_TYPE( 42 | pin_board_pins_obj_type, 43 | MP_QSTR_board, 44 | MP_TYPE_FLAG_NONE, 45 | locals_dict, &pin_board_pins_locals_dict 46 | ); 47 | 48 | const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) 49 | { 50 | mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins); 51 | mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP); 52 | if (named_elem != NULL && named_elem->value != NULL) { 53 | return named_elem->value; 54 | } 55 | return NULL; 56 | } 57 | 58 | const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit) 59 | { 60 | const pin_af_obj_t *af = pin->af; 61 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 62 | if (af->fn == fn && af->unit == unit) { 63 | return af; 64 | } 65 | } 66 | return NULL; 67 | } 68 | 69 | const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx) 70 | { 71 | const pin_af_obj_t *af = pin->af; 72 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 73 | if (af->idx == af_idx) { 74 | return af; 75 | } 76 | } 77 | return NULL; 78 | } 79 | 80 | const pin_af_obj_t *pin_find_af_by_fn_type(const pin_obj_t *pin, uint8_t af_fn, uint8_t af_type) 81 | { 82 | const pin_af_obj_t *af = pin->af; 83 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 84 | if ((af->type == af_type) && (af->fn == af_fn)) { 85 | return af; 86 | } 87 | } 88 | return NULL; 89 | } 90 | 91 | 92 | const pin_af_obj_t *pin_find_af_by_mfp_value(const pin_obj_t *pin, mp_uint_t af_value) 93 | { 94 | const pin_af_obj_t *af = pin->af; 95 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 96 | if (af->mfp_val == af_value) { 97 | return af; 98 | } 99 | } 100 | return NULL; 101 | } 102 | 103 | 104 | 105 | /* unused 106 | const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name) { 107 | const pin_af_obj_t *af = pin->af; 108 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 109 | if (strcmp(name, qstr_str(af->name)) == 0) { 110 | return af; 111 | } 112 | } 113 | return NULL; 114 | } 115 | */ 116 | -------------------------------------------------------------------------------- /M55M1/mods/pin_named_pins.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2013, 2014 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "py/runtime.h" 31 | #include "py/mphal.h" 32 | #include "classPin.h" 33 | 34 | MP_DEFINE_CONST_OBJ_TYPE( 35 | pin_cpu_pins_obj_type, 36 | MP_QSTR_cpu, 37 | MP_TYPE_FLAG_NONE, 38 | locals_dict, &pin_cpu_pins_locals_dict 39 | ); 40 | 41 | MP_DEFINE_CONST_OBJ_TYPE( 42 | pin_board_pins_obj_type, 43 | MP_QSTR_board, 44 | MP_TYPE_FLAG_NONE, 45 | locals_dict, &pin_board_pins_locals_dict 46 | ); 47 | 48 | const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) 49 | { 50 | mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins); 51 | mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP); 52 | if (named_elem != NULL && named_elem->value != NULL) { 53 | return named_elem->value; 54 | } 55 | return NULL; 56 | } 57 | 58 | const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit) 59 | { 60 | const pin_af_obj_t *af = pin->af; 61 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 62 | if (af->fn == fn && af->unit == unit) { 63 | return af; 64 | } 65 | } 66 | return NULL; 67 | } 68 | 69 | const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx) 70 | { 71 | const pin_af_obj_t *af = pin->af; 72 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 73 | if (af->idx == af_idx) { 74 | return af; 75 | } 76 | } 77 | return NULL; 78 | } 79 | 80 | const pin_af_obj_t *pin_find_af_by_fn_type(const pin_obj_t *pin, uint8_t af_fn, uint8_t af_type) 81 | { 82 | const pin_af_obj_t *af = pin->af; 83 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 84 | if ((af->type == af_type) && (af->fn == af_fn)) { 85 | return af; 86 | } 87 | } 88 | return NULL; 89 | } 90 | 91 | 92 | const pin_af_obj_t *pin_find_af_by_mfp_value(const pin_obj_t *pin, mp_uint_t af_value) 93 | { 94 | const pin_af_obj_t *af = pin->af; 95 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 96 | if (af->mfp_val == af_value) { 97 | return af; 98 | } 99 | } 100 | return NULL; 101 | } 102 | 103 | 104 | 105 | /* unused 106 | const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name) { 107 | const pin_af_obj_t *af = pin->af; 108 | for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { 109 | if (strcmp(name, qstr_str(af->name)) == 0) { 110 | return af; 111 | } 112 | } 113 | return NULL; 114 | } 115 | */ 116 | -------------------------------------------------------------------------------- /M5531/PinAFGen.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import re 4 | import argparse 5 | import subprocess 6 | 7 | special_ip = ['EBI', 'CCAP', 'KPI', 'GPIO', 'SWDH', 'USB', 'HSUSB', 'ICE'] 8 | dmic_ip = ['DMIC0', 'DMIC1'] 9 | 10 | def refine_ip_pin(ip, pin): 11 | for s_ip in special_ip: 12 | if s_ip == ip: 13 | ip = ip + '0' 14 | 15 | for s_ip in dmic_ip: 16 | if s_ip == ip: 17 | if ip == 'DMIC0': 18 | pin = 'CH0_' + pin 19 | else: 20 | pin = 'CH1_' + pin 21 | ip = 'DMIC0' 22 | 23 | if pin == None: 24 | pin = ip.rstrip('0123456789') 25 | 26 | return ip + '_' + pin 27 | 28 | 29 | def alternative_pin_parser(input_file, pin_name): 30 | #print('do alternative_pin_parser') 31 | cleaned_str = pin_name.rstrip() 32 | cleaned_str = cleaned_str.strip("/* ").strip(" */").rstrip(" MFP") 33 | 34 | # 分割字串 35 | parts = cleaned_str.split(".") 36 | port_num = parts[0].lstrip('P') 37 | pin_num = parts[1].strip() if len(parts) > 1 else "" 38 | 39 | port_str = 'Port' + port_num 40 | port_pin_str = 'P' + port_num + pin_num 41 | 42 | #format to SYS_GPA_MFP0_PA0MFP_ style 43 | search_str = 'SYS_GP' + port_num 44 | 45 | if int(pin_num) < 4: 46 | mfp_str = 'MFP0' 47 | elif int(pin_num) < 8: 48 | mfp_str = 'MFP1' 49 | elif int(pin_num) < 12: 50 | mfp_str = 'MFP2' 51 | elif int(pin_num) < 16: 52 | mfp_str = 'MFP3' 53 | 54 | search_str = search_str + '_' + mfp_str 55 | search_str = search_str + '_' + port_pin_str + 'MFP_' 56 | #print(search_str) 57 | 58 | alternative_pins = [] 59 | 60 | alternative_pins.append(port_str) 61 | alternative_pins.append(port_pin_str) 62 | alternative_pins.append(mfp_str) 63 | 64 | 65 | #SYS.h's MFP marco would be "#define SYS_GPJ_MFP2_PJ10MFP_EBI_MCLK (0x2UL<= 2: 88 | pin = ip_pin_split[1] 89 | else: 90 | pin = None 91 | 92 | ip_pin = refine_ip_pin(ip, pin) 93 | #print(ip_pin) 94 | alternative_pins.append(ip_pin) 95 | 96 | 97 | if len(alternative_pins) > 3: 98 | return alternative_pins 99 | return None 100 | 101 | parser=argparse.ArgumentParser(description='Pin alternative generation. Input file: BSP/Library/StdDriver/inc/sys.h') 102 | parser.add_argument("--input_file", help='BSP\'s sys.h', required=True) 103 | parser.add_argument("--output_file", help='CSV file') 104 | args=parser.parse_args() 105 | 106 | input_file_name = args.input_file 107 | output_file_name = args.output_file 108 | 109 | if output_file_name == None: 110 | output_file_name = 'template.csv' 111 | 112 | try: 113 | input_file = open(input_file_name, "r") 114 | except OSError: 115 | print("Could not open input file") 116 | exit -1 117 | 118 | try: 119 | output_file = open(output_file_name, "w") 120 | except OSError: 121 | input_file.close() 122 | print("Could not create output file") 123 | exit -2 124 | 125 | output_file.write('#Port,Pin,MFPL/MFPH,SPIM,,,,,,,,,,,,,,,,,,,,,,,EVENTOUT,\n') 126 | 127 | while input_file: 128 | line = input_file.readline() 129 | if not line: 130 | break 131 | 132 | alternative_pins = None 133 | if re.search(" MFP /*", line): 134 | alternative_pins = alternative_pin_parser(input_file, line) 135 | 136 | if alternative_pins != None: 137 | for pins_str in alternative_pins: 138 | output_file.write(pins_str) 139 | output_file.write(',') 140 | output_file.write('EVENTOUT, \n') 141 | 142 | input_file.close() 143 | output_file.close() 144 | print('Done') 145 | --------------------------------------------------------------------------------