mirror of
https://github.com/micropython/micropython.git
synced 2025-12-15 17:30:14 +01:00
This commit adds the beginning of a new alif port with support for Alif Ensemble MCUs. See https://alifsemi.com/ Supported features of this port added by this commit: - UART REPL. - TinyUSB support, for REPL and MSC. - Octal SPI flash support, for filesystem. - machine.Pin support. General notes about the port: - It uses make, similar to other bare-metal ports here. - The toolchain is the standard arm-none-eabi- toolchain. - Flashing a board can be done using either the built-in serial bootloader, or JLink (both supported here). - There are two required submodules (one for drivers/SDK, one for security tools), both of which are open source and on GitHub. - No special hardware or software is needed for development, just a board connected over USB. OpenMV have generously sponsored the development of this port. Signed-off-by: Damien George <damien@micropython.org> Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
153 lines
5.1 KiB
C
153 lines
5.1 KiB
C
/*
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
*
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2024 OpenMV LLC.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#include "py/ringbuf.h"
|
|
#include "shared/runtime/interrupt_char.h"
|
|
#include "irq.h"
|
|
#include ALIF_CMSIS_H
|
|
|
|
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
|
|
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
|
|
|
|
// For regular code that wants to prevent "background tasks" from running.
|
|
// These background tasks (LWIP, Bluetooth) run in PENDSV context.
|
|
#define MICROPY_PY_PENDSV_ENTER uint32_t atomic_state = raise_irq_pri(IRQ_PRI_PENDSV);
|
|
#define MICROPY_PY_PENDSV_REENTER atomic_state = raise_irq_pri(IRQ_PRI_PENDSV);
|
|
#define MICROPY_PY_PENDSV_EXIT restore_irq_pri(atomic_state);
|
|
|
|
// Port level Wait-for-Event macro
|
|
//
|
|
// Do not use this macro directly, include py/runtime.h and
|
|
// call mp_event_wait_indefinite() or mp_event_wait_ms(timeout)
|
|
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
|
|
do { \
|
|
if ((TIMEOUT_MS) < 0) { \
|
|
__WFE(); \
|
|
} else { \
|
|
/* TODO */ \
|
|
__WFE(); \
|
|
} \
|
|
} while (0)
|
|
|
|
// TODO requires mods to py/emitglue.c for this to be picked up
|
|
#define MP_HAL_CLEAN_DCACHE(addr, size) \
|
|
(SCB_CleanDCache_by_Addr((uint32_t *)((uint32_t)addr & ~0x1f), \
|
|
((uint32_t)((uint8_t *)addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
|
|
|
|
extern ringbuf_t stdin_ringbuf;
|
|
|
|
// TODO
|
|
#define mp_hal_quiet_timing_enter() 0
|
|
#define mp_hal_quiet_timing_exit(x) (void)x
|
|
#define mp_hal_delay_us_fast mp_hal_delay_us
|
|
|
|
/******************************************************************************/
|
|
// C-level pin HAL
|
|
|
|
#include "py/obj.h"
|
|
#include "gpio.h"
|
|
#include "pinconf.h"
|
|
|
|
#define MP_HAL_PIN_FMT "%q"
|
|
#define MP_HAL_PIN_MODE_INPUT (0)
|
|
#define MP_HAL_PIN_MODE_OUTPUT (1)
|
|
#define MP_HAL_PIN_MODE_OPEN_DRAIN (2)
|
|
#define MP_HAL_PIN_PULL_NONE (0)
|
|
#define MP_HAL_PIN_PULL_UP (1)
|
|
#define MP_HAL_PIN_PULL_DOWN (2)
|
|
|
|
#define mp_hal_pin_obj_t const machine_pin_obj_t *
|
|
|
|
typedef struct _machine_pin_obj_t {
|
|
mp_obj_base_t base;
|
|
GPIO_Type *gpio;
|
|
uint8_t port;
|
|
uint8_t pin;
|
|
qstr name;
|
|
} machine_pin_obj_t;
|
|
|
|
mp_hal_pin_obj_t mp_hal_get_pin_obj(mp_obj_t pin_in);
|
|
|
|
static inline qstr mp_hal_pin_name(mp_hal_pin_obj_t pin) {
|
|
return pin->name;
|
|
}
|
|
|
|
static inline void mp_hal_pin_input(mp_hal_pin_obj_t pin) {
|
|
uint8_t alt_func = PINMUX_ALTERNATE_FUNCTION_0;
|
|
uint8_t pad_ctrl = PADCTRL_READ_ENABLE;
|
|
pinconf_set(pin->port, pin->pin, alt_func, pad_ctrl);
|
|
gpio_set_direction_input(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_output(mp_hal_pin_obj_t pin) {
|
|
uint8_t alt_func = PINMUX_ALTERNATE_FUNCTION_0;
|
|
uint8_t pad_ctrl = PADCTRL_READ_ENABLE;
|
|
pinconf_set(pin->port, pin->pin, alt_func, pad_ctrl);
|
|
gpio_set_direction_output(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
|
|
uint8_t alt_func = PINMUX_ALTERNATE_FUNCTION_0;
|
|
uint8_t pad_ctrl = PADCTRL_DRIVER_OPEN_DRAIN | PADCTRL_READ_ENABLE;
|
|
pinconf_set(pin->port, pin->pin, alt_func, pad_ctrl);
|
|
gpio_set_direction_output(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_low(mp_hal_pin_obj_t pin) {
|
|
gpio_set_value_low(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_high(mp_hal_pin_obj_t pin) {
|
|
gpio_set_value_high(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline int mp_hal_pin_read(mp_hal_pin_obj_t pin) {
|
|
return gpio_get_value(pin->gpio, pin->pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_write(mp_hal_pin_obj_t pin, int v) {
|
|
if (v) {
|
|
mp_hal_pin_high(pin);
|
|
} else {
|
|
mp_hal_pin_low(pin);
|
|
}
|
|
}
|
|
|
|
static inline void mp_hal_pin_od_low(mp_hal_pin_obj_t pin) {
|
|
mp_hal_pin_low(pin);
|
|
}
|
|
|
|
static inline void mp_hal_pin_od_high(mp_hal_pin_obj_t pin) {
|
|
mp_hal_pin_high(pin);
|
|
}
|
|
|
|
static inline void mp_hal_wake_main_task_from_isr(void) {
|
|
// Defined for tinyusb support, nothing needs to be done here.
|
|
}
|
|
|
|
// Include all the pin definitions.
|
|
#include "genhdr/pins_board.h"
|