There you can find Libraries for your STM32 projects that is written in bare-metal method.
I'm still working on this ...
currently you can find these libraries in my repository:
- aryana_GPIO.h
- aryana_ADC.h
- aryana_SysTickDelay.h
- aryana_LCD16x2_4bit.h
- aryana_Keypad4x4.h
In the following ,you can find the instructions about each libraries that i wrote. so fill free to look at them ...
at first , you must include your propper stm32fyxx.h library to your project.
( for example if you use stm32f401re you should include stm32f4xx.h)
- this library has the following functions:
- enable Portx's clock
aryana_GPIOx_Enable(char PortName)
- Set Port x Pin i as Input
aryana_GPIOx_PINiSetMode_INPUT(char PortName,unsigned int pin)
- Set Port x Pin i as Output
aryana_GPIOx_PINiSetMode_OUT(char PortName,unsigned int pin)
- Set Port x Pin i Low (0)
aryana_GPIOx_PINi_Low(char PortName,unsigned int pin)
- Set Port x Pin i High (1)
aryana_GPIOx_PINi_High(char PortName,unsigned int pin)
- set value of Port x pin i 0 or 1
aryana_GPIOx_PINi_Write(char PortName,unsigned int pin,int bit)
- read entire Portx's value and write it to {int* PortInputValue_Array}
aryana_GPIOx_Read(char PortName,int* PortInputValue_Array)
- HOW TO USE
- enable GPIOx by aryana_GPIOx_Enable(char PortName)
- set GPIOx Pin i as input or out put
- use any funtcion as you need... :)
- GPIO example Blinking LED
#include <stm32f4xx.h>
#include <aryana_GPIO.h>
#define LED_PORT 'A'
#define LED_PIN 2
int main(void)
{
aryana_GPIOx_Enable(LED_PORT) ;
aryana_GPIOx_PINiSetMode_OUT(LED_PORT,LED_PIN)'
while(1)
{
aryana_GPIOx_PINi_High(LED_PORT,LED_PIN);
for(int i=0;i<6000 <i++);
aryana_GPIOx_PINi_LOW(LED_PORT,LED_PIN);
for(int i=0;i<6000 <i++);
}
}
- this library has the following functions:
sysTickDelay_ms(int delay_ms)
sysTickDelay_us(int delay_us)
- this library has the following functions:
- config LCD's GPIO pins and turn it on in 4 bit mod
LCD_Initialaze();
- send command to LCD
LCD_command(unsigned char command);
- send single character to LCD
LCD_data_Character(unsigned char command)
4.send string to LCD
LCD_data_String(char string[]);
- HOW TO USE
- first edit the following macros to match the Hardware
#define LCD_port 'A'
#define LCD_RS_pin 4
#define LCD_RW_pin 5
#define LCD_EN_pin 6
- use LCD_Initialize() function to config GPIO and Run LCD in 4 bit mode
- use LCD_command or LCD_Data functions as you wish... :)
this library has the following functions:
- initialize KeyPad
KeyPad_Init(void)
- listen to the KeyPad . if any keys is pressed by the user , KeyPad_flag will become 1 .
KeyPad_Listen_InsideLoop()
3.find the Row And Col of the Keypad's key that is pressed. the row and col value is stord in these variables : int KeyPad_PressedRow int KeyPad_PressedCol
*use this function after KeyPad_Listen_InsideLoop() as the example .
KeyPad_RowColFinder()
- HOW TO USE
- first edit the following macros and array to match the Hardware
#define KeyPad_port 'C' // 'A' or 'B' or 'C' or 'D'
#define KeyPad_row1Pin 0
#define KeyPad_row2Pin 1
#define KeyPad_row3Pin 2
#define KeyPad_row4Pin 3
#define KeyPad_col1Pin 4
#define KeyPad_col2Pin 5
#define KeyPad_col3Pin 6
#define KeyPad_col4Pin 7
char KeyPad_ArrayCharacters[16] = {'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'};
- initialize KeyPad
KeyPad_Init(void)
- do as the following example.
example
#include <stm32f4xx.h>
#include "aryana_GPIO.h"
#include "aryana_SysTickDelay.h"
#include "aryana_Keypad4x4.h"
#include "aryana_LCD16x2_4bit.h"
int main()
{
LCD_Initialaze();
KeyPad_Init();
while (1)
{
KeyPad_Listen_InsideLoop();
KeyPad_RowColFinder();
//now col and row is been found ... do your things....
if(KeyPad_flag==1){
LCD_data_Character(KeyPad_ArrayCharacters[(4*KeyPad_PressedRow) + (KeyPad_PressedCol)]);
KeyPad_flag=0;
sysTickDelay_ms(2000);
}
////-----------------------------------------------
KeyPad_ResetPins();
}
}