This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Hard fault exception using RTOS and retargetting semihosting

Hi,

I've run into a strange problem using cmsis_os (keil rtx), retargetting of semi-hosting to uart, and interrupts.

I have a simple project set up to use cmsis-rtos (importing rtx_cm4.lib) and uart rx interrupts (using the stm32f4xx hal libraries). Using microlib everything works fine, but as soon as I move to retargetting semihosting (using basically just the retarget.c file from keil) I end up in the hardfault handler.

My code for main is just:

int main()
{
  // initialise the real time kernel
  osKernelInitialize();

  // we need to initialise the hal library and set up the SystemCoreClock
  // properly
  HAL_Init();
  configure_168MHz();

  // set up the uart (with rx interrupts enabled)
  init_uart(9600);
  enable_rx_interrupt();

  // print a status message
  printf("we are alive!\r\n");

  // start everything running
  osKernelStart();
}

and I get the "we are alive!" message displayed on the uart, but as soon as I type anything into the uart window, the uart rx interrupt triggers and then dumps me into the hardfault handler. However, there isn't much information in the registers. This is what I get:

in hard fault handler
SCB->HFSR  = 0x40000000
SCB->CFSR  = 0x00000000
SCB->MMFAR = 0xe000ed34
SCB->BFAR  = 0xe000ed38

stack dump:
SP         = 0x20001d40
R0         = 0x20001730
R1         = 0x0000ffff
R2         = 0x080005ed
R3         = 0x0000000a
R12        = 0x0800425d
LR         = 0x080038ef
PC         = 0x08000ac0
PSR        = 0x21000057

So I can tell I have ended up with a forced hard fault, but the CFSR register is empty so I can't tell what caused it.

Could anybody give me any pointers here? The same code works with no rtos, and the same code works with no retargetting - just not with both rtos and retargetting!

Thanks for your time!

Alex

Parents Reply Children