2015-08-24 09:46:15 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Eistec AB
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-01 15:04:44 +02:00
|
|
|
* @ingroup tests
|
2015-08-24 09:46:15 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Minimal test application for triggering a hard fault or equivalent
|
|
|
|
*
|
|
|
|
* @author Joakim Gebart <joakim.gebart@eistec.se>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <xtimer.h>
|
|
|
|
|
|
|
|
#ifndef FORBIDDEN_ADDRESS
|
|
|
|
/* Many platforms do not allow writes to address 0x00000000 */
|
2021-03-23 09:23:03 +01:00
|
|
|
#define FORBIDDEN_ADDRESS (0x00000000u)
|
2015-08-24 09:46:15 +02:00
|
|
|
#endif /* !defined(FORBIDDEN_ADDRESS) */
|
|
|
|
#ifndef INVALID_INSTRUCTION
|
|
|
|
/* Random garbage may crash the program as well. */
|
2016-03-14 14:28:00 +01:00
|
|
|
#define INVALID_INSTRUCTION __asm__ volatile (".short 0xdead, 0xbeef, 0xcafe, 0xbabe\n")
|
2015-08-24 09:46:15 +02:00
|
|
|
#endif /* !defined(INVALID_INSTRUCTION) */
|
|
|
|
|
|
|
|
#define PRINT_MACRO(a) PRINT_MACRO2(a)
|
|
|
|
#define PRINT_MACRO2(a) #a
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
puts("Fault handler test application");
|
2021-11-25 11:03:58 +01:00
|
|
|
printf("This application will crash by attempting to write to address 0x%08x\n",
|
|
|
|
FORBIDDEN_ADDRESS);
|
2015-08-24 09:46:15 +02:00
|
|
|
puts("Waiting 1 second before crashing...");
|
2021-03-23 09:23:03 +01:00
|
|
|
xtimer_usleep(1000000lu);
|
2015-08-24 09:46:15 +02:00
|
|
|
puts("Write to forbidden address " PRINT_MACRO(FORBIDDEN_ADDRESS));
|
2021-11-25 11:03:58 +01:00
|
|
|
/* cppcheck-suppress nullPointer */
|
2021-03-23 09:23:03 +01:00
|
|
|
*((volatile unsigned int *) FORBIDDEN_ADDRESS) = 12345u;
|
2021-11-25 11:03:58 +01:00
|
|
|
/* cppcheck-suppress nullPointer */
|
2021-03-23 09:23:03 +01:00
|
|
|
unsigned int readback = *((volatile unsigned int *) FORBIDDEN_ADDRESS);
|
2015-08-24 09:46:15 +02:00
|
|
|
printf("readback: 0x%08x\n", readback);
|
|
|
|
puts("We did not expect the application to survive the previous write.");
|
|
|
|
puts("Trying to execute an invalid instruction");
|
|
|
|
puts(PRINT_MACRO(INVALID_INSTRUCTION));
|
|
|
|
INVALID_INSTRUCTION;
|
|
|
|
puts("Failed to crash the program, hanging...");
|
2021-11-25 11:03:58 +01:00
|
|
|
while (1) {}
|
2015-08-24 09:46:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|