I've just started to use a Nano Every in a new project with code that was running on a 33 BLE. However, I am encountering an extremely strange problem where the Nano gets into a continuous loop during initialisation where the processor just keeps restarting i.e. resetting itself. I have a lot of code which runs absolutely fine including an external SPI real time clock but the problem occurs when I start trying to use an OLED display using the u8g2lib library for the SSD1309 display. I've narrowed it down to a single line of code in u8g2_setup.c i.e.
u8g2->tile_buf_ptr = buf;
If I comment out this line of code, the problem doesn't happen (but of course the display doesn't work).
I can replace 'buf' with zero or the address of another variable but the code then fails elsewhere.
I am sure that this is something to do with memory as i am using u8g2lib in a fullscreen mode and 'buf' above is a static array of 1024 bytes. However I am not exceeding the Every's memory :
Sketch uses 18700 bytes (38%) of program storage space. Maximum is 49152 bytes.
Global variables use 2168 bytes (35%) of dynamic memory, leaving 3976 bytes for local variables. Maximum is 6144 bytes.
I have no idea how to debug this problem or fix it and cannot see how a single line of code (which seems perfectly innocent to me) can cause the processor to reset. I can only conclude that the hardware itself is at fault (rather than my or library code).
The main problem I had porting my code from the 33BLE to Nano was that 'ints' are 32 bits in 33BLE and 16 bits in Nano. However, I can't see how this might cause this problem as it seems to me that u8g2lib is explicit about the size of integer variables.
I have tried using both ATMEGA328 register emulation and the 'native' ATMEGA4809 modes.
Can anyone help please ?