2021-09-11 01:10 PM
Hi,
I am a student who has recently started working with STM8s MCU's. Currently I am working with an STM8s207K8 Nucleo 32 development board, I am using STVD along with a cosmic toolchain to program my dev board. I am able to program the microcontroller successfully using the standard peripheral library, however when I am trying to create a custom driver the compiler throws an error stating that it can not open the specific header file, this happens when I try to add the inc and src files to the the already existing SPL files, and when I create a new folder of custom drivers and create two sub folders for inc and src files the compiler throws around 15 errors, I am attaching screenshots of the error here and also pasting the header and source files of the custom UART driver that I am trying to create.
Below is the header file for the UART driver
/********************/
//uart_driver.h
#ifndef UART_H
#define UART_H
/* Initialization */
void uart_init(uint32_t baud_rate);
/* Send Character */
void uart_send_char(uint8_t data);
/* Receive Character */
uint8_t uart_rec_char(void);
#endif
/********************/
Below is the source file for the UART driver
/********************/
//uart_driver.c
#include <uart_driver.h>
/* Initialization */
void uart_init(uint32_t baud_rate)
{
UART3_DeInit();
UART3_Init(baud_rate, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE);
}
/* Send Character */
void uart_send_char(uint8_t data)
{
while (UART3_GetFlagStatus(UART3_FLAG_TXE) == RESET); //Checks if data transmission is stopped
UART3_SendData8(data);
}
/* Receive Character */
uint8_t uart_rec_char(void)
{
uint8_t data;
while (UART3_GetFlagStatus(UART3_FLAG_RXNE) == RESET); //Checks if data is received
data = UART3_ReceiveData8();
return data;
}
/********************/
I would really appreciate it if someone could help me resolve my problem
Thanks
Solved! Go to Solution.
2021-09-12 01:57 PM
Hi, I have identified the problem and deployed a solution as well now. All the paths were set up correctly, and I tried using the library in the specified form as well but it was not successful, apparently you have to include the stm8s.h library in your header file as well as in your main c code. I suppose the #include "stm8s.h" file also acts as the board specific header file, the absence of which in the uart_driver header file was causing a compilation error. I have tested this by creating another driver for clock configurations and delay functions which are also working fine. Thanks for your help though it gave me the necessary idea to guide me to a particular solution. I will paste the code along with this message here so that someone else who might be struggling with this issue can find a solution and refer to the code as example.
/**********uart_driver.h**********/
#include "stm8s.h"
#ifndef UART_H
#define UART_H
/* Initialization */
void uart_init(uint32_t baud_rate);
/* Send Character */
void uart_send_char(uint8_t data);
/* Receive Character */
uint8_t uart_rec_char(void);
#endif
/********************/
/**********uart_driver.c**********/
#include <uart_driver.h>
/* Initialization */
void uart_init(uint32_t baud_rate)
{
UART3_DeInit();
UART3_Init(baud_rate, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE);
}
/* Send Character */
void uart_send_char(uint8_t data)
{
while (UART3_GetFlagStatus(UART3_FLAG_TXE) == RESET); //Checks if data transmission is stopped
UART3_SendData8(data);
}
/* Receive Character */
uint8_t uart_rec_char(void)
{
uint8_t data;
while (UART3_GetFlagStatus(UART3_FLAG_RXNE) == RESET); //Checks if data is received
data = UART3_ReceiveData8();
return data;
}
/********************/
Thanks
2021-09-12 09:08 AM
Start with the first error
Perhaps make sure you #include all the definitions and libraries the code in your uart_driver.c needs
2021-09-12 11:35 AM
Hi I included the #include "stm8s.h" library in the uart_driver.c file however is is still showing one of the same errors which it was displaying yesterday, that is compiler can't open uart_driver.h. Another issue that I noticed was that once I compiled the code the uart_driver.h file disappeared from the External Dependencies folder.
2021-09-12 12:47 PM
Ok, so you'd likely need to make sure the include paths point to the directory the file is situated in.
or use the #include "uart_driver.h" form if it is in the same directory as the .C file
2021-09-12 01:57 PM
Hi, I have identified the problem and deployed a solution as well now. All the paths were set up correctly, and I tried using the library in the specified form as well but it was not successful, apparently you have to include the stm8s.h library in your header file as well as in your main c code. I suppose the #include "stm8s.h" file also acts as the board specific header file, the absence of which in the uart_driver header file was causing a compilation error. I have tested this by creating another driver for clock configurations and delay functions which are also working fine. Thanks for your help though it gave me the necessary idea to guide me to a particular solution. I will paste the code along with this message here so that someone else who might be struggling with this issue can find a solution and refer to the code as example.
/**********uart_driver.h**********/
#include "stm8s.h"
#ifndef UART_H
#define UART_H
/* Initialization */
void uart_init(uint32_t baud_rate);
/* Send Character */
void uart_send_char(uint8_t data);
/* Receive Character */
uint8_t uart_rec_char(void);
#endif
/********************/
/**********uart_driver.c**********/
#include <uart_driver.h>
/* Initialization */
void uart_init(uint32_t baud_rate)
{
UART3_DeInit();
UART3_Init(baud_rate, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE);
}
/* Send Character */
void uart_send_char(uint8_t data)
{
while (UART3_GetFlagStatus(UART3_FLAG_TXE) == RESET); //Checks if data transmission is stopped
UART3_SendData8(data);
}
/* Receive Character */
uint8_t uart_rec_char(void)
{
uint8_t data;
while (UART3_GetFlagStatus(UART3_FLAG_RXNE) == RESET); //Checks if data is received
data = UART3_ReceiveData8();
return data;
}
/********************/
Thanks