cancel
Showing results for 
Search instead for 
Did you mean: 

flash word write and byte write

whitney
Associate II
Posted on September 01, 2011 at 22:32

Hello,

I am using the STM32F series. Right now I am writing to the flash one word at time. I have no problem doing this. I now implemented a function that writes one byte at a time. When I try to do this, I get the ''programming parallelism error'' (PGPERR bit in FLASH_SR register). However, I have correctly changed the PSIZE bits in the control register and this has been verified in the debug window. Does anybody know why I am getting this error?

Clive1 I know you're out there. You helped me solve my last problem.

Any input is much appreciated.

Thanks.
3 REPLIES 3
Posted on September 02, 2011 at 00:06

I thought the minimum write size for the STM32F1 series was 16-bits, but let me check.

Normally I'd pair things up, and write an additional NUL byte for strings to get them to multiples of two bytes, or write aligned structures into it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
raptorhal2
Lead
Posted on September 02, 2011 at 00:31

The F2 series allows what gman is trying to do.

gman - identify where in your code sequence the error occurs. Is it the first byte write attempt, or the next word write attempt. I presume you set PSIZE before the byte write, did you reset it to 16 bits after the byte write function ?

Cheers, Hal

whitney
Associate II
Posted on September 02, 2011 at 15:30

Hello Clive1 and Baird,

Thank you very much for the input. I just found an error in my code however. The following is my FlashProgramByte function:

//******************************************************************************************************

// @brief   Programs a byte (8-bit) at a specified address.

// @param   address: specifies the address to be programmed.

//          data: specifies the data to be programmed.

// @return  kFLASH_ERROR: if there was an error while programming the flash.

//          kFLASH_COMPLETE: if everything went okay.

//******************************************************************************************************

uint32_t FlashProgramByte( uint32_t address, uint8_t data )

{

  uint32_t flash_status;

  // Wait for last operation to be completed

  flash_status = flashWaitForLastOperation();

  

  // if the previous operation is completed, proceed to program the new data

  if(flash_status == kFLASH_COMPLETE){

    FLASH_REGS.CR.PSIZE = kFLASH_BYTE_PSIZE;      // set the PSIZE bits

    FLASH_REGS.CR.PG = 1;                         // set the programming bit

    *(uint8_t *)address = data;                   // write the data to the specified address

        

    // Wait for last operation to be completed 

    flash_status = flashWaitForLastOperation();

    // when program operation is completed, disable the PG Bit

    FLASH_REGS.CR.PG = 0;

  } 

  

  // Return the Program Status

  return( flash_status );

}

My problem was the following line:

*(uint8_t *)address = data;                   // write the data to the specified address

was

*(uint32_t *)address = data;                   // write the data to the specified address

So in summary, it was just me messing up pointers. Thanks for your input however, I really appreciate it.

Gman