From 0d63eb5f6d2f94ca3507df72072d50f1c0e94698 Mon Sep 17 00:00:00 2001 From: gbcwbz Date: Thu, 14 Apr 2016 23:47:32 +0800 Subject: [PATCH] fix hardfault when RT_CAN_USING_BUS_HOOK is enabled in bsp/stm32f10x function `rt_pin_write` is invoked by function `can_bus_hook`, and it should to be initialized by gpio.c. but gpio.c was not added in SConscript --- bsp/stm32f10x/drivers/SConscript | 3 +++ bsp/stm32f10x/rtconfig.h | 2 +- components/drivers/misc/pin.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bsp/stm32f10x/drivers/SConscript b/bsp/stm32f10x/drivers/SConscript index 6be188e0f0..6a1ab42bb7 100644 --- a/bsp/stm32f10x/drivers/SConscript +++ b/bsp/stm32f10x/drivers/SConscript @@ -12,6 +12,9 @@ led.c usart.c """) +if GetDepend(['RT_USING_PIN']): + src += ['gpio.c'] + # add canbus driver. if GetDepend('RT_USING_CAN'): src += ['bxcan.c'] diff --git a/bsp/stm32f10x/rtconfig.h b/bsp/stm32f10x/rtconfig.h index 01ef716a19..f448846001 100644 --- a/bsp/stm32f10x/rtconfig.h +++ b/bsp/stm32f10x/rtconfig.h @@ -84,7 +84,7 @@ #define RT_USING_CAN -//#define RT_CAN_USING_BUS_HOOK +#define RT_CAN_USING_BUS_HOOK #define RT_CAN_USING_HDR /* SECTION: device filesystem */ diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index f3577a11d5..0a200af5aa 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -101,18 +101,21 @@ int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void /* RT-Thread Hardware PIN APIs */ void rt_pin_mode(rt_base_t pin, rt_base_t mode) { + RT_ASSERT(_hw_pin.ops != RT_NULL); _hw_pin.ops->pin_mode(&_hw_pin.parent, pin, mode); } FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_mode, pinMode, set hardware pin mode); void rt_pin_write(rt_base_t pin, rt_base_t value) { + RT_ASSERT(_hw_pin.ops != RT_NULL); _hw_pin.ops->pin_write(&_hw_pin.parent, pin, value); } FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_write, pinWrite, write value to hardware pin); int rt_pin_read(rt_base_t pin) { + RT_ASSERT(_hw_pin.ops != RT_NULL); return _hw_pin.ops->pin_read(&_hw_pin.parent, pin); } FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_read, pinRead, read status from hardware pin);