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 🙂

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…. 🙂