Add assert macros to aid in debugging.
Adds libopencm3/cm3/assert.h header that provides assertion check macros similar to those provided by the standard C library. Thanks to Nicolas Schodet for help.
This commit is contained in:
34
lib/cm3/assert.c
Normal file
34
lib/cm3/assert.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the libopencm3 project.
|
||||
*
|
||||
* Copyright (C) 2012 Tomaz Solc <tomaz.solc@tablix.org>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/cm3/assert.h>
|
||||
|
||||
void __attribute__((weak)) cm3_assert_failed(void)
|
||||
{
|
||||
while(1);
|
||||
}
|
||||
|
||||
void __attribute__((weak)) cm3_assert_failed_verbose(
|
||||
const char *file __attribute__((unused)),
|
||||
int line __attribute__((unused)),
|
||||
const char *func __attribute__((unused)),
|
||||
const char *assert_expr __attribute__((unused)))
|
||||
{
|
||||
cm3_assert_failed();
|
||||
}
|
||||
@@ -28,8 +28,8 @@ CFLAGS = -Os -g -Wall -Wextra -I../../include -fno-common \
|
||||
-ffunction-sections -fdata-sections -MD
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
OBJS = gpio.o vector.o
|
||||
OBJS = gpio.o vector.o assert.o
|
||||
|
||||
# VPATH += ../usb
|
||||
VPATH += ../cm3
|
||||
|
||||
include ../Makefile.include
|
||||
|
||||
@@ -28,8 +28,8 @@ CFLAGS = -Os -g -Wall -Wextra -I../../include -fno-common \
|
||||
-ffunction-sections -fdata-sections -MD
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
OBJS = gpio.o
|
||||
OBJS = gpio.o assert.o
|
||||
|
||||
# VPATH += ../usb
|
||||
VPATH += ../cm3
|
||||
|
||||
include ../Makefile.include
|
||||
|
||||
@@ -28,8 +28,8 @@ CFLAGS = -O0 -g -Wall -Wextra -I../../include -fno-common \
|
||||
-ffunction-sections -fdata-sections -MD
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
OBJS = gpio.o vector.o
|
||||
OBJS = gpio.o vector.o assert.o
|
||||
|
||||
# VPATH += ../usb
|
||||
VPATH += ../cm3
|
||||
|
||||
include ../Makefile.include
|
||||
|
||||
@@ -31,8 +31,9 @@ CFLAGS = -O2 -g3 -Wall -Wextra -I../../include -fno-common \
|
||||
-mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
OBJS = gpio.o vector.o scu.o i2c.o ssp.o nvic.o systick.o
|
||||
OBJS = gpio.o vector.o scu.o i2c.o ssp.o nvic.o systick.o \
|
||||
assert.o
|
||||
|
||||
# VPATH += ../usb
|
||||
VPATH += ../cm3
|
||||
|
||||
include ../Makefile.include
|
||||
|
||||
@@ -31,9 +31,9 @@ ARFLAGS = rcs
|
||||
OBJS = vector.o rcc.o gpio.o usart.o adc.o spi.o flash.o nvic.o \
|
||||
rtc.o i2c.o dma.o systick.o exti.o scb.o ethernet.o \
|
||||
usb_f103.o usb.o usb_control.o usb_standard.o can.o \
|
||||
timer.o usb_f107.o desig.o crc.o
|
||||
timer.o usb_f107.o desig.o crc.o assert.o
|
||||
|
||||
VPATH += ../../usb:../
|
||||
VPATH += ../../usb:../:../../cm3
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
/**@{*/
|
||||
|
||||
#include <libopencm3/cm3/assert.h>
|
||||
#include <libopencm3/stm32/f1/rcc.h>
|
||||
#include <libopencm3/stm32/f1/flash.h>
|
||||
|
||||
@@ -166,8 +167,7 @@ int rcc_osc_ready_int_flag(osc_t osc)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shouldn't be reached. */
|
||||
return -1;
|
||||
cm3_assert_not_reached();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
@@ -29,8 +29,8 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
|
||||
# ARFLAGS = rcsv
|
||||
ARFLAGS = rcs
|
||||
OBJS = vector.o rcc.o gpio.o usart.o spi.o flash.o nvic.o \
|
||||
i2c.o systick.o exti.o scb.o timer.o \
|
||||
i2c.o systick.o exti.o scb.o timer.o assert.o
|
||||
|
||||
VPATH += ../../usb:../
|
||||
VPATH += ../../usb:../:../../cm3
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/cm3/assert.h>
|
||||
#include <libopencm3/stm32/f2/rcc.h>
|
||||
#include <libopencm3/stm32/f2/flash.h>
|
||||
|
||||
@@ -125,8 +126,7 @@ int rcc_osc_ready_int_flag(osc_t osc)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shouldn't be reached. */
|
||||
return -1;
|
||||
cm3_assert_not_reached();
|
||||
}
|
||||
|
||||
void rcc_css_int_clear(void)
|
||||
|
||||
@@ -31,7 +31,8 @@ ARFLAGS = rcs
|
||||
OBJS = vector.o rcc.o gpio.o usart.o spi.o flash.o nvic.o \
|
||||
i2c.o systick.o exti.o scb.o pwr.o timer.o \
|
||||
usb.o usb_standard.o usb_control.o usb_f107.o \
|
||||
assert.o
|
||||
|
||||
VPATH += ../../usb:../
|
||||
VPATH += ../../usb:../:../../cm3
|
||||
|
||||
include ../../Makefile.include
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libopencm3/cm3/assert.h>
|
||||
#include <libopencm3/stm32/f4/rcc.h>
|
||||
#include <libopencm3/stm32/f4/pwr.h>
|
||||
#include <libopencm3/stm32/f4/flash.h>
|
||||
@@ -139,8 +140,7 @@ int rcc_osc_ready_int_flag(osc_t osc)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Shouldn't be reached. */
|
||||
return -1;
|
||||
cm3_assert_not_reached();
|
||||
}
|
||||
|
||||
void rcc_css_int_clear(void)
|
||||
|
||||
Reference in New Issue
Block a user