Just playing around with the external flash and came to the situation where I hit a performance wall
No issue I think but I wanted to know how the programDataPage address is created. Obviously it is aligned to a page boundary, but is it maybe aligned to something more that that? E.g. aligned to a 4k, 8k or the like boundary?
I am asking because if there is such, data can be placed in the external flash in a way that for critical sections the address calculation and the seekData can be done more efficiently.
Say if I know that an address x + y will not cross the alignment of x then I can send the address >> 16 before adding y. And while waiting I can do additional address calculations.
I know it is very theoretical at the moment but maybe worth a thougth.
At least in my case when reading the map from external flash, there is quite some performance hit.
It is a typical raycaster. Each ray (64 of them) marches over the map with it’s stepx/stepy value. So sequencial reading is hard to implement.
The code is a mess right now and not in a shape to be shared. There will be too much noise.
@Mr.Blinky can you give me a quick hint how to check at which frequency the SPI runs? Today I thought I waited for around 18 to 20 cycles but the SPI transfer was not ok. Only a wait() could fix the issue.
Btw, I thought a little bit about my initial request. Actually I can align the address myself. Say I have the following scenario:
map size is 4096 bytes
So in order to be able to send flashaddress and do something else (e.g. map position calculation) while flashaddress goes out I could just put my leveldata at 4096 byte aligned addresses in flash. That way the upper byte of the flash address will never change and I can send it right away and do something else while the SPI block clocks it out.
Having said that, for repetitive random accesses to the flash it might be useful to have a seekData function that takes an address that does not need to be added to programDataPage. So the user can do all this calculation itself where it is not critical and then just seek to it.
damn it, no I can’t align the address myself because it is the sum of my local offset from the binary file I create and a random address aligned to the page boundary which is created by the flash-builder script…
Is there a way to tell the flash-builder script about any alignment preferences?
Ok I found the issue. I added like 50 nops without any effect, then read the datasheet about the SPI and found it is actually required to read the SPSR before accessing the SPDR. So simple nops won’t help. A single read of SPSR did the trick.
Seems like clearing the SPIF flag either by reading it or executing an interrupt routine is required.
Thanks for the macro. I used it a lot recently but in some situations I wanted to add it multiple times which cause compilation errors as the label was multiply defined. You probably have a solution for this but in case you are interested, here is what I came up with:
asm volatile("lookAtMe%=:\n"::"r" (__LINE__));
It adds the line number to the label name, so all of them will be unique and you can spill them out in your code.
Depends on the use-case. I use it to find these in the disassembly of the .elf file in order to see how the code was translated
So if I can additionally define the name, that would be great and the line number makes it unique. For instance if I use your macro in another macros within the same scope.
Thanks. Although I know it already it might be good to explain here for other users that read this. I was just too lazy to do it myself because the preprocessor always gives me the creeps and you’ve been already in a flow .
Your points are all valid. Just sometimes I cannot resist. Btw, adding the function name to the label does not work on my side. I think the FUNCTION is expaned into a char array, so you cannot stringify it I guess. At least I did not find a way other than giving the macro a new parameter but that would make the thing odd.