When accessing SRAM, a problem occurs. The problem code is as follows:
The main function program is as follows:
/*
* Function name: main
* Description: Main function
* Input: None
* Output: None
*/
int main(void)
{
USART1_Config();
printf("USART IS OK!\r\n");
SysTick_Init();
LED_GPIO_Init();
LED_Turn(LEDALL,LED_OFF);
printf("Enter SRAM memory test! \r\n");
FSMC_SRAM_Test();
printf("Enter SRAM memory test ended! \r\n");
while(1)
{
LED_Turn(LED4,LED_ON);
Delay_ms(500);
LED_Turn(LED4,LED_OFF);
Delay_ms(500);
}
}
The content of the FSMC_SRAM_Test() function on line 16 is as follows:
/*
************************************************************************
Function name: void FMSC_SRAM_Test(void)
FSMC_SRAM test example
Entry parameters: None
Return data: None
other instructions:
Calling form:
************************************************************************
*/
void FSMC_SRAM_Test(void)
{
u32 WriteReadStatus = 0, Index = 0;
u16 TxBuffer[SRAM_BUFFER_SIZE];
u16 RxBuffer[SRAM_BUFFER_SIZE];
printf("\n\rFSMC initialization \r\n");
//FSMC initialization
FSMC_SRAM_Init();
printf("\n\r Static memory initialization completed!\r");
/*Fill the data BUFFER of SRAM with a series of data starting from 0x1234 and increasing continuously */
SRAM_Fill_Buffer(TxBuffer, SRAM_BUFFER_SIZE, 0x1234);
printf("\n\rStart writing data to static memory \r");
FSMC_SRAM_WriteBuffer(TxBuffer, SRAM_WRITE_READ_ADDR, SRAM_BUFFER_SIZE);
printf("\n\r Static memory writing data completed!\r");
printf("\n\rStart reading data from static memory\r");
FSMC_SRAM_ReadBuffer(RxBuffer, SRAM_WRITE_READ_ADDR, SRAM_BUFFER_SIZE);
printf("\n\r Static memory data reading completed!\r");
printf("\n\r Check whether the written data is consistent with the read data, if yes: DS1 is on, if no: DS2 is on!\n\r");
for (Index = 0x00; (Index < SRAM_BUFFER_SIZE) && (WriteReadStatus == 0); Index++)
{
if (RxBuffer[Index] != TxBuffer[Index])
{
WriteReadStatus = Index + 1;
}
printf("%02x ",RxBuffer[Index]);
}
if (WriteReadStatus == 0)
{
LED_Turn(LED1,LED_ON);
}
else
{
LED_Turn(LED2,LED_ON);
}
}
When this function is blocked, the program after this function can be executed.
But when it is not blocked, the function can be entered normally. The pintf() function on line 21 cannot be printed, but the FSMC_SRAM_Init() on line 22 can be entered;
but this function enters HardFault_Handler() after executing only two sentences;
after blocking the occurrence statement of entering HardFault_Handler(), it still enters HardFault_Handler() after executing only two sentences.
It is very frustrating. From the search results on the Internet, it is roughly as follows:
Memory leak
Stack overflow, increase the stack size
Array out of bounds
Wrong operation of hardware
The location of variable definition affects the compiler
The pointer points to a place that the system does not allow, and the access is out of bounds.
JLINK driver version problem
…
There are too many explanations, it's very confusing, it seems that there are many reasons for entering the HardFault_Handler() function.
I also made corresponding adjustments and processing according to the opinions of the majority of netizens... The results are all the same tragic.
Later, an unintentional move solved my problem. I defined the two arrays declared by the FSMC_SRAM_Test() function as global variables, as follows:
u16 TxBuffer[SRAM_BUFFER_SIZE];
u16 RxBuffer[SRAM_BUFFER_SIZE];
and the problem was solved. I was lucky and fortunate.
Visually, the analysis of the problem is as follows:
The array definition is incorrect, and the compiler has problems with its handling.
Another possibility is that the array I defined is too large. SRAM_BUFFER_SIZE is 0XFF. There is probably a memory problem, but the compiler cannot detect it.
Previous article:STM32F1 drives AM2302 temperature and humidity sensor
Next article:KeilMDK4.22 compiles STM32 project and reports error: Error: L6218
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- STC8A8K64 MCU ADC input is disturbed
- Four memory protection issues of TI C66x DSP
- Synopsys latest IP resource recommendations
- Outsourcing Motor Drive Control Project
- MicroPython Hands-on (20) - Three-axis acceleration of the control board
- CXN2000-6KVA power supply maintenance case
- Design of wireless sensor nodes based on the characteristics of wireless sensor networks
- This circuit cannot maintain constant current. Please analyze it.
- LSM6DSL 3D Accelerometer and 3D Gyroscope PCB Package and Code
- Ultrasonic Flow Measurement EVM