主函数代码如下:
#include <stdio.h>
#include "gd32c10x.h"
#include "main.h"
/* 异常中断栈内容结构体*/
typedef struct
{
uint32_t LR_hardfault;
uint32_t R4;
uint32_t R5;
uint32_t R6;
uint32_t R7;
uint32_t R8;
uint32_t R9;
uint32_t R10;
uint32_t R11;
uint32_t R0;
uint32_t R1;
uint32_t R2;
uint32_t R3;
uint32_t R12;
uint32_t LR;
uint32_t PC;
uint32_t xPSR;
}Hard_Fault_Typedef;
uint8_t c[1024]={0};
uint32_t *p=(uint32_t*)0x20ffffff;
/*hardfault stack information output function*/
void hw_fault_printf(Hard_Fault_Typedef* hard_fault)
{
printf("LR_hardfault: 0x%x\n",hard_fault->LR_hardfault);
printf("R4: 0x%x\n",hard_fault->R4);
printf("R5: 0x%x\n",hard_fault->R5);
printf("R6: 0x%x\n",hard_fault->R6);
printf("R7: 0x%x\n",hard_fault->R7);
printf("R8: 0x%x\n",hard_fault->R8);
printf("R9: 0x%x\n",hard_fault->R9);
printf("R10: 0x%x\n",hard_fault->R10);
printf("R11: 0x%x\n",hard_fault->R11);
printf("R0: 0x%x\n",hard_fault->R0);
printf("R1: 0x%x\n",hard_fault->R1);
printf("R2: 0x%x\n",hard_fault->R2);
printf("R3: 0x%x\n",hard_fault->R3);
printf("R12: 0x%x\n",hard_fault->R12);
printf("LR: 0x%x\n",hard_fault->LR);
printf("PC: 0x%x\n",hard_fault->PC);
printf("xPSR: 0x%x\n",hard_fault->xPSR);
}
/*usart configure function*/
void USART_init(void)
{
rcu_periph_clock_enable(RCU_USART0);
/*enable COM GPIO clock USART0*/
rcu_periph_clock_enable(RCU_GPIOA);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_9);
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ,GPIO_PIN_10);
usart_deinit(USART0);
usart_baudrate_set(USART0, 115200U);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
usart_enable(USART0);
}
/*taskA function*/
void task_A(void)
{
task_B();
}
/*taskB function*/
void task_B(void)
{
task_C(1);
}
uint8_t task_C(uint8_t data)
{
*p=2;
c[10]=data;
return 100/data;
}
/*taskC function*/
int main(void)
{
USART_init();
task_A();
while(1)
{
}
}
int fputc(int ch, FILE *f)
{
while (RESET == usart_flag_get(USART0, USART_FLAG_TBE));
usart_data_transmit(USART0, (uint8_t) ch);
return ch;
}
|
———————————————— 版权声明:本文为CSDN博主「木子芯双」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_31446727/article/details/125709280