STM32 FLASH changes from Freddie Chopin

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5473 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-03 13:39:16 +00:00
parent d0d3328d9c
commit 8d75785fad
4 changed files with 138 additions and 16 deletions

View File

@ -3855,3 +3855,6 @@
not just SPI (from Jose Pablo Carballo).
* arch/arm/src/arm/Kconfig and armv7m/Kconfig: Add an option for
buildroot toolchains: They may be EABI or OABI.
* include/nuttx/progmem and arch/arm/src/stm32/stm32_flash.c:
Fix a counting bug plus change interface to use either relative
or absolut FLASH addressing (from Freddie Chopin).

View File

@ -10,6 +10,8 @@ README
o Configuring NuttX
- Instantiating "Canned" Configurations
- NuttX Configuration Tool
- Incompatibilities with Older Configurations
- Converting Older Configurations to use the Configuration Tool
- NuttX Configuration Tool under DOS
o Toolchains
- Cross-Development Toolchains
@ -292,6 +294,114 @@ NuttX Configuration Tool
install 'mconf', make certain that your PATH variable includes
a path to that installation directory.
The basic configuration order is "bottom-up":
- Select the build environment,
- Select the processor,
- Select the board,
- Select the supported peripherals
- Configure the device drivers,
- Configure the application options on top of this.
This is pretty straight forward for creating new configurations
but may be less intuitive for modifying existing configurations.
Incompatibilities with Older Configurations
-------------------------------------------
***** WARNING *****
The old legacy, manual configurations and the new kconfig-frontends
configurations are not 100% compatible. Old legacy configurations
can *not* be used with the kconfig-frontends tool: If you run
'make menuconfig' with a legacy configuration the resulting
configuration will probably not be functional.
Q: How can I tell if a configuration is a new kconfig-frontends
configuration or an older, manual configuration?
A: a) New kcondfig-frontends configurations will have this setting
within the defconfig/.config file":
CONFIG_NUTTX_NEWCONFIG=y
b) Only old, manual configurations will have an appconfig file
Converting Older Configurations to use the Configuration Tool
-------------------------------------------------------------
Q: How can I convert a older, manual configuration into a new,
kconfig-frontends toolchain.
A: 1) Look at the appconfig file: Each application path there
will now have to have an enabling setting. For example,
if the old appconfig file had:
CONFIGURED_APPS = examples/ostest
Then the new configuration will need:
CONFIG_EXAMPLES_OSTEST=y
The appconfig file can then be deleted because it will not
be needed after the conversion.
2) Build the cmpconfig utility at tools:
cd tools
make -f Makefile.host cmpconfig
3) Perform these steps repeatedly until you are convinced that
the configurations are the same:
a) Repeat the following until you have account for all of the differences:
cp configs/<board>/<condfiguration>/defconfig .config
make menuconfig (Just exit and save the new .config file)
tools/cmpconfig configs/<board>/<condfiguration>/defconfig .config | grep file1
The final grep will show settings in the old defconfig file that
do not appear in the new .config file (or have a different value
in the new .config file). In the new configuration, you will
probably have to enable certain groups of features. Such
hierarachical enabling options were not part of the older
configuration.
b) Then make sure these all make sense:
tools/cmpconfig configs/<board>/<condfiguration>/defconfig .config | grep file2
The final grep will show settings in the new .config file that
do not appear in the older defconfig file (or have a different value
in the new .config file). Here you should see only the new
hierarachical enabling options (such as CONFIG_SPI or CONFIG_MMCSD)
plus some other internal configuration settings (like CONFIG_ARCH_HAVE_UART0).
You will have to convince yourself that these new settings all make sense.
4) Finally, update the configuration:
cp .config configs/<board>/<condfiguration>/defconfig
rm configs/<board>/<condfiguration>/appconfig
NOTE: You should comment out the line containing the CONFIG_APPS_DIR
in the new defconfig file. Why? Because the application directory
may reside at a different location when the configuration is installed
at some later time.
# CONFIG_APPS_DIR="../apps"
5) The updated configuration can then be instantiated in the normal
fashion:
cd tools
./configure.sh <board>/<condfiguration>
NOTE: If CONFIG_APPS_DIR is not defined in the defconfig file,
the configure.sh script will find and add the new, correct path to
the application directory (CONFIG_APPS_DIR) when it copies the
defconfig file to the .config file. This is the setting that was
commented out in step 4.
NuttX Configuration Tool under DOS
----------------------------------

View File

@ -35,7 +35,7 @@
/* Provides standard flash access functions, to be used by the flash mtd driver.
* The interface is defined in the include/nuttx/progmem.h
*
*
* Requirements during write/erase operations on FLASH:
* - HSI must be ON.
* - Low Power Modes are not permitted during write/erase
@ -80,7 +80,7 @@ void stm32_flash_unlock(void)
if (getreg32(STM32_FLASH_CR) & FLASH_CR_LOCK)
{
/* Unlock sequence */
putreg32(FLASH_KEY1, STM32_FLASH_KEYR);
putreg32(FLASH_KEY2, STM32_FLASH_KEYR);
}
@ -112,6 +112,11 @@ uint16_t up_progmem_pagesize(uint16_t page)
int up_progmem_getpage(uint32_t addr)
{
if (addr >= STM32_FLASH_BASE)
{
addr -= STM32_FLASH_BASE;
}
if (addr >= STM32_FLASH_SIZE)
{
return -EFAULT;
@ -131,14 +136,14 @@ int up_progmem_erasepage(uint16_t page)
}
/* Get flash ready and begin erasing single page */
if (!(getreg32(STM32_RCC_CR) & RCC_CR_HSION))
{
return -EPERM;
}
stm32_flash_unlock();
modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_PER);
putreg32(page * STM32_FLASH_PAGESIZE, STM32_FLASH_AR);
modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_STRT);
@ -146,10 +151,10 @@ int up_progmem_erasepage(uint16_t page)
while(getreg32(STM32_FLASH_SR) & FLASH_SR_BSY) up_waste();
modifyreg32(STM32_FLASH_CR, FLASH_CR_PER, 0);
/* Verify */
for (addr = page * STM32_FLASH_PAGESIZE + STM32_FLASH_BASE, count = STM32_FLASH_PAGESIZE;
for (addr = page * STM32_FLASH_PAGESIZE + STM32_FLASH_BASE, count = STM32_FLASH_PAGESIZE;
count; count-=4, addr += 4)
{
if (getreg32(addr) != 0xffffffff)
@ -173,8 +178,8 @@ int up_progmem_ispageerased(uint16_t page)
}
/* Verify */
for (addr = page * STM32_FLASH_PAGESIZE + STM32_FLASH_BASE, count = STM32_FLASH_PAGESIZE;
for (addr = page * STM32_FLASH_PAGESIZE + STM32_FLASH_BASE, count = STM32_FLASH_PAGESIZE;
count; count--, addr++)
{
if (getreg8(addr) != 0xff)
@ -200,6 +205,11 @@ int up_progmem_write(uint32_t addr, const void *buf, size_t count)
/* Check for valid address range */
if (addr >= STM32_FLASH_BASE)
{
addr -= STM32_FLASH_BASE;
}
if ((addr+count) >= STM32_FLASH_SIZE)
{
return -EFAULT;
@ -213,10 +223,10 @@ int up_progmem_write(uint32_t addr, const void *buf, size_t count)
}
stm32_flash_unlock();
modifyreg32(STM32_FLASH_CR, 0, FLASH_CR_PG);
for (addr += STM32_FLASH_BASE; count; count--, hword++, addr+=2)
for (addr += STM32_FLASH_BASE; count; count-=2, hword++, addr+=2)
{
/* Write half-word and wait to complete */
@ -237,7 +247,6 @@ int up_progmem_write(uint32_t addr, const void *buf, size_t count)
modifyreg32(STM32_FLASH_CR, FLASH_CR_PG, 0);
return -EIO;
}
}
modifyreg32(STM32_FLASH_CR, FLASH_CR_PG, 0);

View File

@ -99,7 +99,7 @@ uint16_t up_progmem_pagesize(uint16_t page);
* Address to page conversion
*
* Input Parameters:
* addr - Address without flash offet (aligned to page0)
* addr - Address with of without flash offset (absolute or aligned to page0)
*
* Returned Value:
* Page or negative value on error. The following errors are reported
@ -165,7 +165,7 @@ int up_progmem_ispageerased(uint16_t page);
* the address be aligned inside the page boundaries.
*
* Input Parameters:
* addr - Address without flash offet (aligned to page0)
* addr - Address with or without flash offset (absolute or aligned to page0)
* buf - Pointer to buffer
* count - Number of bytes to write *
*