cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l451 error when trying to write to the Flash

lucasrj
Associate II

i am trying to implement openBootloader for an stm32l451,

but i cant get the write to work i get the following errors HAL_FLASH_ERROR_PROG | HAL_FLASH_ERROR_PGA |HAL_FLASH_ERROR_PGS

i am trying to write to 800c000 in the flash

this is my code( i used https://github.com/STMicroelectronics/stm32wl-openbl-apps to assist in how to write the interfaces)

void OPENBL_FLASH_Unlock(void) { HAL_FLASH_Unlock(); }

static void OPENBL_FLASH_Program(uint32_t Address, uint64_t Data) {
  /* Clear all FLASH errors flags before starting write operation */
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);

  HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, Address, Data);
}


void OPENBL_FLASH_Write(uint32_t Address, uint8_t *Data, uint32_t DataLength) {  
  uint32_t index;
  __ALIGNED(4) uint8_t buffer[FLASH_PROG_STEP_SIZE] = {0x0U};
  uint8_t remaining;

  if ((Data != NULL) && (DataLength != 0U)) {
    /* Unlock the flash memory for write operation */
    OPENBL_FLASH_Unlock();

    /* Program double-word by double-word (8 bytes) */
    while ((DataLength >> 3U) > 0U) {
      for (index = 0U; index < FLASH_PROG_STEP_SIZE; index++) {
        buffer[index] = *(Data + index);
      }

      OPENBL_FLASH_Program(Address,
                           *((uint64_t *)buffer));

      Address += FLASH_PROG_STEP_SIZE;
      Data += FLASH_PROG_STEP_SIZE;
      DataLength -= FLASH_PROG_STEP_SIZE;
    }

    /* If remaining count, go back to fill the rest with 0xFF */
    if (DataLength > 0U) {
      remaining = FLASH_PROG_STEP_SIZE - DataLength;

      /* Copy the remaining bytes */
      for (index = 0U; index < DataLength; index++) {
        buffer[index] = *(Data + index);
      }

      /* Fill the upper bytes with 0xFF */
      for (index = 0U; index < remaining; index++) {
        buffer[index + DataLength] = 0xFFU;
      }

      /* FLASH word program */
      OPENBL_FLASH_Program(Address,
                           (uint64_t)(*((uint64_t *)((uint32_t)buffer))));
    }

    /* Lock the Flash to disable the flash control register access */
    OPENBL_FLASH_Lock();
  }

 is where something i am missing ?

12 REPLIES 12
Saket_Om
ST Employee

Hello @lucasrj 

Is the OPENBL_FLASH_Erase() work fine please?

Could you please share your entire code then we can assist you more effectively. 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
lucasrj
Associate II

hey @Saket_Om 

Sorry for the late reply

I have not tried the OPENBL_FLASH_Erase() as I have not implemented it in the Python script on the host side,

The host device is an NX Jetson using an arm processor, so it can not run the Cube programmer.

Is there an ARM version of Cube Programmer?

Then, I used the debugger. I could see it got the correct data in OPENBL_FLASH_Write() and called OPENBL_FLASH_Program() with the expected data, so I don't see how it should make a difference. Am I missing something?

I have attached my flash interface files

 

Hello @lucasrj 

Is the Write process work fine with STM32Cube programmer please? 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

I can write to it using a st-link, I am unable to connected the serial to an x64 computer.

it is connected to an jetson nx running arm

Is where a version of stm32cube programmer working on arm? 

@lucasrj 

Is your host running on windows?

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Sorry for the late response,

No it is running ubuntu 20

Hello @lucasrj 

The STM32Cube programmer tool is compatible with ARM architecture on Ubuntu.

Please check the RN0109.

Saket_Om_0-1744270964288.png

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

If I read what you sent correctly, it states that the stm32cube programmer can program stm32 arm processors but does not talk about the host PC. I can see I am running an older version of Ubuntu than is officially supported. What is the last version of the Cube programmer supporting Ubuntu 20?

Then, I tryed to run the Linux install as I did on my x64 laptop, and I got the following

lucasrj_0-1744271682050.png

 

Hello @lucasrj 

I apologize for this misunderstood, but the tool is not compatible with ARM architecture.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar