Browse Source

various code improvments:

1. flash_if driver support 2M.
2. vrom support

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
8c3e4ad0b2
  1. 34
      lib/flash_if.c
  2. 19
      lib/flash_if.h
  3. 16
      lib/vrom.c
  4. 6
      src/config.h
  5. 2
      src/flash.ld
  6. 2
      src/iap.c
  7. 9
      src/iap.ld
  8. 34
      src/main.c
  9. 2
      targets.mk

34
lib/flash_if.c

@ -32,9 +32,39 @@ static uint32_t get_sector(uint32_t Address)
sector = FLASH_Sector_9;
} else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10)) {
sector = FLASH_Sector_10;
#if !defined(STM32F429_439xx)
} else {/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/
sector = FLASH_Sector_11;
}
#else
} else if((Address < ADDR_FLASH_SECTOR_12) && (Address >= ADDR_FLASH_SECTOR_11)) {
sector = FLASH_Sector_11;
} else if((Address < ADDR_FLASH_SECTOR_13) && (Address >= ADDR_FLASH_SECTOR_12)) {
sector = FLASH_Sector_12;
} else if((Address < ADDR_FLASH_SECTOR_14) && (Address >= ADDR_FLASH_SECTOR_13)) {
sector = FLASH_Sector_13;
} else if((Address < ADDR_FLASH_SECTOR_15) && (Address >= ADDR_FLASH_SECTOR_14)) {
sector = FLASH_Sector_14;
} else if((Address < ADDR_FLASH_SECTOR_16) && (Address >= ADDR_FLASH_SECTOR_15)) {
sector = FLASH_Sector_15;
} else if((Address < ADDR_FLASH_SECTOR_17) && (Address >= ADDR_FLASH_SECTOR_16)) {
sector = FLASH_Sector_16;
} else if((Address < ADDR_FLASH_SECTOR_18) && (Address >= ADDR_FLASH_SECTOR_17)) {
sector = FLASH_Sector_17;
} else if((Address < ADDR_FLASH_SECTOR_19) && (Address >= ADDR_FLASH_SECTOR_18)) {
sector = FLASH_Sector_18;
} else if((Address < ADDR_FLASH_SECTOR_20) && (Address >= ADDR_FLASH_SECTOR_19)) {
sector = FLASH_Sector_19;
} else if((Address < ADDR_FLASH_SECTOR_21) && (Address >= ADDR_FLASH_SECTOR_20)) {
sector = FLASH_Sector_20;
} else if((Address < ADDR_FLASH_SECTOR_22) && (Address >= ADDR_FLASH_SECTOR_21)) {
sector = FLASH_Sector_21;
} else if((Address < ADDR_FLASH_SECTOR_23) && (Address >= ADDR_FLASH_SECTOR_22)) {
sector = FLASH_Sector_22;
} else {
sector = FLASH_Sector_23;
}
#endif
return sector;
}
@ -67,7 +97,11 @@ int flash_if_erase(uint32_t start_address, uint32_t length)
if (length > 0) {
end = get_sector(start_address + length);
} else {
#if !defined(STM32F429_439xx)
end = FLASH_Sector_11;
#else
end = FLASH_Sector_23;
#endif
}
for (i = start; i <= end; i += 8) {

19
lib/flash_if.h

@ -17,8 +17,27 @@
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbyte */
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbyte */
#ifdef STM32F429_439xx
#define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* Base @ of Sector 12, 16 Kbyte */
#define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* Base @ of Sector 13, 16 Kbyte */
#define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* Base @ of Sector 14, 16 Kbyte */
#define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810c000) /* Base @ of Sector 15, 16 Kbyte */
#define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* Base @ of Sector 16, 64 Kbyte */
#define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* Base @ of Sector 17, 128 Kbyte */
#define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* Base @ of Sector 18, 128 Kbyte */
#define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* Base @ of Sector 19, 128 Kbyte */
#define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* Base @ of Sector 20, 128 Kbyte */
#define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081a0000) /* Base @ of Sector 21, 128 Kbyte */
#define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081c0000) /* Base @ of Sector 22, 128 Kbyte */
#define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081e0000) /* Base @ of Sector 23, 128 Kbyte */
#endif
/* End of the Flash address */
#ifdef STM32F429_439xx
#define USER_FLASH_END_ADDRESS 0x081FFFFF
#else
#define USER_FLASH_END_ADDRESS 0x080FFFFF
#endif
void flash_if_init(void);
int flash_if_erase(uint32_t start_address, uint32_t length);

16
lib/vrom.c

@ -33,15 +33,23 @@
#include "stm32f4xx_flash.h"
#include "stm32f4xx_crc.h"
#include "vrom.h"
#include "config.h"
#define VROM_SECT_SZ (4096) /*!< Size of a flash sector */
#define VROM_SECT_CNT (3) /*!< Number of sectors */
#define VROM_BLOCK_SZ (256) /*!< Size of a flash block */
#ifndef TARGET_VROM_SECT_CNT
#define TARGET_VROM_SECT_CNT 3
#endif
#define VROM_SECT_SZ (16384) /*!< Size of a flash sector */
#define VROM_SECT_CNT (TARGET_VROM_SECT_CNT) /*!< Number of sectors */
#define VROM_BLOCK_SZ (256) /*!< Size of a flash block */
/*!
* Starting address for the flash area
*/
#define VROM_START_ADDR (0x08001000)
#ifdef TARGET_VROM_START_ADDR
#define TARGET_VROM_START_ADDR 0x08004000
#endif
#define VROM_START_ADDR (TARGET_VROM_START_ADDR)
/*!
* Number of blocks we can fit per sector, including the index block.

6
src/config.h

@ -1,7 +1,11 @@
#ifndef __TARGET_CONFIG_H__
#define __TARGET_CONFIG_H__
#define APP_ADDRESS (0x08004000)
/* vrom */
#define TARGET_VROM_START_ADDR 0x08004000
#define TARGET_VROM_SECT_CNT 1
#define APP_ADDRESS (0x08008000)
#define LED_D3 (PI13)
#define LED_D4 (PK5)

2
src/flash.ld

@ -2,7 +2,7 @@ ENTRY(Reset_Handler)
_MIN_HEAP_SIZE = 0x200;
_MIN_STACK_SIZE = 0x400;
MEMORY {
flash (rx) : org = 0x08004000, len = 2032K
flash (rx) : org = 0x08008000, len = 2016K
ram1 (xrw) : org = 0x20000000, len = 112K
ram2 (xrw) : org = 0x2001c000, len = 16K
ram3 (xrw) : org = 0x20020000, len = 64K

2
src/iap.c

@ -127,7 +127,7 @@ int main()
printf("................\r\n");
// serial_close(UART);
serial_close(UART);
bkp_sram_write(MAGIC_DEV, 0);
bkp_sram_write(MAGIC_POS, MAGIC_BOOT);

9
src/iap.ld

@ -3,6 +3,7 @@ _MIN_HEAP_SIZE = 0x200;
_MIN_STACK_SIZE = 0x400;
MEMORY {
flash (rx) : org = 0x08000000, len = 16K
eeprom (rx): org = 0x08004000, len = 16K
ram (xrw): org = 0x20000000, len = 112K
ccmram (rw): org = 0x10000000, len = 64K
sdram (rw): org = 0xc0000000, len = 32M
@ -14,6 +15,14 @@ SECTIONS {
. = ALIGN(4);
} >flash
.eeprom : {
. = ALIGN(4);
KEEP(*(.eeprom))
. = ORIGIN(eeprom) + LENGTH(eeprom) - 1;
BYTE(0xff)
. = ALIGN(4);
} > eeprom = 0xff
.text : {
. = ALIGN(4);
*(.text)

34
src/main.c

@ -418,6 +418,7 @@ static int __on_40ms(struct timer *tm, void *user)
return 0;
}
#if !defined(STM32F429ZI_EVAL)
int main()
{
/*
@ -435,10 +436,6 @@ int main()
printf("build: %s (%s)\r\n", __DATE__, __TIME__);
while (1) {
cmd_loop();
iwdg_reset();
}
/* RS422 */
serial_setup(RS422_0, RS422_BAUDRATE, 8, SERIAL_STOPBITS_1);
serial_setup(RS422_1, RS422_BAUDRATE, 8, SERIAL_STOPBITS_1);
@ -525,4 +522,33 @@ int main()
}
return 0;
}
#else
int main()
{
/*
* recovery from bad image.
*/
iwdg_set_period_ms(1000);
iwdg_start();
cmd_init();
bkp_sram_init();
bkp_sram_write(MAGIC_POS, MAGIC_APP);
/* debug console */
serial_setup(&serial0, CONSOLE_BAUDRATE, 8, SERIAL_STOPBITS_1);
gpio_init(PG13 | PG14, GPIO_OUTPUT);
gpio_write(PG13 | PG14, 1);
printf("build: %s (%s)\r\n", __DATE__, __TIME__);
printf("running\r\n...............................\r\n> ");
while (1) {
cmd_loop();
iwdg_reset();
}
return 0;
}
#endif

2
targets.mk

@ -13,7 +13,7 @@ ifeq ($(TARGET),f429)
ROMSZ := 2048k
RAMSZ := 192k
link_script := $(top_dir)/src/flash.ld
TARGET_CFLAGS += -DSTM32F429xx -DSTM32F429_439xx -DHSE_VALUE=8000000 -DDATA_IN_ExtSDRAM
TARGET_CFLAGS += -DSTM32F429xx -DSTM32F429_439xx -DHSE_VALUE=8000000 -DDATA_IN_ExtSDRAM -DSTM32F429ZI_EVAL
cmsis_srcs += $(stdph_dir)/src/stm32f4xx_fmc.c
endif

Loading…
Cancel
Save