2014-07-02 13:42:37 +01:00
|
|
|
// We use the ST Cube HAL library for most hardware peripherals
|
2015-07-28 16:36:26 +01:00
|
|
|
#include STM32_HAL_H
|
2016-02-11 05:20:14 +00:00
|
|
|
#include "pin.h"
|
2014-07-02 13:42:37 +01:00
|
|
|
|
2015-10-30 23:03:58 +00:00
|
|
|
extern const unsigned char mp_hal_status_to_errno_table[4];
|
2014-10-23 14:25:32 +01:00
|
|
|
|
|
|
|
NORETURN void mp_hal_raise(HAL_StatusTypeDef status);
|
2014-11-27 16:58:31 +00:00
|
|
|
void mp_hal_set_interrupt_char(int c); // -1 to disable
|
2015-02-13 15:04:53 +00:00
|
|
|
|
2016-10-06 02:12:20 +01:00
|
|
|
// timing functions
|
2016-10-18 04:30:00 +01:00
|
|
|
|
2017-09-06 05:09:13 +01:00
|
|
|
#include "irq.h"
|
2017-06-22 07:18:42 +01:00
|
|
|
|
2018-05-28 02:23:33 +01:00
|
|
|
#if __CORTEX_M == 0
|
|
|
|
// Don't have raise_irq_pri on Cortex-M0 so keep IRQs enabled to have SysTick timing
|
|
|
|
#define mp_hal_quiet_timing_enter() (1)
|
|
|
|
#define mp_hal_quiet_timing_exit(irq_state) (void)(irq_state)
|
|
|
|
#else
|
2017-06-22 07:18:42 +01:00
|
|
|
#define mp_hal_quiet_timing_enter() raise_irq_pri(1)
|
|
|
|
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
|
2018-05-28 02:23:33 +01:00
|
|
|
#endif
|
2017-03-02 04:32:32 +00:00
|
|
|
#define mp_hal_delay_us_fast(us) mp_hal_delay_us(us)
|
2016-04-12 13:51:39 +01:00
|
|
|
|
2016-10-18 04:30:00 +01:00
|
|
|
void mp_hal_ticks_cpu_enable(void);
|
|
|
|
static inline mp_uint_t mp_hal_ticks_cpu(void) {
|
2018-05-28 02:23:33 +01:00
|
|
|
#if __CORTEX_M == 0
|
|
|
|
return 0;
|
|
|
|
#else
|
2018-03-29 06:23:52 +01:00
|
|
|
if (!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) {
|
2016-10-18 04:30:00 +01:00
|
|
|
mp_hal_ticks_cpu_enable();
|
|
|
|
}
|
|
|
|
return DWT->CYCCNT;
|
2018-05-28 02:23:33 +01:00
|
|
|
#endif
|
2016-10-18 04:30:00 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:50:47 +01:00
|
|
|
// C-level pin HAL
|
2016-10-18 04:32:42 +01:00
|
|
|
|
2017-09-06 05:09:13 +01:00
|
|
|
#include "pin.h"
|
2016-10-18 04:32:42 +01:00
|
|
|
|
2016-12-08 02:47:01 +00:00
|
|
|
#define MP_HAL_PIN_FMT "%q"
|
2016-11-11 06:53:45 +00:00
|
|
|
#define MP_HAL_PIN_MODE_INPUT (0)
|
|
|
|
#define MP_HAL_PIN_MODE_OUTPUT (1)
|
|
|
|
#define MP_HAL_PIN_MODE_ALT (2)
|
|
|
|
#define MP_HAL_PIN_MODE_ANALOG (3)
|
2018-05-02 03:05:45 +01:00
|
|
|
#if defined(GPIO_ASCR_ASC0)
|
|
|
|
#define MP_HAL_PIN_MODE_ADC (11)
|
|
|
|
#else
|
|
|
|
#define MP_HAL_PIN_MODE_ADC (3)
|
|
|
|
#endif
|
2016-11-11 06:53:45 +00:00
|
|
|
#define MP_HAL_PIN_MODE_OPEN_DRAIN (5)
|
|
|
|
#define MP_HAL_PIN_MODE_ALT_OPEN_DRAIN (6)
|
2016-12-22 03:51:07 +00:00
|
|
|
#define MP_HAL_PIN_PULL_NONE (GPIO_NOPULL)
|
|
|
|
#define MP_HAL_PIN_PULL_UP (GPIO_PULLUP)
|
|
|
|
#define MP_HAL_PIN_PULL_DOWN (GPIO_PULLDOWN)
|
2019-02-19 00:11:41 +00:00
|
|
|
#define MP_HAL_PIN_SPEED_LOW (GPIO_SPEED_FREQ_LOW)
|
|
|
|
#define MP_HAL_PIN_SPEED_MEDIUM (GPIO_SPEED_FREQ_MEDIUM)
|
|
|
|
#define MP_HAL_PIN_SPEED_HIGH (GPIO_SPEED_FREQ_HIGH)
|
|
|
|
#define MP_HAL_PIN_SPEED_VERY_HIGH (GPIO_SPEED_FREQ_VERY_HIGH)
|
2016-11-11 06:53:45 +00:00
|
|
|
|
2016-10-05 05:51:40 +01:00
|
|
|
#define mp_hal_pin_obj_t const pin_obj_t*
|
2016-10-18 04:32:42 +01:00
|
|
|
#define mp_hal_get_pin_obj(o) pin_find(o)
|
2016-12-08 02:47:01 +00:00
|
|
|
#define mp_hal_pin_name(p) ((p)->name)
|
2016-11-11 06:53:45 +00:00
|
|
|
#define mp_hal_pin_input(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0)
|
|
|
|
#define mp_hal_pin_output(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0)
|
|
|
|
#define mp_hal_pin_open_drain(p) mp_hal_pin_config((p), MP_HAL_PIN_MODE_OPEN_DRAIN, MP_HAL_PIN_PULL_NONE, 0)
|
2016-10-18 04:32:42 +01:00
|
|
|
#define mp_hal_pin_high(p) (((p)->gpio->BSRR) = (p)->pin_mask)
|
|
|
|
#define mp_hal_pin_low(p) (((p)->gpio->BSRR) = ((p)->pin_mask << 16))
|
|
|
|
#define mp_hal_pin_od_low(p) mp_hal_pin_low(p)
|
|
|
|
#define mp_hal_pin_od_high(p) mp_hal_pin_high(p)
|
|
|
|
#define mp_hal_pin_read(p) (((p)->gpio->IDR >> (p)->pin) & 1)
|
2020-01-08 00:38:20 +00:00
|
|
|
#define mp_hal_pin_write(p, v) ((v) ? mp_hal_pin_high(p) : mp_hal_pin_low(p))
|
2016-10-18 04:32:42 +01:00
|
|
|
|
|
|
|
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio);
|
|
|
|
void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt);
|
2016-11-11 06:53:45 +00:00
|
|
|
bool mp_hal_pin_config_alt(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint8_t fn, uint8_t unit);
|
2018-05-01 08:31:23 +01:00
|
|
|
void mp_hal_pin_config_speed(mp_hal_pin_obj_t pin_obj, uint32_t speed);
|
2019-02-22 10:53:41 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MP_HAL_MAC_WLAN0 = 0,
|
|
|
|
MP_HAL_MAC_WLAN1,
|
|
|
|
MP_HAL_MAC_BDADDR,
|
|
|
|
MP_HAL_MAC_ETH0,
|
|
|
|
};
|
|
|
|
|
2019-08-21 14:06:56 +01:00
|
|
|
void mp_hal_generate_laa_mac(int idx, uint8_t buf[6]);
|
2019-02-22 10:53:41 +00:00
|
|
|
void mp_hal_get_mac(int idx, uint8_t buf[6]);
|
2019-06-01 07:08:40 +01:00
|
|
|
void mp_hal_get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest);
|