Merge stm32-meowbit
This commit is contained in:
commit
b9bed98538
@ -74,7 +74,7 @@ uint8_t display_init_sequence[] = {
|
|||||||
void board_init(void) {
|
void board_init(void) {
|
||||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||||
bus->base.type = &displayio_fourwire_type;
|
bus->base.type = &displayio_fourwire_type;
|
||||||
busio_spi_obj_t *internal_spi = &spi;
|
busio_spi_obj_t *internal_spi = &supervisor_flash_spi_bus;
|
||||||
common_hal_displayio_fourwire_construct(bus,
|
common_hal_displayio_fourwire_construct(bus,
|
||||||
internal_spi,
|
internal_spi,
|
||||||
&pin_PA08, // Command or data
|
&pin_PA08, // Command or data
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#define BOARD_OSC_DIV 12
|
#define BOARD_OSC_DIV 12
|
||||||
#define BOARD_NO_VBUS_SENSE
|
#define BOARD_NO_VBUS_SENSE
|
||||||
// #define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
|
#define BOARD_VTOR_DEFER //Leave VTOR relocation to bootloader
|
||||||
#define BOARD_USE_INTERNAL_SPI
|
#define BOARD_USE_INTERNAL_SPI
|
||||||
|
|
||||||
// On-board flash
|
// On-board flash
|
||||||
|
@ -9,7 +9,7 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
|
|||||||
EXTERNAL_FLASH_DEVICES = W25Q16JV_IQ
|
EXTERNAL_FLASH_DEVICES = W25Q16JV_IQ
|
||||||
LONGINT_IMPL = MPZ
|
LONGINT_IMPL = MPZ
|
||||||
|
|
||||||
# BOOTLOADER_OFFSET = 0x8010000
|
BOOTLOADER_OFFSET = 0x8010000
|
||||||
|
|
||||||
# INTERNAL_FLASH_FILESYSTEM = 1
|
# INTERNAL_FLASH_FILESYSTEM = 1
|
||||||
# LONGINT_IMPL = NONE
|
# LONGINT_IMPL = NONE
|
||||||
@ -19,5 +19,5 @@ MCU_VARIANT = stm32f4
|
|||||||
MCU_SUB_VARIANT = stm32f401xe
|
MCU_SUB_VARIANT = stm32f401xe
|
||||||
MCU_PACKAGE = 64
|
MCU_PACKAGE = 64
|
||||||
CMSIS_MCU = STM32F401xE
|
CMSIS_MCU = STM32F401xE
|
||||||
# LD_FILE = boards/STM32F401_boot.ld
|
LD_FILE = boards/STM32F401_boot.ld
|
||||||
LD_FILE = boards/STM32F401_fs.ld #use for internal flash
|
# LD_FILE = boards/STM32F401_fs.ld #use for internal flash
|
@ -13,7 +13,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_DISP_CS), MP_ROM_PTR(&pin_PB12) },
|
{ MP_ROM_QSTR(MP_QSTR_DISP_CS), MP_ROM_PTR(&pin_PB12) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_DISP_DC), MP_ROM_PTR(&pin_PA08) },
|
{ MP_ROM_QSTR(MP_QSTR_DISP_DC), MP_ROM_PTR(&pin_PA08) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_DISP_RST), MP_ROM_PTR(&pin_PB10) },
|
{ MP_ROM_QSTR(MP_QSTR_DISP_RST), MP_ROM_PTR(&pin_PB10) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_DISP_BL), MP_ROM_PTR(&pin_PB03) }, //what is this, backlight?
|
{ MP_ROM_QSTR(MP_QSTR_DISP_BL), MP_ROM_PTR(&pin_PB03) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_BUZZ), MP_ROM_PTR(&pin_PB08) },
|
{ MP_ROM_QSTR(MP_QSTR_BUZZ), MP_ROM_PTR(&pin_PB08) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_BTNA), MP_ROM_PTR(&pin_PB09) },
|
{ MP_ROM_QSTR(MP_QSTR_BTNA), MP_ROM_PTR(&pin_PB09) },
|
||||||
@ -62,8 +62,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_P0), MP_ROM_PTR(&pin_PA00) },
|
{ MP_ROM_QSTR(MP_QSTR_P0), MP_ROM_PTR(&pin_PA00) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PB00) },
|
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PB00) },
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_INTERNAL_SPI), MP_ROM_PTR(&spi) },
|
|
||||||
|
|
||||||
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
|
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_INTERNAL_SPI), MP_ROM_PTR(&supervisor_flash_spi_bus) },
|
||||||
};
|
};
|
||||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
||||||
|
@ -68,9 +68,8 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
|
STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
|
||||||
//duty cycle is (0xFFFF - duty)/0xFFFF fraction x (number of pulses per period)
|
//duty cycle is duty/0xFFFF fraction x (number of pulses per period)
|
||||||
//Note that pulses are inverted, so duty cycle is inverted
|
return (duty*period) / ((1 << 16) - 1);
|
||||||
return ((0xFFFF - duty)*period) / ((1 << 16) - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
|
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
|
||||||
@ -114,11 +113,12 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||||||
bool first_time_setup = true;
|
bool first_time_setup = true;
|
||||||
|
|
||||||
for (uint i = 0; i < tim_num; i++) {
|
for (uint i = 0; i < tim_num; i++) {
|
||||||
uint8_t l_tim_index = mcu_tim_pin_list[i].tim_index - 1;
|
const mcu_tim_pin_obj_t * l_tim = &mcu_tim_pin_list[i];
|
||||||
uint8_t l_tim_channel = mcu_tim_pin_list[i].channel_index - 1;
|
uint8_t l_tim_index = l_tim->tim_index - 1;
|
||||||
|
uint8_t l_tim_channel = l_tim->channel_index - 1;
|
||||||
|
|
||||||
//if pin is same
|
//if pin is same
|
||||||
if (mcu_tim_pin_list[i].pin == pin) {
|
if (l_tim->pin == pin) {
|
||||||
//check if the timer has a channel active
|
//check if the timer has a channel active
|
||||||
if (reserved_tim[l_tim_index] != 0) {
|
if (reserved_tim[l_tim_index] != 0) {
|
||||||
//is it the same channel? (or all channels reserved by a var-freq)
|
//is it the same channel? (or all channels reserved by a var-freq)
|
||||||
@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||||||
first_time_setup = false; //skip setting up the timer
|
first_time_setup = false; //skip setting up the timer
|
||||||
}
|
}
|
||||||
//No problems taken, so set it up
|
//No problems taken, so set it up
|
||||||
self->tim = &mcu_tim_pin_list[i];
|
self->tim = l_tim;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,11 +203,8 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||||||
//Channel/PWM init
|
//Channel/PWM init
|
||||||
self->chan_handle.OCMode = TIM_OCMODE_PWM1;
|
self->chan_handle.OCMode = TIM_OCMODE_PWM1;
|
||||||
self->chan_handle.Pulse = timer_get_internal_duty(duty, period);
|
self->chan_handle.Pulse = timer_get_internal_duty(duty, period);
|
||||||
self->chan_handle.OCPolarity = TIM_OCPOLARITY_LOW;
|
self->chan_handle.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
self->chan_handle.OCFastMode = TIM_OCFAST_DISABLE;
|
self->chan_handle.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
self->chan_handle.OCNPolarity = TIM_OCNPOLARITY_LOW; // needed for TIM1 and TIM8
|
|
||||||
self->chan_handle.OCIdleState = TIM_OCIDLESTATE_SET; // needed for TIM1 and TIM8
|
|
||||||
self->chan_handle.OCNIdleState = TIM_OCNIDLESTATE_SET; // needed for TIM1 and TIM8
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&self->handle, &self->chan_handle, self->channel) != HAL_OK) {
|
if (HAL_TIM_PWM_ConfigChannel(&self->handle, &self->chan_handle, self->channel) != HAL_OK) {
|
||||||
mp_raise_ValueError(translate("Could not initialize channel"));
|
mp_raise_ValueError(translate("Could not initialize channel"));
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ void reset_displays(void) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef BOARD_USE_INTERNAL_SPI
|
#ifdef BOARD_USE_INTERNAL_SPI
|
||||||
if (original_spi == (mp_obj_t)(&spi)) {
|
if (original_spi == (mp_obj_t)(&supervisor_flash_spi_bus)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,33 +36,33 @@
|
|||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
|
|
||||||
digitalio_digitalinout_obj_t cs_pin;
|
digitalio_digitalinout_obj_t cs_pin;
|
||||||
busio_spi_obj_t spi;
|
busio_spi_obj_t supervisor_flash_spi_bus;
|
||||||
|
|
||||||
const external_flash_device* flash_device;
|
const external_flash_device* flash_device;
|
||||||
uint32_t spi_flash_baudrate;
|
uint32_t spi_flash_baudrate;
|
||||||
|
|
||||||
// Enable the flash over SPI.
|
// Enable the flash over SPI.
|
||||||
static void flash_enable(void) {
|
static void flash_enable(void) {
|
||||||
while (!common_hal_busio_spi_try_lock(&spi)) {}
|
while (!common_hal_busio_spi_try_lock(&supervisor_flash_spi_bus)) {}
|
||||||
common_hal_digitalio_digitalinout_set_value(&cs_pin, false);
|
common_hal_digitalio_digitalinout_set_value(&cs_pin, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable the flash over SPI.
|
// Disable the flash over SPI.
|
||||||
static void flash_disable(void) {
|
static void flash_disable(void) {
|
||||||
common_hal_digitalio_digitalinout_set_value(&cs_pin, true);
|
common_hal_digitalio_digitalinout_set_value(&cs_pin, true);
|
||||||
common_hal_busio_spi_unlock(&spi);
|
common_hal_busio_spi_unlock(&supervisor_flash_spi_bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool transfer(uint8_t* command, uint32_t command_length, uint8_t* data_in, uint8_t* data_out, uint32_t data_length) {
|
static bool transfer(uint8_t* command, uint32_t command_length, uint8_t* data_in, uint8_t* data_out, uint32_t data_length) {
|
||||||
flash_enable();
|
flash_enable();
|
||||||
bool status = common_hal_busio_spi_write(&spi, command, command_length);
|
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, command, command_length);
|
||||||
if (status) {
|
if (status) {
|
||||||
if (data_in != NULL && data_out != NULL) {
|
if (data_in != NULL && data_out != NULL) {
|
||||||
status = common_hal_busio_spi_transfer(&spi, data_out, data_in, data_length);
|
status = common_hal_busio_spi_transfer(&supervisor_flash_spi_bus, data_out, data_in, data_length);
|
||||||
} else if (data_out != NULL) {
|
} else if (data_out != NULL) {
|
||||||
status = common_hal_busio_spi_read(&spi, data_out, data_length, 0xff);
|
status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data_out, data_length, 0xff);
|
||||||
} else if (data_in != NULL) {
|
} else if (data_in != NULL) {
|
||||||
status = common_hal_busio_spi_write(&spi, data_in, data_length);
|
status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data_in, data_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flash_disable();
|
flash_disable();
|
||||||
@ -103,10 +103,10 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t data_length)
|
|||||||
// Write the SPI flash write address into the bytes following the command byte.
|
// Write the SPI flash write address into the bytes following the command byte.
|
||||||
address_to_bytes(address, request + 1);
|
address_to_bytes(address, request + 1);
|
||||||
flash_enable();
|
flash_enable();
|
||||||
common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
|
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
|
||||||
bool status = common_hal_busio_spi_write(&spi, request, 4);
|
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, 4);
|
||||||
if (status) {
|
if (status) {
|
||||||
status = common_hal_busio_spi_write(&spi, data, data_length);
|
status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, data, data_length);
|
||||||
}
|
}
|
||||||
flash_disable();
|
flash_disable();
|
||||||
return status;
|
return status;
|
||||||
@ -122,10 +122,10 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t data_length)
|
|||||||
// Write the SPI flash write address into the bytes following the command byte.
|
// Write the SPI flash write address into the bytes following the command byte.
|
||||||
address_to_bytes(address, request + 1);
|
address_to_bytes(address, request + 1);
|
||||||
flash_enable();
|
flash_enable();
|
||||||
common_hal_busio_spi_configure(&spi, spi_flash_baudrate, 0, 0, 8);
|
common_hal_busio_spi_configure(&supervisor_flash_spi_bus, spi_flash_baudrate, 0, 0, 8);
|
||||||
bool status = common_hal_busio_spi_write(&spi, request, command_length);
|
bool status = common_hal_busio_spi_write(&supervisor_flash_spi_bus, request, command_length);
|
||||||
if (status) {
|
if (status) {
|
||||||
status = common_hal_busio_spi_read(&spi, data, data_length, 0xff);
|
status = common_hal_busio_spi_read(&supervisor_flash_spi_bus, data, data_length, 0xff);
|
||||||
}
|
}
|
||||||
flash_disable();
|
flash_disable();
|
||||||
return status;
|
return status;
|
||||||
@ -140,9 +140,9 @@ void spi_flash_init(void) {
|
|||||||
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
|
common_hal_digitalio_digitalinout_switch_to_output(&cs_pin, true, DRIVE_MODE_PUSH_PULL);
|
||||||
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
|
common_hal_digitalio_digitalinout_never_reset(&cs_pin);
|
||||||
|
|
||||||
spi.base.type = &busio_spi_type;
|
supervisor_flash_spi_bus.base.type = &busio_spi_type;
|
||||||
common_hal_busio_spi_construct(&spi, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
|
common_hal_busio_spi_construct(&supervisor_flash_spi_bus, SPI_FLASH_SCK_PIN, SPI_FLASH_MOSI_PIN, SPI_FLASH_MISO_PIN);
|
||||||
common_hal_busio_spi_never_reset(&spi);
|
common_hal_busio_spi_never_reset(&supervisor_flash_spi_bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_flash_init_device(const external_flash_device* device) {
|
void spi_flash_init_device(const external_flash_device* device) {
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "shared-bindings/busio/SPI.h"
|
#include "shared-bindings/busio/SPI.h"
|
||||||
|
|
||||||
extern busio_spi_obj_t spi; //Used to share SPI bus on some boards
|
extern busio_spi_obj_t supervisor_flash_spi_bus; //Used to share SPI bus on some boards
|
||||||
|
|
||||||
// This API is implemented for both normal SPI peripherals and QSPI peripherals.
|
// This API is implemented for both normal SPI peripherals and QSPI peripherals.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user