Showing posts with label firmware. Show all posts
Showing posts with label firmware. Show all posts

Sunday, March 3, 2013

SD Card library and example on olimexino stm32

Today I tried to configure SD card library and run examples on olimexino stm32. This will use the microSD card slot on board. You can read more about micro SD card on Wikipedia here.

Maple IDE can be used to program the board. Download Maple IDE.

I downloaded SDCARD library and examples - Maple SDCARD_Lib + Examples MapleIDE leaflabs forums.



Olimexino stm32 board front side picture

Olimexino stm32 board back side pictrure with microSD card slot visible

I download the files from the above link. Unzipped the files to a folder and copied the two unzipped folders to the /libraries/ folder in my Maple IDE installation folder. There is a readme.txt file in the unzipped  folder. 
Sdcard I used is in fat16 format.How to Format a Fat16 SD Card

I used a Sandisk micro sdcard of 2GB and inserted it into the card slot at the back of the board.
Lets start with an example. I fired the Maple IDE. Then selected the my first example by selecting File -> Examples -.SdFat -> MapleExamples -> SDFatInfo.

Maple STM32 SDFatFileInfo example selection File -> Examples -.SdFat -> MapleExamples -> SDFatInfo.


As easy as it gets I pressed Ctrl+R key to compile the code. When the example code is compiled it also compiles the library files.
Then pressed Ctrl+U to upload the code to the maple Olimexino stm32 board.

Once the code is uploaded then to see the card information on the serial port in Maple itself select Tools -> Serial port or Ctrl+Shift+M keys to open Serial Monitor window.
In the text bar next to 'Send' button entered a character (I pressed 'a') and clicked 'Send'.

SDFatFileInfo Serial Monitor output

I could see lots of card info. How simple. And I have not done any coding for sdcard yet:).
So as a next step I wanted to see the above info on Microsoft HyperTerminal instead of the Maple build in Serial Monitor.

So I closed the Serial monitor window, and opened HyperTerminal. Opened a new connection, gave a name for the connection, selected the com port where the stm32 board is connected,  selected the baud  rate as per the settings shown in the figure here.
Olimexino STM32 hyperteminal settings


Then when connected pressed any key("a") in my case on the keyboard.
Olimexino STM32 SDFatFileInfo hyperterminal output

Here is the output.

Now that I get card info, I tried a few examples for file read and write already in the SDCard library and examples for Maple that we download earlier. I found a simple example to write file and read a file on a microSD Card.

I fired my Maple IDE. Then started the example by selecting File -> Examples -.SdFat -> SDClass -> ReadWrite.

Compiled the code (Ctrl+R), then uploaded firmware to stm32 board (Ctrl+U).
Fired my HyperTerminal at 115200 baud rate. Pressed a key on the keyboard and got the following output




It shows that initialization of SDCard was done successfully, write to file test.txt was successful. The read back of file contents and display on the serial port is also complete.

That was so easy to read and write to a SDCard. Now I can write my own programs to use SD library and examples. There are lots of other examples available in the library and should be easy to to implement modify in any application.

This blog is not meant to be a manual so if you find any mistakes please point out to me. If any one has any comments/feedback please post. Also if you find the information useful please link to my blog.

Over the next few blogs I will be writing on using temperature sensors and XBEE's. I am also looking at Jeenode and Seeeduino Stalker v2.3

Tuesday, February 19, 2013

Olimexino-STM32 Hello World example

After the first blink example on OLIMEXINO-STM32 board using the MAPLE ide, the next and obvious example is "Hello World". I have modified the Blink without delay example available in Maple and added Serial code.
The serial output will be available on the SerialUSB port through the mini usb cable connected to the PC. In addition to three serial ports, the Maple’s STM32 microprocessor includes a dedicated USB peripheral. This peripheral is used to emulate a regular serial port for use as a terminal. The emulated terminal is relatively slow; it is best for transferring data at regular serial speeds (kilobaud).
Library access to the emulated serial port is provided through the SerialUSB object. You can mostly use SerialUSB as a drop-in replacement for Serial1, Serial2, and Serial3.

The baud rate by default is 115200.

Here is the code. Copy it to a blank sketch and compile.


/*
  Hello World -Blink without delay
  Send out "Hello World" over SerialUsb port at 115200 baud rate.
  Turns on and off the built-in light emitting diode (LED), without
  using the delay() function.  This means that other code can run at
  the same time without being interrupted by the LED code.

  created 2005
  by David A. Mellis
  modified 17 Jun 2009
  by Tom Igoe
  modified for Maple 27 May 2011
  by Marti Bolivar
  Modified by Jaime Fernandes 17 Feb 2013
  Uses the inbuilt millis() function to get time elapsed in milliseconds
*/

// Variables:
int previousMillis = 0;        // will store the last time the LED was updated
int interval = 1000;            // interval at which to blink (in milliseconds)

void setup() {
    // Set up the built-in LED pin as output:
    pinMode(BOARD_LED_PIN, OUTPUT);

   
    //Send Hello World string over serial port
    SerialUSB.println("Hello World");
}

void loop() {
// Check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time we blinked
// the LED is bigger than the interval at which we want to blink
// the LED.
// Every time the led is toggled serial port sends out 
// a "Toggled LED" message

// millis function information
    if (millis() - previousMillis > interval) {
        // Save the last time you blinked the LED
        previousMillis = millis();
        // If the LED is off, turn it on, and vice-versa:
        toggleLED();
        SerialUSB.println("Toggled LED");
    }
}


If compile is successful, download to the stm32 board. Refer to my previous post to see how to compile the code and download to the board. To see the output, on the menu bar select Tools -> Serial Monitor. Once the code runs you should see BOARD_LED_PIN (green LED) being toggled every (interval)milliseconds. The serial port should also display "Toggled LED" message.