3167 views|7 replies

2865

Posts

4

Resources
The OP
 

STM32L431 strange assignment problem? [Copy link]

Today I am learning the internal flash assignment operation of STM32L431. The program code is as follows keil 5.28 version, HAL library STM32Cube FW_L4 V1.14.0

  uint32_t page_Error = 0;
  uint32_t NbOfPages =0;
  HAL_StatusTypeDef ret;
  ret= HAL_OK;
  NbOfPages = FLASH_BANK_SIZE/FLASH_PAGE_SIZE -1; 
  FLASH_EraseInitTypeDef EraseInitStruct;
  EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
  EraseInitStruct.Banks = FLASH_BANK_1;
  EraseInitStruct.Page = NbOfPages;
  EraseInitStruct.NbPages = 0x01;
	  
  HAL_FLASH_Unlock(); //
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
  page_Error = HAL_FLASH_GetError();
  if(HAL_FLASHEx_Erase(&EraseInitStruct,&page_Error) == HAL_OK)
  {
    ret=HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST,WriteAddress,num);
  }
  HAL_FLASH_Lock();
  return ret;

You can see that the EraseInitStruct; structure is an assignment operation, and the value of the debugging variable at the breakpoint is

EraseInitStruct.NbPages=0x08003BD9

Other members are normal. Look at the definition of FLASH_EraseInitTypeDef

EraseInitStruct.NbPages is an integer of uint32_t. Can anyone explain it?

This post is from stm32/stm8

Latest reply

You can try adding a few more free elements to the structure, initializing the assignment or not assigning free elements, and see the simulation results. Then change the optimization level and see.   Details Published on 2019-12-21 10:07
 

2865

Posts

4

Resources
2
 

I adjusted the location of the assignment.

Found that the assigned variable is still wrong! !

This is why even an assignment statement fails to execute.

This post is from stm32/stm8
 
 

6040

Posts

204

Resources
3
 

I feel it may be caused by optimization

This post is from stm32/stm8

Comments

What is open optimization?  Details Published on 2019-12-11 21:18
 
 

2865

Posts

4

Resources
4
 
lcofjp Published on 2019-12-11 18:40 I think it may be caused by optimization

Please tell me "What is optimization"?

This post is from stm32/stm8
 
 
 

2865

Posts

4

Resources
5
 

Finally, I optimized the internal variables of the function to three, and found that the assignment statement was normal. But the program still cannot be executed.

This post is from stm32/stm8
 
 
 

7422

Posts

2

Resources
6
 
Stack overflowed
This post is from stm32/stm8
 
 
 

6040

Posts

204

Resources
7
 

If it doesn’t work, try changing the compiler version, maybe it’s a compiler bug;

Optimization refers to the optimization level in the compiler settings

This post is from stm32/stm8
 
 
 

15

Posts

0

Resources
8
 

You can try adding a few more free elements to the structure, initializing the assignment or not assigning free elements, and see the simulation results. Then change the optimization level and see.

This post is from stm32/stm8
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list