Usually the reasons why our program runs out of control are as follows:
1. memset/ memcpy usage error
error code
aucCpyLength=NAME_DATA_LENGTH- ((wucCdTextCmdBufferPara.stTagCmdPara.ucPageNo+1)*TAG_PAGE_LENGTH);
memset(pucCpyDestAdress + TAG_PAGE_LENGTH,0x00,aucCpyLength)
where: NAME_DATA_LENGTH is 64
TAG_PAGE_LENGTH is 10
wrong reason
Since the variable wucCdTextCmdBufferPara.stTagCmdPara.ucPageNo is 6, aucCpyLength=64-70=0xFA. Since the memset function is called later, the contents of the 0xFA addresses starting from the pucCpyDestAdress address are all rewritten to 0, resulting in pointer variable calculation errors during engine control and pointing to illegal areas, eventually causing the program to run away.
Solution
1 Before calling the memset function, perform error tolerance on the maximum range of length to avoid other variables being modified due to length exceeding
the range .
2 Review the variables involved in length calculation to avoid assigning out-of-range values in the program.
Method example
if(NAME_DATA_LENGTH>= ((wucCdTextCmdBufferPara.stTagCmdPara.ucPageNo+1)* TAG_PAGE_LENGTH ))
{
aucCpyLength=NAME_DATA_LENGTH- ((wucCdTextCmdBufferPara.stTagCmdPara.ucPageNo+1)*TAG_PAGE_LENGTH);
memset(pucCpyDestAdress+ TAG_PAGE_LENGTH,0x00,aucCpyLength);
}
2 Pointer usage error
Error code
INT8U* pucCDMode;
CDDRV_L1_wvdGetCDMP3Mode(pucCDMode);
Function prototype void CDDRV_L1_wvdGetCDMP3Mode(INT8U* pucCDMode)
Error reason Pointer pucCDMode is used without being initialized.
Solution
1 Initialize the pointer pucCDMode
2 Use automatic variables and perform operations through the addresses of automatic variables.
Method example
INT8U pucCDMode;
CDDRV_L1_wvdGetCDMP3Mode(&pucCDMode);
3 Array control error { When nuiBTDrvOnePacketDataSize is larger than the size of the nucBTDrvReceiveSaveBuffer array, that is, nuiBTDrvOnePacketDataSize>200, the content after the address of nucBTDrvReceiveSaveBuffer+200 will be overwritten, eventually causing the program to run away. When the size of the acquired data exceeds the size range specified by the communication array, the erroneous data is discarded or other corresponding processing is performed. In other words, when assigning values to the array, it is necessary to determine whether it exceeds the range, and if it exceeds the range, corresponding processing is performed. Add fault tolerance before the wrong code.
error code
for(nuiBTDrvUartRcvSvCnt=REC_DATA_CMDID_ADDR1; nuiBTDrvUartRcvSvCnt
nucBTDrvReceiveSaveBuffer[nuiBTDrvUartRcvSvCnt] =nucBTUartReceiveBuffer[nuiBTDrvUartRcvRp];
nuiBTDrvUartRcvRp++;
if(nuiBTDrvUartRcvRp >= RECEIVE_DATA_LENGTH_MAX){
nuiBTDrvUartRcvRp = BT_DRV_NULL;
}
}
The nucBTDrvReceiveSaveBuffer size is defined as 200
wrong reason
This situation will only occur when there is an interference signal in BT communication.
Solution
Method Example
if(nuiBTDrvOnePacketDataSize >= RECEIVE_DATA_PROC_LENGTH)
{
nuiBTDrvOnePacketDataSize = RECEIVE_DATA_PROC_LENGTH;
}
Previous article:The reason why the microcontroller program runs away
Next article:Research on Debugging Programs in RAM of MSP430
- 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
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to minimize the cost of low-power AC/DC circuits?
- The water hydrogen engine has officially rolled off the production line. The vehicle can run just by adding water???
- Synopsys IP Resources: A look at the complete Ethernet PHY IP for high-performance computing SoCs
- [National Technology N32 MCU Development Package] --N32G4FR Series
- CC3220 Wireless MCU LaunchPad Development Kit Design
- 422 Driver Output Level
- NB-IoT application classification and technical characteristics analysis
- "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 2. Chapter 2 Bias Current
- I2C Timing
- CUBEMX configures six-step square wave drive BLDC