cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrectly writing to memory?

plsWork
Associate II

I am trying to make a guitar loop pedal with my nucleo-l476rg board. It has 1MB of flash and I am trying to write and read from bank 2 only as it is the bank of memory I want to use for storing recorded audio. I currently have an active buffer set up between my ADC and DAC and it works well. My goal is to continue to have this active passthrough while recording and playing. It currently stays active when recording however, my DAC shuts off or I read on open circuit from my multimeter when I press the play button. I believe my issue is with either how I am writing to FLASH memory or reading from it. I am using two buffers to achieve this active passthrough while recording as one buffer stores samples while the other is being written to memory and then the buffers reverse. This buffering I believe is working properly as I've been testing which code is running with the on-board LED however i dont think memory part of my code is working. I am coding this at the register level. I've attached my main file. Any help would be greatly appreciated.

5 REPLIES 5
TDK
Super User
for(uint32_t x=0;x<1024;x+=2){
			//  uint32_t word = ((uint32_t)BackBuffer[x+1]<<16)|(uint32_t)BackBuffer[x];
			  *(volatile uint32_t *)(addr) = BackBuffer[x];

			  while(FLASH->SR & FLASH_SR_BSY);

			  FLASH->SR |= FLASH_SR_EOP;
			  addr += 2;
			  HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5, GPIO_PIN_SET);  //LED on if playing
		  }

You're writing 4 bytes (uint32_t), then you're skipping ahead only 2 bytes and writing again. This is not allowed. You must write exactly 2 uint32_t to an aligned address. This is also not writing every value. Your commented code is better but needs to skip ahead 4 bytes, not 2.

TDK_0-1756041821779.png

 

If you feel a post has answered your question, please click "Accept as Solution".

Like this? this is still giving me nothing.

TDK
Super User

What does "giving me nothing" mean? Step through it. No error flags get set? What data are you writing? What data is being read after programming?

If you feel a post has answered your question, please click "Accept as Solution".

I am trying to pass a stored guitar signal to my DAC. When I press the record button, my code is supposed to use two buffers to write the signal into flash memory (bank2). One buffer is being filled up with samples while a filled buffer is being written into memory and then the buffers switch. It perhaps is a timing issue between these buffers. However, when I press the play button after recording a sample, my DAC produces no output to my amp and my multimeter reads an open circuit.

Maybe go to start and ask is possible use flash your way? FLASH is realy usable to write, but rewrite have limited count and rewrite require erase before next write  =  your MCU FLASH is destroyed after some time of pedal use.

Next trouble is speed of flash process vs. speed of ADC samples arrive