STM32F446RE Nucleo Board の LED を点滅させようとしていました。オンボード LED は A ポートの 5 番目の PIN にあります。プログラムで次のエラーが発生し、ドライバー (gpio_drive.c) ファイルも含まれません。ここにエラーがあります。致命的なエラー: stm32f4xx_gpio_driver.c: そのようなファイルまたはディレクトリはありません
そして、それを削除してそのディレクトリなしでデバッグすると、次のエラーが発生します。
WWDG_IRQHandler() at startup_stm32f446retx.s:116 0x80002bc
Infinite_Loop: b Infinite_Loop .size Default_Handler, .-Default_Handler
メインコードは次のとおりです。
#include "stm32f4xx_gpio_driver.h"
void delay(void){
for(uint32_t i = 0; i < 5000; i++);
}
int main(void){
GPIO_Handle_t GpioLed;
GpioLed.pGPIOx = GPIOA;
GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_5;
GpioLed.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_FAST;
GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUT;
GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_OP_TYPE_PP;
GpioLed.GPIO_PinConfig.GPIO_PinPuPdControl =GPIO_NO_PUPD;
GPIO_PeriClockControl(GPIOA,ENABLE);
GPIO_Init(&GpioLed);
while(1){
GPIO_ToggleOutputPin(GPIOA,GPIO_PIN_NO_5);
delay();
}
return 0;
}
ここに私のgpio.hファイルがあります
/*
* stm32fxx_gpio_driver.h
*
* Created on: 20 Tem 2020
* Author: hkn_d
*/
#ifndef INC_STM32F4XX_GPIO_DRIVER_H_
#define INC_STM32F4XX_GPIO_DRIVER_H_
#include "stm32f4xx.h"
/*
*
* @GPIO_PIN_NUMBERS
* GPIO Possible Pin Numbers
*/
#define GPIO_PIN_NO_0 0
#define GPIO_PIN_NO_1 1
#define GPIO_PIN_NO_2 2
#define GPIO_PIN_NO_3 3
#define GPIO_PIN_NO_4 4
#define GPIO_PIN_NO_5 5
#define GPIO_PIN_NO_6 6
#define GPIO_PIN_NO_7 7
#define GPIO_PIN_NO_8 8
#define GPIO_PIN_NO_9 9
#define GPIO_PIN_NO_10 10
#define GPIO_PIN_NO_11 11
#define GPIO_PIN_NO_12 12
#define GPIO_PIN_NO_13 13
#define GPIO_PIN_NO_14 14
#define GPIO_PIN_NO_15 15
/*
*
* @GPIO_PIN_MODES
*
*
*GPIO Possible Pin Modes*/
#define GPIO_MODE_IN 0
#define GPIO_MODE_OUT 1
#define GPIO_MODE_ALTFN 2
#define GPIO_MODE_ANALOG 3
#define GPIO_MODE_IT_FT 4
#define GPIO_MODE_IT_RT 5
#define GPIO_MODE_IT_RFT 6
/*
* @GPIO_OP_TYPES
GPIO Output Types, Push Pull - Open Drain
*/
#define GPIO_OP_TYPE_PP 0
#define GPIO_OP_TYPE_OD 1
/*
* @GPIO_SPEEDS
GPIO Possible Pin Output Speeds
*/
#define GPIO_SPEED_LOW 0
#define GPIO_SPEED_MEDIUM 1
#define GPIO_SPEED_FAST 2
#define GPIO_SPEED_HIGH 3
/*
*
* @GPIO_PUPD
* GPIO Pin pull-up and pull-down configuration macros
*/
#define GPIO_NO_PUPD 0
#define GPIO_PU 1
#define GPIO_PD 2
typedef struct{
uint8_t GPIO_PinNumber; /*< Possible values from @GPIO_PIN_NUMBERS>*/
uint8_t GPIO_PinMode; /*< Possible values from @GPIO_PIN_MODES>*/
uint8_t GPIO_PinSpeed; /*< Possible values from @GPIO_SPEEDS>*/
uint8_t GPIO_PinPuPdControl; /*< Possible values from @GPIO_PUPD*/
uint8_t GPIO_PinOPType; /*< Possible values from @GPIO_OP_TYPES>*/
uint8_t GPIO_AltFunMode; /*< Possible values from @GPIO_PIN_NUMBERS>*/
}GPIO_PinConfig_t;
typedef struct {
GPIO_RegDef_t *pGPIOx; //Base address of GPIO port
GPIO_PinConfig_t GPIO_PinConfig;
}GPIO_Handle_t;
/*Init - Deinit*/
void GPIO_Init(GPIO_Handle_t *pGPIOHandle);
void GPIO_DeInit(GPIO_RegDef_t *pGPIOx);
/*Peripheral Clock Setup*/
void GPIO_PeriClockControl(GPIO_RegDef_t *pGPIOx, uint8_t EnorDis);
/*Data Read & Write*/
uint8_t GPIO_ReadFromInputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber);
uint16_t GPIO_ReadFromInputPort(GPIO_RegDef_t *pGPIOx);
void GPIO_WriteToOutputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber, uint8_t Value);
void GPIO_WriteToOutputPort(GPIO_RegDef_t *pGPIOx, uint8_t Value);
void GPIO_ToggleOutputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber);
/*IRQ Configuration and ISR handling*/
void GPIO_IRQConfig(uint8_t IRQNumber, uint8_t IRQPriority, uint8_t EnorDi);
void GPIO_IRQHandling(uint8_t PinNumber);
#endif /* INC_STM32F4XX_GPIO_DRIVER_H_ */
これは、含めることができないgpiao.cファイルです(このファイルを含めることができないため、可能性があります):
/*
* stm32f4xx_gpio_driver.c
*
* Created on: 20 Tem 2020
* Author: hkn_d
*/
#include "stm32f4xx_gpio_driver.h"
#include "stm32f4xx.h"
/*****************************************
* @fn GPIO_Inıt
*
* @brief This function initialize the GPIO on address.
*
* @param [*pGPIOHandle] Pointer of GPIO Handle Address
*
* @return none
*
* @Note none
*
*/
void GPIO_Init(GPIO_Handle_t *pGPIOHandle){
uint32_t temp;
//Deciding whether it is interrupt signal or not
if(pGPIOHandle->GPIO_PinConfig.GPIO_PinMode<=GPIO_MODE_ANALOG)
{
temp = (pGPIOHandle->GPIO_PinConfig.GPIO_PinMode << (2 *pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber));
pGPIOHandle->pGPIOx->MODER &= ~(0x3 <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->MODER |= temp;
}
else{
}
temp = 0;
temp = (pGPIOHandle->GPIO_PinConfig.GPIO_PinSpeed << (2 *pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber));
pGPIOHandle->pGPIOx->OSPEEDER &= ~(0x3 <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->OSPEEDER |= temp; //initialize speed
temp = 0;
temp = (pGPIOHandle->GPIO_PinConfig.GPIO_PinPuPdControl << (2 *pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber));
pGPIOHandle->pGPIOx->PUPDR &= ~(0x3 <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->PUPDR |= temp; //initialize pull up/push down
temp = (pGPIOHandle->GPIO_PinConfig.GPIO_PinOPType << pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber);
pGPIOHandle->pGPIOx->OTYPER &= ~(0x1 <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->OTYPER |= temp; //initialize output type (open drain, push pull)
if(temp == (pGPIOHandle->GPIO_PinConfig.GPIO_PinMode == GPIO_MODE_ALTFN)){
//Configure Alt. Functionality
uint32_t tempa;
if(pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber <= GPIO_PIN_NO_7){
tempa = (pGPIOHandle->GPIO_PinConfig.GPIO_AltFunMode << (4 *pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber));
pGPIOHandle->pGPIOx->AFRL &= ~(((0xF)) <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->AFRL |= tempa; //Alternate Function Low Registers
}
else{
tempa = 0;
tempa = (pGPIOHandle->GPIO_PinConfig.GPIO_AltFunMode << (4 *pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber));
pGPIOHandle->pGPIOx->AFRH &= ~(0xF <<pGPIOHandle->GPIO_PinConfig.GPIO_PinNumber); //Clearing Bits
pGPIOHandle->pGPIOx->AFRH |= tempa; //Alternate Function High Registers
}
}
else{
}
}
/*Interrupt part will be discussed later.
*
* @fn GPIO_Deinit
*
* @brief This function deinitializes the GPIO on address.
*
* @param[**pGPIOx] Pointer to GPIO Register Definitions
*
* @return none
*
* @Note none
*
*/
void GPIO_DeInit(GPIO_RegDef_t *pGPIOx){
if(pGPIOx == GPIOA)
{
GPIOA_REG_RESET();
}
else if(pGPIOx == GPIOC){
GPIOC_REG_RESET();
}
else if(pGPIOx == GPIOD){
GPIOD_REG_RESET();
}
else if(pGPIOx == GPIOE){
GPIOE_REG_RESET();
}
else if(pGPIOx == GPIOF){
GPIOF_REG_RESET();
}
else if(pGPIOx == GPIOG){
GPIOG_REG_RESET();
}
else if(pGPIOx == GPIOH){
GPIOH_REG_RESET();
}
else if(pGPIOx == GPIOB){
GPIOB_REG_RESET();
}
}
/*****************************************
* @fn GPIO_PeriClockControl
*
* @brief This function controls GPIO peripheral clock.
*
* @param1[**pGPIOx] Pointer to GPIO Register Definitions
*
* @param2[EnorDis] ENABLE or DISABLE macros
*
* @return none
*
* @Note none
*
*/
void GPIO_PeriClockControl(GPIO_RegDef_t *pGPIOx, uint8_t EnorDi){
if(EnorDi == ENABLE){
if(pGPIOx == GPIOA)
{
GPIOA_PCLOCK_EN();
}
else if(pGPIOx == GPIOC){
GPIOC_PCLOCK_EN();
}
else if(pGPIOx == GPIOD){
GPIOD_PCLOCK_EN();
}
else if(pGPIOx == GPIOE){
GPIOE_PCLOCK_EN();
}
else if(pGPIOx == GPIOF){
GPIOF_PCLOCK_EN();
}
else if(pGPIOx == GPIOG){
GPIOG_PCLOCK_EN();
}
else if(pGPIOx == GPIOH){
GPIOH_PCLOCK_EN();
}
else if(pGPIOx == GPIOB){
GPIOB_PCLOCK_EN();
}
}
else{
if(pGPIOx == GPIOA)
{
GPIOA_PCLOCK_DI();
}
else if(pGPIOx == GPIOC){
GPIOC_PCLOCK_DI();
}
else if(pGPIOx == GPIOD){
GPIOD_PCLOCK_DI();
}
else if(pGPIOx == GPIOE){
GPIOE_PCLOCK_DI();
}
else if(pGPIOx == GPIOF){
GPIOF_PCLOCK_DI();
}
else if(pGPIOx == GPIOG){
GPIOG_PCLOCK_DI();
}
else if(pGPIOx == GPIOH){
GPIOH_PCLOCK_DI();
}
else if(pGPIOx == GPIOB){
GPIOB_PCLOCK_DI();
}
}
}
/*****************************************
* @fn GPIO_ReadFromInputPin
*
* @brief This function reads from the decided pin.
*
* @param1[*pGPIOx] Pointer to GPIO Register Definitions
*
* @param2[PinNumber] ENABLE or DISABLE macros
*
* @return uint8_t
*
* @Note none
*
*/
uint8_t GPIO_ReadFromInputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber){
uint8_t value;
value = (uint8_t) ((pGPIOx->IDR >> PinNumber) & 0x00000001);
return value;
}
/*****************************************
* @fn PIO_ReadFromInputPort
*
* @brief This function reads from the decided port.
*
* @param1[*pGPIOx] Pointer to GPIO Register Definitions
*
*
* @return uint16_t
*
* @Note none
*
*/
uint16_t GPIO_ReadFromInputPort(GPIO_RegDef_t *pGPIOx){
uint16_t value;
value = (uint16_t) pGPIOx->IDR;
return value;
}
/*****************************************
* @fn GPIO_WriteToOutputPin
*
* @brief This function writes to the decided output pin.
*
* @param1[*pGPIOx] Pointer to GPIO Register Definitions
*
* @param2[PinNumber] 8 bit variable for Pin Number
*
* @param3[Value] Value to be written
*
* @return none
*
* @Note none
*
*/
void GPIO_WriteToOutputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber, uint8_t Value){
if(Value == GPIO_PIN_SET){
pGPIOx->ODR |= ( 1<<PinNumber);
}
else{
pGPIOx->ODR &= ~( 1<<PinNumber);
}
}
/*****************************************
* @fn GPIO_WriteToOutputPort
*
* @brief This function writes to the decided output port.
*
* @param1[*pGPIOx] Pointer to GPIO Register Definitions
*
* @param2[Value] Value to be written
*
* @return none
*
* @Note none
*
*/
void GPIO_WriteToOutputPort(GPIO_RegDef_t *pGPIOx, uint8_t Value){
pGPIOx->ODR = Value;
}
/*****************************************
* @fn GPIO_ToggleOutputPin
*
* @brief This function toggles the decided pin.
*
* @param1[*pGPIOx] Pointer to GPIO Register Definitions
*
* @param2[PinNumber] 8 bit variable for Pin Number
*
* @return none
*
* @Note none
*
*/
void GPIO_ToggleOutputPin(GPIO_RegDef_t *pGPIOx, uint8_t PinNumber){
(pGPIOx->ODR) = (pGPIOx->ODR ^ ( 1 << PinNumber));
}