Closed
Description
The Environment
- Mbed LPC1768 on an Embedded Artists base board.
- LPCXpresso v5.2.4 [Build 2122].
- Using CAN2, LEDs and serial I/O interfaces.
The Problem
Hardfault interrupt on LPC1768 when attaching a callback function to a CAN object and only one CAN object is defined.
How to Reproduce
Run the following app on an mbed LPC1768 . Note the blue LEDs of death as HardFault_Handler() is called.
#include "mbed.h" BusOut myleds(LED1, LED2, LED3, LED4); CAN can2(p30, p29); bool got_message = false; extern "C" void HardFault_Handler () { error("Hit HardFault handler!\r\n"); } void can_callback() { got_message = true; } int main() { CANMessage msg; printf("main()\n"); can2.attach(can_callback, CAN::RxIrq); int i = 0; while(1) { printf("loop()\n"); if (got_message) { got_message = false; can2.read(msg); printf("Message received: %d\n", msg.data[0]); } wait(0.2); myleds = i++; i %= 16; } }
The Workaround
Create a second unused CAN object
CAN can1(p9, p10);
and run the app again. The app now works OK.
The Cause
Checking IER on both CAN peripheral modules when only one of them is enabled causes a hard fault.
The error is in function can_irq_set(), at line 167 of file …/mbed/targets/hal/TARGET_NXP/TARGET_LPC176x/can_api.c.
Metadata
Metadata
Assignees
Labels
No labels