Flash memory changes - non functional

This commit is contained in:
Hierophect 2019-09-27 11:00:09 -04:00
parent 51df8d18b4
commit ad33950966
9 changed files with 45 additions and 18 deletions

View File

@ -137,6 +137,7 @@ SRC_STM32 = \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c \

View File

@ -7,8 +7,8 @@ MEMORY
{ {
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K /* entire flash */
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */
FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 48K /* sectors 1,2,3 are 16K */ FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K */
FLASH_TEXT (rx) : ORIGIN = 0x08010000, LENGTH = 960K /* sector 4 is 64K, sectors 5,6,7 are 128K */ FLASH_TEXT (rx) : ORIGIN = 0x08010000, LENGTH = 896K /* sector 4 is 64K, sectors 5,6,7 are 128K */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
} }

View File

@ -60,7 +60,7 @@
/* #define HAL_SAI_MODULE_ENABLED */ /* #define HAL_SAI_MODULE_ENABLED */
#define HAL_SD_MODULE_ENABLED #define HAL_SD_MODULE_ENABLED
/* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_MMC_MODULE_ENABLED */
/* #define HAL_SPI_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */ /* #define HAL_TIM_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_USART_MODULE_ENABLED */
@ -70,7 +70,6 @@
#define HAL_PCD_MODULE_ENABLED #define HAL_PCD_MODULE_ENABLED
/* #define HAL_HCD_MODULE_ENABLED */ /* #define HAL_HCD_MODULE_ENABLED */
/* #define HAL_DSI_MODULE_ENABLED */ /* #define HAL_DSI_MODULE_ENABLED */
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_QSPI_MODULE_ENABLED #define HAL_QSPI_MODULE_ENABLED
/* #define HAL_CEC_MODULE_ENABLED */ /* #define HAL_CEC_MODULE_ENABLED */
/* #define HAL_FMPI2C_MODULE_ENABLED */ /* #define HAL_FMPI2C_MODULE_ENABLED */

View File

@ -37,7 +37,6 @@
STATIC bool reserved_spi[6]; STATIC bool reserved_spi[6];
void spi_reset(void) { void spi_reset(void) {
//Note: I2Cs are also forcibly reset in construct, due to silicon error
#ifdef SPI1 #ifdef SPI1
reserved_spi[0] = false; reserved_spi[0] = false;
__HAL_RCC_SPI1_CLK_DISABLE(); __HAL_RCC_SPI1_CLK_DISABLE();
@ -65,10 +64,10 @@ void spi_reset(void) {
} }
void common_hal_busio_spi_construct(busio_spi_obj_t *self, void common_hal_busio_spi_construct(busio_spi_obj_t *self,
const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * sck, const mcu_pin_obj_t * mosi,
const mcu_pin_obj_t * miso) { const mcu_pin_obj_t * miso) {
//match pins to I2C objects //match pins to SPI objects
SPI_TypeDef * SPIx; SPI_TypeDef * SPIx;
uint8_t sck_len = sizeof(mcu_spi_sck_list)/sizeof(*mcu_spi_sck_list); uint8_t sck_len = sizeof(mcu_spi_sck_list)/sizeof(*mcu_spi_sck_list);
@ -77,7 +76,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
//sck //sck
for(uint i=0; i<sck_len;i++) { for(uint i=0; i<sck_len;i++) {
if (mcu_spi_sck_list[i].pin == clock) { if (mcu_spi_sck_list[i].pin == sck) {
//mosi //mosi
for(uint j=0; j<mosi_len;j++) { for(uint j=0; j<mosi_len;j++) {
if (mcu_spi_mosi_list[j].pin == mosi) { if (mcu_spi_mosi_list[j].pin == mosi) {
@ -99,8 +98,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
} }
//handle typedef selection, errors //handle typedef selection, errors
if(self->clk!=NULL && self->mosi!=NULL && self->miso!=NULL ) { if(self->sck!=NULL && self->mosi!=NULL && self->miso!=NULL ) {
SPIx = mcu_spi_banks[self->clk->spi_index-1]; SPIx = mcu_spi_banks[self->sck->spi_index-1];
} else { } else {
mp_raise_RuntimeError(translate("Invalid SPI pin selection")); mp_raise_RuntimeError(translate("Invalid SPI pin selection"));
} }

View File

@ -29,6 +29,9 @@
#include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Pin.h"
#include "stm32f4xx_hal.h"
#include "stm32f4/periph.h"
#include "py/obj.h" #include "py/obj.h"
typedef struct { typedef struct {

View File

@ -94,7 +94,7 @@ typedef struct {
#define SPI(index, alt, spi_pin) \ #define SPI(index, alt, spi_pin) \
{ \ { \
.i2c_index = index, \ .spi_index = index, \
.altfn_index = alt, \ .altfn_index = alt, \
.pin = spi_pin, \ .pin = spi_pin, \
} }

View File

@ -53,7 +53,7 @@ const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4] = {
// SPI // SPI
SPI_TypeDef * mcu_i2c_banks[3] = {SPI1, SPI2, SPI3, SPI4, SPI5}; SPI_TypeDef * mcu_spi_banks[5] = {SPI1, SPI2, SPI3, SPI4, SPI5};
const mcu_spi_sck_obj_t mcu_spi_sck_list[16] = { const mcu_spi_sck_obj_t mcu_spi_sck_list[16] = {
SPI(1, 5, &pin_PA05), SPI(1, 5, &pin_PA05),

View File

@ -62,7 +62,11 @@ static const flash_layout_t flash_layout[] = {
#endif #endif
}; };
static uint8_t sector_copy[0x4000] __attribute__((aligned(4))); static uint8_t sector_copy_16[0x4000] __attribute__((aligned(4)));
#if INTERNAL_FLASH_FILESYSTEM_SIZE >= 0x1C000
static uint8_t sector_copy_64[0x10000] __attribute__((aligned(4)));
#endif
//Return the sector of a given flash address. //Return the sector of a given flash address.
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
@ -126,7 +130,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
int32_t dest = convert_block_to_flash_addr(block); int32_t dest = convert_block_to_flash_addr(block);
if (dest == -1) { if (dest == -1) {
// bad block number // bad block number
mp_printf(&mp_plat_print, "BAD FLASH BLOCK ERROR"); mp_printf(&mp_plat_print, "Error: flash block not in filesystem");
return false; return false;
} }
@ -142,7 +146,28 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
uint32_t sector_start_addr; uint32_t sector_start_addr;
EraseInitStruct.Sector = flash_get_sector_info(dest, &sector_start_addr, &sector_size); EraseInitStruct.Sector = flash_get_sector_info(dest, &sector_start_addr, &sector_size);
EraseInitStruct.NbSectors = 1; EraseInitStruct.NbSectors = 1;
if (sector_size>0x4000) return false;
//If we have lots of ram the filesystem can be bigger.
if (INTERNAL_FLASH_FILESYSTEM_SIZE>=0x1C000) {
if (sector_size>0x10000) { //support 64KB sector 4
mp_printf(&mp_plat_print, "Error: flash sector too large");
return false;
}
} else {
if (sector_size>0x4000) {
mp_printf(&mp_plat_print, "Error: flash sector too large");
return false;
}
}
uint8_t * sector_copy;
if (sector_size == 0x4000) {
sector_copy = sector_copy_16;
} else if (sector_size == 0x10000) {
sector_copy = sector_copy_64;
} else {
mp_printf(&mp_plat_print, "Error: flash sector incorrect size");
}
// copy the sector // copy the sector
memcpy(sector_copy,(void *)sector_start_addr,sector_size); memcpy(sector_copy,(void *)sector_start_addr,sector_size);
@ -159,7 +184,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
// error occurred during sector erase // error occurred during sector erase
HAL_FLASH_Lock(); // lock the flash HAL_FLASH_Lock(); // lock the flash
mp_printf(&mp_plat_print, "FLASH SECTOR ERASE ERROR"); mp_printf(&mp_plat_print, "Error: flash sector erase failure");
return false; return false;
} }
@ -177,7 +202,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, sector_start_addr, (uint64_t)sector_copy[i]) != HAL_OK) { if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, sector_start_addr, (uint64_t)sector_copy[i]) != HAL_OK) {
// error occurred during flash write // error occurred during flash write
HAL_FLASH_Lock(); // lock the flash HAL_FLASH_Lock(); // lock the flash
mp_printf(&mp_plat_print, "FLASH WRITE ERROR"); mp_printf(&mp_plat_print, "Error: flash sector write error");
return false; return false;
} }
sector_start_addr += 1; sector_start_addr += 1;

View File

@ -39,7 +39,7 @@
#ifdef STM32F412Zx #ifdef STM32F412Zx
#define STM32_FLASH_SIZE 0x100000 //1MB #define STM32_FLASH_SIZE 0x100000 //1MB
#define INTERNAL_FLASH_FILESYSTEM_SIZE 0xC000 //48KiB #define INTERNAL_FLASH_FILESYSTEM_SIZE 0xC000 //112KiB
#endif #endif
#ifdef STM32F405xx #ifdef STM32F405xx