This commit is contained in:
2016-09-04 17:37:22 +02:00
parent eb8d4d07fc
commit 2093a48bed
10 changed files with 90 additions and 98 deletions
-16
View File
@@ -60,33 +60,17 @@ void MX_GPIO_Init(void)
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(RGB_DOUT_GPIO_Port, RGB_DOUT_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = LED1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = RGB_DOUT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(RGB_DOUT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* USER CODE BEGIN 2 */
+63 -3
View File
@@ -36,7 +36,53 @@
#include "stm32f1xx_it.h"
/* USER CODE BEGIN 0 */
#include "utils/debug.h"
/**
* Hard Fault diagnosis function (for use with debugger)
*
* Source:
* http://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html
*/
static void __attribute__((noreturn)) __attribute__((used))
prvGetRegistersFromStack(uint32_t *pulFaultStackAddress)
{
/* These are volatile to try and prevent the compiler/linker optimising them
away as the variables never actually get used. If the debugger won't show the
values of the variables, make them global my moving their declaration outside
of this function. */
volatile __attribute__((unused)) uint32_t r0;
volatile __attribute__((unused)) uint32_t r1;
volatile __attribute__((unused)) uint32_t r2;
volatile __attribute__((unused)) uint32_t r3;
volatile __attribute__((unused)) uint32_t r12;
volatile __attribute__((unused)) uint32_t lr; /* Link register. */
volatile __attribute__((unused)) uint32_t pc; /* Program counter. */
volatile __attribute__((unused)) uint32_t psr;/* Program status register. */
r0 = pulFaultStackAddress[ 0 ];
r1 = pulFaultStackAddress[ 1 ];
r2 = pulFaultStackAddress[ 2 ];
r3 = pulFaultStackAddress[ 3 ];
r12 = pulFaultStackAddress[ 4 ];
lr = pulFaultStackAddress[ 5 ];
pc = pulFaultStackAddress[ 6 ];
psr = pulFaultStackAddress[ 7 ];
error("Hard fault.");
dbg("r0 = 0x%08"PRIu32, r0);
dbg("r1 = 0x%08"PRIu32, r1);
dbg("r2 = 0x%08"PRIu32, r2);
dbg("r3 = 0x%08"PRIu32, r3);
dbg("r12 = 0x%08"PRIu32, r12);
dbg("LR = 0x%08"PRIu32, lr);
dbg("PC = 0x%08"PRIu32, pc);
dbg("PSR = 0x%08"PRIu32, psr);
/* When the following line is hit, the variables contain the register values. */
for (;;);
}
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
@@ -65,6 +111,20 @@ void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
// Branch to HF reporting routine
__asm volatile (
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, [r0, #24] \n"
" ldr r2, =prvGetRegistersFromStack \n"
" bx r2 \n"
);
// NOTE: Dead code follows
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
@@ -80,7 +140,7 @@ void HardFault_Handler(void)
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
error("Memory management fault.");
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
@@ -96,7 +156,7 @@ void MemManage_Handler(void)
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
error("Prefetch fault.");
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
@@ -112,7 +172,7 @@ void BusFault_Handler(void)
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
error("Usage fault.");
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{