2019-02-28 06:42 AM
Hi,
I am using the STM32L496 and I have wired an SRAM to it using the FMC to read and write. I have configured it to be a 16 bit Data bus, it is a 16 bit SRAM. I am using NE1.
It works well, except when I write a half-word to an odd memory location I can see two NOE's and two NE1's on my oscilloscope (ie it seems to write twice when only one write is required). Looking at the address bus it appears to be writting to the address one below what I want. Then it writes to the actual address I want.
It is the same for read.
It only does a single read or write for even address locations.
What is causing it?
Can I fix it?
Many thanks, Ali
2019-02-28 07:04 AM
> It works well, except when I write a half-word to an odd memory location ...
This is to be expected. Don't do misaligned read/writes.
One byte of your misaligned half-word is located in one half-word (address), the next byte is located at the subsequent half-word address. Thus two accesses are required.
2019-02-28 07:27 AM
Sorry, I don't understand. If I have address 0xaa55 for example, surely this accesses a 'half word' stored at location 0xaa55? And 0xaa54 accesses a different 'half word' location 0xaa54?
If 0xaa55 (or any other address) straddles two locations (and that is the cause of my double write), why have a A0? Surely this means I can only read half of the values in my SRAM?
Thanks for your help, Ali
2019-02-28 07:37 AM
In 16-bit mode the A0 pin on the outside of the STM32 is the A1 bit internally, it uses BYTE LANE signals to direct the use of D0..D7 and D8..D15 into the memory during WRITES
All the address bits shift. In 32-bit wide memory mode Ext A0 == Int A2, as the bus is shifted two bits to reduce the pin count and increase the memory addressable.
2019-02-28 08:32 AM
OK I see now, thank you. I assumed A0 on the outside was A0 on the inside!
If I use a uint16_t pointer to access the memory and increment the pointer, it increases the address by 2 each time. The problem became apparent because I tried to use an 'absolute' address which naturally includes A0.
Great, now I understand. Thanks again.