Topic : extended addressing mode STM8

Forum : ST7/STM8

Original Post
Post Information Post
June 10, 2011 - 2:05pm
Guest

Hi,
I can not enable extended addressing mode. I tried to enable the feature by uncomment the definition:
“#define PointerAttr_Far 2 /*!< Used with memory Models for code larger than 64K */ “
but it doesn’t work.
In both case:
#define PointerAttr_Near 1 */ /*!< Used with memory Models for code smaller than 64K */
or
#define PointerAttr_Far 2 /*!< Used with memory Models for code larger than 64K */
i found the same result. I can only write up to 0xFFFF of internal Flash memory.
I used examples taken from STM8S_StdPeriph_Lib_V2.0.0 : FLASH_ByteReadWriteOperation
Processor: STM8S207RB
Ride 7.30.10.0159
RKit-STM8 for Ride7 2.32.10.0307
Ride 7 Patch 7.30.10.0169
Please help me, I spend so much time but without success.
Regards Marcin

Replies
Post Information Post
+1
0
-1
June 10, 2011 - 4:48pm
Raisonance Support Team

Hi Marcin,

We successfully built the FLASH_ByteReadWriteOperation example from the STM8S_StdPeriph_Lib_V2.0.0. It works fine.
There may at least be 2 things that you must check:
- Ensure you execute the code on actual hardware, not in the simulator.
- The debugger "plays" with the flash lock/unlock, as it sometimes has to write to it. This may leave the flash in an unexpected state. You can run the example without any breakpoint, then manually break execution and check whether you successfully reached the end of the main() function.

Best Regards,

+1
0
-1
June 14, 2011 - 12:42pm
Guest

Hi Bruno,
Thanks a lot of your suggestions. Unfortunately I have incorrect results . Please try to test some modifications in FLASH_ByteReadWriteOperation example:
/* Define FLASH programming time */
FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);
/* Unlock Data memory */
FLASH_Unlock(FLASH_MEMTYPE_PROG);
/* Read a byte at a specified address */
add = 0xFFFF;
FLASH_ProgramByte(add , 44); - this line produces good results
val = FLASH_ReadByte(add);
add = 0x10000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);
add = 0x20000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);
add = 0x27000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);

Additionally I switch options:
• #define RAM_EXECUTION (1)
• Program model (project options) STM8LargeROM/STM8SmallROM
But without result.
Only
add = 0xFFFF;
FLASH_ProgramByte(add , 44);
Works ok
How do I test:
1 step
Compilation, download to flash, reset, reset, upload from flash to file.
2 step
Comment:
/*
add = 0xFFFF;
FLASH_ProgramByte(add , 44); - this line produces good results
val = FLASH_ReadByte(add);
add = 0x10000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);
add = 0x20000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);
add = 0x27000;
FLASH_ProgramByte(add , 44); - no results
val = FLASH_ReadByte(add);
*/
Compilation, download to flash, reset, reset, upload from flash to file
3 step
comparison.
Best Regards,
Marcin Wijata

+1
0
-1
June 14, 2011 - 4:46pm
Raisonance Support Team

Hi Marcin,

We reproduced the problem in our Labs.
The problem comes from the fact that in the FLASH_ProgramByte() function, the "PointerAttr" qualifier should be applied to pointers and not to the value.

The solution is to correct the ST library the following way:

void FLASH_EraseByte(uint32_t Address)
{
    /* Check parameter */
    assert_param(IS_FLASH_ADDRESS_OK(Address));
    
    /* Erase byte */
   *(PointerAttr uint8_t*) (uint16_t)Address = FLASH_CLEAR_BYTE; // WILL NOT WORK! qualifier is forgotten
   *(uint8_t PointerAttr*) (uint16_t)Address = FLASH_CLEAR_BYTE; // Works fine. PointerAttr is replaced by "far" on STM8S208
}

*ALL* the functions from the library that use the PointerAttr qualifier should be rewritten as above.
Note that this limitation should be corrected in a future release of RKit-STM8, so that both syntaxes will be supported.

Best Regards,

+1
0
-1
June 20, 2011 - 9:54am
Guest

Hi Bruno,
Thanks a lot of your help. The problem is solved.
Best regards
Marcin

+1
0
-1
June 28, 2011 - 12:07am
Guest

Hi All,
I was working on this problem all day on an STM8S, and while I did end up needing to do the change mentioned in this thread, with:

FLASH_ProgramByte(0x12345, 0xAB);
val = FLASH_ReadByte(0x12345);

//////////////

void FLASH_ProgramByte(u32 Address, u8 Data)
{
assert_param(IS_FLASH_ADDRESS_OK(Address));
*(u8 PointerAttr*) (u16)Address = Data;
}

I did not get the correct "val", while:

void FLASH_ProgramByte(u32 Address, u8 Data)
{
assert_param(IS_FLASH_ADDRESS_OK(Address));
*(u8 PointerAttr*) (u32)Address = Data;
}

did give me the correct "val".

I tried this with different addresses over 0xFFFF and only the u16->u32 change gives me the correct value while running on the physical chip. I'm not too familiar with using these Near and Far addresses, but I have my compiler set to STM8S Large Rom, and my u8, u16, u32 types are identical to the ones in the the ST libraries.

Hope this helps.

+1
0
-1
June 28, 2011 - 9:53am
Raisonance Support Team

Hi,

You are right, of course. A 16-bit uint16_t address cannot hold a 24-bit addresss, it must be changed to uint32_t instead.
Actually the (uint32_t) cast should be completely removed from the code, as it is useless in this case.

Best Regards,
Bruno