STM32F765意外复位

时间:2017-07-24 18:31:59

标签: c reset stm32 cube

我通过UART进行通信的简单代码。问题是微控制器在0.5秒后重新启动。所以在这种情况下,我只看到" StartStartStart ..."在我的航站楼。

有人知道如何解决这个问题吗?

的main.c

#include "main.h"

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef Uart1Handle;
DMA_HandleTypeDef hdma_usart1_rx;
DMA_HandleTypeDef hdma_usart1_tx;
GPIO_InitTypeDef gpio_init_structure;

/* Buffer used for transmission */
uint8_t aTxStartMessage[] = "Hello World";
uint8_t aTxEndMessage[] = "\n\r Example Finished\n\r";

/* Buffer used for reception */
uint8_t aRxBuffer[RXBUFFERSIZE];

/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void CPU_CACHE_Enable(void);
static void Error_Handler(void);

int main(void) {
    CPU_CACHE_Enable();
    HAL_Init();
    SystemClock_Config();

    LED_Init(LED1);
    COM_Init(COM1, &Uart1Handle, 9600);

    uint8_t message1[] = "Start";

//  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
//  HAL_NVIC_EnableIRQ(USART1_IRQn);
    HAL_UART_Transmit(&Uart1Handle, (uint8_t *) message1, strlen(message1), 0xFFFF);

    while (HAL_UART_GetState(&Uart1Handle) != HAL_UART_STATE_READY) {
    }


    while (1) {
        HAL_Delay(100);
    }
}

功能

void COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart, uint16_t bautrate) {
    GPIO_InitTypeDef gpio_init_structure;

    /* Enable GPIO clock */
    SIM100_COMx_CLK_ENABLE(COM);
    /* Enable USART clock */
    SIM100_COMx_GPIO_CLK_ENABLE(COM);

    /* Configure USART as alternate function */
    gpio_init_structure.Pin = COM_PIN[COM];
    gpio_init_structure.Mode = GPIO_MODE_AF_PP;
    gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH;
    gpio_init_structure.Pull = GPIO_PULLUP;
    gpio_init_structure.Alternate = COM_AF[COM];
    HAL_GPIO_Init(COM_PORT[COM], &gpio_init_structure);

    huart->Instance = COM_USART[COM];
    huart->Init.BaudRate = bautrate;
    huart->Init.WordLength = UART_WORDLENGTH_8B;
    huart->Init.StopBits = UART_STOPBITS_1;
    huart->Init.Parity = UART_PARITY_NONE;
    huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart->Init.Mode = UART_MODE_TX_RX;
    huart->Init.OverSampling = UART_OVERSAMPLING_16;

    HAL_UART_Init(huart);
}

void LED_Init(Led_TypeDef Led) {
    GPIO_InitTypeDef GPIO_InitStruct;

    /* Enable the GPIO_LED clock */
    LEDx_GPIO_CLK_ENABLE(Led);

    /* Configure the GPIO_LED pin */
    GPIO_InitStruct.Pin = GPIO_PIN[Led];
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

    HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);

    /* By default, turn off LED */
    HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);

}

0 个答案:

没有答案