Getting userinput in STM32F4Discovery using ChibiOS RTOS

To get user input in STM32F4Discovery..chnage directory to the concerned folder

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

edit the main.c file and insert this code

#include "ch.h"
#include "hal.h"

int main(void) {

halInit();
chSysInit();

palSetPadMode(GPIOD,4, PAL_MODE_INPUT);
palSetPadMode(GPIOD,6, PAL_MODE_OUTPUT_PUSHPULL);

while (TRUE) {
int x;
x=palReadPad(GPIOD,4);
if (x){
palSetPad(GPIOD, 6);
}
else{
palClearPad(GPIOD, 6);
}

}
}

Here GPIOD pin4 is set as input and pin6 is set as output….I connected a button to 5v and the out of the button is connected to  pin4 which is set as input whenever i press the button pin4 becomes high and whenever pin4 becomes high pin6 becomes high an led is connected to pin6 to know the user button action…

to generate binary

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

make

st-flash write build/ch.bin 0x08000000

Happy Hacking 🙂

STM32F4Discovery GPIO Programming using ChibiOS RTOS

To use the gpio pins…

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

Similar to the earlier method edit the main.c file and insert this code

#include "ch.h"
#include "hal.h"
int main(void) {
halInit();
chSysInit();
palSetPadMode(GPIOD, 4, PAL_MODE_OUTPUT_PUSHPULL); /* PD4 */
while (TRUE) {
palSetPad(GPIOD, 4);
chThdSleepMilliseconds(500);
palClearPad(GPIOD, 4);
chThdSleepMilliseconds(500);
}
}

The palSetPadMode configures PD4 or GPIOD’s fourth pin as output..now connect an led to the PD4 and see output

Now repeat the older steps to generate binary

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

make

st-flash write build/ch.bin 0x08000000

Happy Hacking 🙂

Getting started with STM32F4Discovery and ChibiOS

ChibiOS is a portable,open source RTOS…ChibiOS can be downloaded from source forge

http://sourceforge.net/projects/chibios/

Extract the downloaded file..Inside the folder you can see a folder named Demos inside that our board will be listed ARMCM4-STM32F407-DISCOVERY inside that folder there will be a main.c….Edit that main.c file

#include "ch.h"
#include "hal.h"

int main(void) {

halInit();
chSysInit();

palSetPadMode(GPIOD, GPIOD_LED4, PAL_MODE_OUTPUT_PUSHPULL); /* Green. */

while (TRUE) {
palSetPad(GPIOD, GPIOD_LED4);
chThdSleepMilliseconds(500);
palClearPad(GPIOD, GPIOD_LED4);
chThdSleepMilliseconds(500);
}
}

palSetPadMode configure the I/O as input or output….palSetPad and  palClearPad is similar to High and Low…halinit is the intialization of hardware abstraction layer and chsysinit is the intialization of kernel…

Open a terminal and change directory to that folder

cd ChibiOS_2.4.1/demos/ARMCM4-STM32F407-DISCOVERY/

make

st-flash write build/ch.bin 0x08000000

Happy Hacking 🙂

STM32F4Discovery first IO Toggle example

Now we are trying to run our first led blinking example..

cd  ~/stm32build/stlink_texane/

Download the examples

wget http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32f4discovery_fw.zip

Unzip it

unzip stm32f4discovery_fw.zip

Download the Make files

wget http://jthomson.towhee.org/stm32f4discovery_files/STM32F4DISCOVERY_Makefiles.zip

Unzip the make files

unzip STM32F4DISCOVERY_Makefiles.zip

cd ~/stm32build/stlink_texane/STM32F4DISCOVERY_Makefiles

Copy the Makefile to Example directory

cp Makefile.IO_Toggle ~/stm32build/stlink_texane/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/IO_Toggle/

cd ~/stm32build/stlink_texane/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/IO_Toggle

Build the project

make -f Makefile.IO_Toggle

flash the program to STM32F4Discovery board

st-flash write IO_Toggle.bin 0x8000000

Press reset button we can see LED’s flashing…. 🙂

Building the JTAG comunication tool STLINK

STLINK is open source software to program and debug ST’s STM32 Discovery kits. Those kits have an onboard chip that translates USB commands sent by the host PC into JTAG/SWD commands.

sudo apt-get install libusb-1.0-0-dev

This is the previously created directory for building purposes

 cd  ~/stm32build
git clone git://github.com/texane/stlink.git stlink_texane
cd stm32build/stlink_texane/

./autogen.sh
./configure

make

If everything went ok we will binaries of st-flash and st-util

 

 

 

 

add the binaries to .bashrc using export command

connect the board to the system..in theJtag communication part we can see power and one another led islighted up in red color…open up a terminal and issue the command

#st-util

It detects the hardware and listens to the port and we can see the jtag led turns green when board is detected

Getting started with STM32F4Discovery in Gnu/Linux

 

Building Toolchain

To compile code for STM32F4Discovery we need to setup ARM Toolchain in our system whichsupport ARM Cortex M3.I used summon ARM toolchain which is available in github

https://github.com/esden/summon-arm-toolchain.git

First install the dependencies in our system

sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev 
libmpc-dev autoconf texinfo build-essential libftdi-dev

We should also do this too

sudo apt-get build-dep gcc-4.5

Make a directory somewhere to do the whole build process i made a folder named stm32build in home directory

mkdir  ~/stm32build
cd  ~/stm32build

clone the summon-arm- toolchain

git clone https://github.com/esden/summon-arm-toolchain.git
cd summon-arm-toolchain

read the README  befor begining the build

$./summon-arm-toolchain LIBSTM32_EN=1

While building the toolchain i got an error on gdb like this

 

to fix this error i edited the summon-arm-toolchain file

 

 

 

 

 

 

I changed the GDB names from the default code and restarted the build and it worked fine.After final installation the output was like this

 

 

 

 

 

 

 

 

 

When the installation is completed afolder named sat will be created in your system insidethat folder there will bea bin folder where all the binaries will be located

 

 

 

 

export all these binaries to your $PATH so that we can acess it everywhere.

export PATH=~/sat/bin:$PATH

Add this to the end of your .bashrc file

So the toolchain is ready now…. 🙂