This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hard fault- bus fault - driver lack time delay or ccs optimization level problem...

I am using tm4c123g mcu, when power up  it may drive a led up which can be seen easily to indicate running status. But sometimes(1/4 chances) it can not run.

Soon we find the mcu runs into hard fault and get the ti SPMA043.pdf  to solve the problem with a near result from driver context:

//! \note It takes five clock cycles after the write to enable a peripheral
//! before the the peripheral is actually enabled. During this time, attempts
//! to access the peripheral result in a bus fault. Care should be taken
//! to ensure that the peripheral is not accessed during this brief time
//! period.
//!
//! \return None.
//
//*****************************************************************************
void
SysCtlPeripheralEnable(unsigned long ulPeripheral)

When we add a little delay in SysCtlPeripheralEnable, the Hard fault- bus fault did not appear when we tested 50 times;

Also, when we changed the CCS V5.2.1  optimization level  -O2 --opt_for_speed=5 to none, the problem seems also disappeared.

I've checked the latest driver lib and find no changes about it.

So, advices please!

  • This question should go to the TM4C forum. After you call SysCtlPeripheralEnable(unsigned long ulPeripheral) to enable the peripheral, you should call SysCtlPeripheralReady() to make sure that the peripheral is ready before accessing the peripheral.

    Thanks and regards,

    Zhaohong