Merge pull request #2186 from hierophect/stm32-spi-flash
STM32: SPI Flash
This commit is contained in:
commit
f4922a530a
@ -34,4 +34,10 @@
|
||||
#define FLASH_PAGE_SIZE (0x4000)
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
|
||||
|
||||
// On-board flash
|
||||
#define SPI_FLASH_MOSI_PIN &pin_PB05
|
||||
#define SPI_FLASH_MISO_PIN &pin_PB04
|
||||
#define SPI_FLASH_SCK_PIN &pin_PB03
|
||||
#define SPI_FLASH_CS_PIN &pin_PA15
|
||||
|
@ -4,8 +4,10 @@ USB_PRODUCT = "Feather F405"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
USB_DEVICES = "CDC,MSC"
|
||||
|
||||
INTERNAL_FLASH_FILESYSTEM = 1
|
||||
LONGINT_IMPL = NONE
|
||||
SPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q16C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = stm32f4
|
||||
|
@ -34,4 +34,5 @@
|
||||
#define FLASH_PAGE_SIZE (0x4000)
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
|
||||
|
||||
|
@ -6,6 +6,11 @@ USB_MANUFACTURER = "STMicroelectronics"
|
||||
INTERNAL_FLASH_FILESYSTEM = 1
|
||||
LONGINT_IMPL = NONE
|
||||
|
||||
# QSPI_FLASH_FILESYSTEM = 1
|
||||
# EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
# EXTERNAL_FLASH_DEVICES = N25Q128A
|
||||
# LONGINT_IMPL = MPZ
|
||||
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = stm32f4
|
||||
MCU_SUB_VARIANT = stm32f412zx
|
||||
|
@ -221,11 +221,11 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
|
||||
|
||||
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
|
||||
const uint8_t *data, size_t len, bool transmit_stop_bit) {
|
||||
HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr<<1), (uint8_t *)data, (uint16_t)len, 2);
|
||||
HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr<<1), (uint8_t *)data, (uint16_t)len, 500);
|
||||
return result == HAL_OK ? 0 : MP_EIO;
|
||||
}
|
||||
|
||||
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
|
||||
uint8_t *data, size_t len) {
|
||||
return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 2) == HAL_OK ? 0 : MP_EIO;
|
||||
return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500) == HAL_OK ? 0 : MP_EIO;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
continue;
|
||||
}
|
||||
//store pins if not
|
||||
self->sck = &mcu_spi_sck_list[j];
|
||||
self->sck = &mcu_spi_sck_list[i];
|
||||
self->mosi = &mcu_spi_mosi_list[j];
|
||||
self->miso = &mcu_spi_miso_list[k];
|
||||
break;
|
||||
@ -123,9 +123,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
SPIx = mcu_spi_banks[self->sck->spi_index-1];
|
||||
} else {
|
||||
if (spi_taken) {
|
||||
mp_raise_RuntimeError(translate("Hardware busy, try alternative pins"));
|
||||
mp_raise_ValueError(translate("Hardware busy, try alternative pins"));
|
||||
} else {
|
||||
mp_raise_RuntimeError(translate("Invalid SPI pin selection"));
|
||||
mp_raise_ValueError(translate("Invalid SPI pin selection"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,14 +196,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||
self->handle.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
self->handle.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
self->handle.Init.NSS = SPI_NSS_SOFT;
|
||||
self->handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
self->handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
||||
self->handle.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
self->handle.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
self->handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
self->handle.Init.CRCPolynomial = 10;
|
||||
if (HAL_SPI_Init(&self->handle) != HAL_OK)
|
||||
{
|
||||
mp_raise_RuntimeError(translate("SPI Init Error"));
|
||||
mp_raise_ValueError(translate("SPI Init Error"));
|
||||
}
|
||||
self->baudrate = (HAL_RCC_GetPCLK2Freq()/16);
|
||||
self->prescaler = 16;
|
||||
@ -344,7 +344,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
|
||||
|
||||
if (HAL_SPI_Init(&self->handle) != HAL_OK)
|
||||
{
|
||||
mp_raise_RuntimeError(translate("SPI Re-initialization error"));
|
||||
mp_raise_ValueError(translate("SPI Re-initialization error"));
|
||||
}
|
||||
|
||||
self->baudrate = baudrate;
|
||||
@ -383,21 +383,21 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
|
||||
|
||||
bool common_hal_busio_spi_write(busio_spi_obj_t *self,
|
||||
const uint8_t *data, size_t len) {
|
||||
HAL_StatusTypeDef result = HAL_SPI_Transmit (&self->handle, (uint8_t *)data, (uint16_t)len, 2);
|
||||
return result == HAL_OK ? 1 : 0;
|
||||
HAL_StatusTypeDef result = HAL_SPI_Transmit (&self->handle, (uint8_t *)data, (uint16_t)len, HAL_MAX_DELAY);
|
||||
return result == HAL_OK;
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_read(busio_spi_obj_t *self,
|
||||
uint8_t *data, size_t len, uint8_t write_value) {
|
||||
HAL_StatusTypeDef result = HAL_SPI_Receive (&self->handle, data, (uint16_t)len, 2);
|
||||
return result == HAL_OK ? 1 : 0;
|
||||
HAL_StatusTypeDef result = HAL_SPI_Receive (&self->handle, data, (uint16_t)len, HAL_MAX_DELAY);
|
||||
return result == HAL_OK;
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
|
||||
uint8_t *data_out, uint8_t *data_in, size_t len) {
|
||||
HAL_StatusTypeDef result = HAL_SPI_TransmitReceive (&self->handle,
|
||||
data_out, data_in, (uint16_t)len,2);
|
||||
return result == HAL_OK ? 1 : 0;
|
||||
data_out, data_in, (uint16_t)len,HAL_MAX_DELAY);
|
||||
return result == HAL_OK;
|
||||
}
|
||||
|
||||
uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) {
|
||||
|
@ -40,9 +40,9 @@ void stm32f4_peripherals_gpio_init(void) {
|
||||
never_reset_pin_number(2,15); //PC15 OSC32_OUT
|
||||
never_reset_pin_number(0,13); //PA13 SWDIO
|
||||
never_reset_pin_number(0,14); //PA14 SWCLK
|
||||
never_reset_pin_number(0,15); //PA15 JTDI
|
||||
never_reset_pin_number(1,3); //PB3 JTDO
|
||||
never_reset_pin_number(1,4); //PB4 JTRST
|
||||
// never_reset_pin_number(0,15); //PA15 JTDI
|
||||
// never_reset_pin_number(1,3); //PB3 JTDO
|
||||
// never_reset_pin_number(1,4); //PB4 JTRST
|
||||
|
||||
// Port H is not included in GPIO port array
|
||||
// never_reset_pin_number(5,0); //PH0 JTDO
|
||||
|
@ -215,9 +215,9 @@ void stm32f4_peripherals_gpio_init(void) {
|
||||
never_reset_pin_number(2,15); //PC15 OSC32_OUT
|
||||
never_reset_pin_number(0,13); //PA13 SWDIO
|
||||
never_reset_pin_number(0,14); //PA14 SWCLK
|
||||
never_reset_pin_number(0,15); //PA15 JTDI
|
||||
never_reset_pin_number(1,3); //PB3 JTDO
|
||||
never_reset_pin_number(1,4); //PB4 JTRST
|
||||
//never_reset_pin_number(0,15); //PA15 JTDI
|
||||
//never_reset_pin_number(1,3); //PB3 JTDO
|
||||
//never_reset_pin_number(1,4); //PB4 JTRST
|
||||
|
||||
// Port H is not included in GPIO port array
|
||||
// never_reset_pin_number(5,0); //PH0 JTDO
|
||||
|
@ -442,4 +442,5 @@ typedef struct {
|
||||
.write_status_register_split = false, \
|
||||
.single_status_byte = false, \
|
||||
}
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_EXTERNAL_FLASH_DEVICES_H
|
||||
|
Loading…
Reference in New Issue
Block a user