STM32 DFU Programming

January 25th, 2010 8 comments

The time is currently 21:42 and I’ve been sitting in front of my computer in 2 hours to get the DFU programming to work.

Now it is working, and I’m able to make one of my excisting projects into a DFU loadable project (compiled it’s a .dfu filed)

I’ve also changed the DFU bootloader code to use GPIOA_0 as DFU Enable pin, and GPIOA_1 as USB Disconnect – this makes me able to use the GPIOB and GPIOC for my display without any interferrance!

Here is how you make a Ride7 project DFU loadable:

The Default Startup script (in settings) has been set to No, as we have included a special startup script in the project (startup_stm32f10x_hd.s – found in CMSIS\Core\CM3\startup\gcc)
Also change the Linker Script in project settings to match the processor group you are using (Connectivity, High Density… and so on – fx stm32f10x_hd_flash_offset.ld)
Also be aware of the change in the NVIC_Configuration – here we tell the processor that the Flash has to start at adress 0x3000
When you have compiled the code to a HEX file, run “DFU File Manager” to create a .dfu file.
Target ID: 00 is Internal Flash
Target ID: 01 is SPI Flash
Target ID: 02 is NOR Flash
Now you can use DfuSe to load the .dfu file into the internal flash of your STM32!
Categories: ARM Tags: ,

STM32 USB Connection

January 25th, 2010 8 comments

The USB connection between the STM32 and the computer is finally working.
I’ve tried the different USB programs from the StdPeriph Library

Fx.

  • Virtual COM Port
  • DFU Programming

As I’m using Ride7 for programming, I can upload the project and sources if you want me too.

 

OBS: If you have projects which DOESN’T use the USB, you have to set the USB Disconnect jupmer to Ground (Pos. 1-2), as if not, the STM32 will stop in some kind of USB Interrupt trying to make a data communication with the computer, but it never comes as the STM32 doesn’t start one!

I discovered this รƒ?ร‚ย when I tried DFU’ing my 320×240 LCD code – and when I went back to normal .hex, it didn’t work – that was because I had to set the USB Disconnect to Ground!

Categories: ARM Tags: , , ,

STM32 Peripheral Notes

January 18th, 2010 No comments

Got some sensors hooked up to my header board.
The code is ugly and needs work, but gets data from stuff.

UART1@115200 = ft232 USB adapter (todo change to internal usb) – for debugging
UART2@9600 = SFE 16×2 SerLCD (For Display)
I2C1@100KHz = TMP102 (temperature) and HMC6352 (compass)

TMP102:

Compatible with LM75
TIe ADD0 to GND for default address 0x90
I just grabbed the LM75 stuff from ST’s STM32103B EVAL Demo kit (tsensor.h/c) and ripped out the LCD stuff – TODO work on formatting, return types, etc

HMC6352:

Get Heading: Send 0x41 (‘A’) and read in two bytes of data / 10 for decimal degrees

I think I like I2C, this was all entirely too easy ๐Ÿ™‚

TODO: Improvements so maybe I can post some code, and should do a driver for the ADXL345 accelerometer.

New Gyro, Cam, LCD on the way to figure out as well.

Categories: ARM Tags:

STM32 Buildchain

January 10th, 2010 No comments

So I’m quite frustrated with trying to roll my own arm-elf- toolchain. Building it was easy enough, but getting the options right is proving to be challenging. I managed to work through all the hard/soft FPU stuff with newlib, and got things to compile, but still some linker warnings/errors that result in the app crashing on the hardware. One day I’ll learn to debug and look into this more.

In the meantime, even though the download link for it is quite well hidden, I have discovered that I am quite happy with Codesourcery’s G++ Lite edition. It includes the GNU ARM buildchain, along with some of their proprietary tools (so no, I can’t mirror it ๐Ÿ™ ) as an unsupported command line only free version with a license that looks very reasonable to me, so I’m pretty comfortable working with it. Thanks to those responsible for make the Lite version exist, now if only we could get an arm buildchain in the repos…

To save you the trouble of accidentally downloading their full suite trial edition like I did (feel free to purchase it if you want an IDE and other tools), here is a link to the downloads:
http://www.codesourcery.com/sgpp/lite/arm/portal/subscription?@template=lite
You will want to select the EABI (first) link (unless you need a different target OS, which for an STM you probably don’t)
The first links for the Installer are the easiest to use, everything is packaged in a Java installer to extract and setup your path, make links, etc)

I’ve been using Randomskk’s STM32 Skeleton project Randomskk’s GitHub, he has a rather nice blinking LED example in there (I had to change the LED pin for my board and fixup the Makefile to have tabs, but that was all painless).

Now to see if I can get FreeRTOS to build under arm-none-eabi – what fun, doesn’t look like it will be trivial based on the errors I’m getting so far, but I can’t imagine it should be too bad.

Categories: ARM Tags:

Bizarreness

January 10th, 2010 No comments

So we all know that GSM phones can induce various sounds in unshielded amplified speakers, but ever have one take over control of your machine?

I recently got a new Blackberry 8320 and switched it from T-Mobile to AT&T (work phone). Whats fun is that when I set it down to the right of my keyboard (by the mouse and my Polycom) my cursor starts doing strange and interesting things when its radio is active – cursor movement, right clicks/half-clicks, etc – just weirdness. Now if this were an RF mouse or something, sure, but this is a wired, USB, optical mouse, which makes it seem odd. Any theories? Anyone know if optical mice have an ADC anywhere in the input chain?

Categories: TKJ Electronics Tags:

STM32 OpenOCD Config

January 10th, 2010 No comments

Below is the openocd config I am currently using with my STM32 (Olimex STM32 header board from SFE) to program through the JTAG header on the board. Randomskk had better scripts, but they didn’t want to behave for me. Its rather minimal, but it does the job. TODO: integrate changes back into the skeleton project.

Tested on FC10/FC11 with openocd 0.3.1

GIves some weird warning know – run with sudo openocd -f thisfile.cfg 2>&1 | grep -v khz for readable output (filters the repetitious warning)

telnet_port 4444
gdb_port 3333

interface parport
parport_port 0
parport_cable wiggler

jtag_khz 1000
jtag_speed 0

source [find board/olimex_stm32_h103.cfg]

init
reset halt
stm32x mass_erase 0
#flash write_image main.elf 0 elf
#verify_image jtag/flash.elf 0 elf
flash write_bank 0 main.bin 0
verify_image main.bin 0 bin
reset run
shutdown
Categories: ARM Tags:

WiFi SMS Gateway

September 5th, 2009 10 comments

After a long search on the internet, trying to find a cheap SMS Gateway, I got the idea to create one myself.
As I already had a GM862 module laying around, and I’ve got the WiShield WiFi module for the Arduino too, I thought it would be easy – but it wasn’t!

The hardware setup is pretty easy, except the powering for the GM862, as it requires about 3.8V. That was made with a Linear LT1528 3A low dropout voltage regulator.
After alot of testing and measuring, I finally made a working circuit, and afterwards an Eagle Schematic.

WiFi SMS Gateway - Schematic

WiFi SMS Gateway - Schematic

รƒ?ร‚ย 

In the following picture you will see the hardware setup, which consists of the Arduino with the WiShield on the top, the GM862 on two breadboards, and alot of wires!

WiFi SMS Gateway - Hardware

WiFi SMS Gateway - Hardware

รƒ?ร‚ย 

But the real problems appeared when I started programming! I had alot of troubles with the serial connection between the Arduino and the GM862 module, which apparently wasn’t caused by the hardware setup!

รƒ?ร‚ย 
After alot of debugging I figured it out, and a simple SMS sending code was working ๐Ÿ™‚
Then after a couple of hours I’ve added the WiFi parsing code which sends an SMS to the requested number, with the requested message, read from the GET parameters!

You can grab the code here, and try it out:

/*
 * WiFi SMS Gateway sketch by Thomas Jespersen - http://elec.tkjweb.dk/blog
 * --- Remeber to change the PIN, if any, in the setup() routine! ---
 */

#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,111};	// IP address of WiShield
unsigned char gateway_ip[] = {192,168,2,254};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"};		// max 32 bytes


unsigned char security_type = 0;	// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"Passphrase"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
				};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------

//unsigned byte TimeBeforeConnection;

unsigned int lastSMStime = 0;

   char number[7];
   char* message;

void sendSMS() {
  if (millis()/1000 > lastSMStime) {
    Serial.print("AT+CMGF=1\r\n");
    delay(500);
    Serial.print("AT+CMGS=");
    delay(250);
    for (int i=0; i < 8; i++) {
      Serial.print(number[i]);
    }
    //Serial.print(number);
    // Replace with a valid phone number
    Serial.print("\r\n");
    delay(2500);
    Serial.print(message);
    delay(500);

    // End the SMS with a control-z
    Serial.print(0x1A,BYTE);
    lastSMStime = (millis()/1000) + 2;
  }
}

// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {

    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("<head><title>TKJ's SMS Gateway</title>");
        WiServer.print("<h1>This is TKJ's SMS Gateway</h1><br>");
        WiServer.print("</html>");

        // URL was recognized
        return true;
    }

    // Check if the requested URL starts with "/?"
    if (URL[0] == '/' && URL[1] == '?') {
        for (int i=0; i<8; i++) {
          number[i] = '0';
        }
        message = "";

        for (int i=0; i < 8; i++) {
          number[i] = URL[i+2];
        }
        for (int i=0; i < strlen(URL); i++) {
          message[i] = URL[i+10];
        }

        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("<head><title>TKJ's SMS Gateway</title>");
        WiServer.print("<h1>The SMS is now sent!</h1><br><p>");
        //WiServer.print(message);
        WiServer.print("</p>");
        WiServer.print("</html>");

        sendSMS();

        // URL was recognized
        return true;
    }

    // URL not found
    return false;
}

void setup() {
  // Turn GSM Module ON
  pinMode(3, OUTPUT);
  digitalWrite(3, HIGH);
  delay(500);
  digitalWrite(3, LOW);
  delay(500);
  digitalWrite(3, HIGH);
  delay(1000);

  // Type Mobile SIM Pin Code
  Serial.begin(9600);
  // Remember to change the PIN, if any
  Serial.print("AT+CPIN=0000\r\n");

  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);

  // Enable Serial output and ask WiServer to generate log messages (optional)
  WiServer.enableVerboseMode(false);

}

void loop(){

  // Run WiServer
  WiServer.server_task();
  delay(10);
}


Categories: Arduino Tags: , , , , ,

RFID Modded Safe

June 20th, 2009 3 comments

This project is about my RFID Modded Safe.

I’ve modded an old electronic toy-safe, which is unlocked by typing the 4-char password.

RFID Modded Safe

RFID Modded Safe

I’ve unsoldered the locking-mechanism from the circuitboard, and connected it to the Arduino instead.

Locking-Mechanism Hack

Locking-Mechanism Hack

Then I connected a ID-20 RFID Reader to the Arduino and programmed it to read the tag, and see if it was allowed to enter the safe.

ID-20 RFID Reader

ID-20 RFID Reader

If it was allowed, the Arduino will keep the safe unlocked in 3 seconds!

I’ve also made this video to show how it works:
httphd://www.youtube.com/watch?v=oxuD–7wWE8

You can grab the code here, and try it out:

#include <NewSoftSerial.h>

NewSoftSerial ID12(5,6);
//                RX,TX

// RFID reader ID-12 for Arduino
// Based on code by BARRAGAN
// and code from HC Gilje - http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/
// Modified for Arudino by djmatic
// Modified for ID-12 and checksum by Martijn The - http://www.martijnthe.nl/
//
// Use the drawings from HC Gilje to wire up the ID-12.
// Remark: disconnect the rx serial wire to the ID-12 when uploading the sketch


void setup() {
  Serial.begin(9600);                                 // connect to the serial port
  ID12.begin(9600);
  pinMode(12, OUTPUT);
}

void loop () {
  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(ID12.available() > 0) {
    if((val = ID12.read()) == 2) {                  // check for header
      bytesread = 0;
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if( ID12.available() > 0) {
          val = ID12.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading
            break;                                    // stop reading
          }

          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }

          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        }
      }

      // Output to Serial:

      if (bytesread == 12) {                          // if 12 digit read is complete
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();

        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();

        if (code[0] == 0x01 && code[1] == 0x07 && code[2] == 0x7A && code[3] == 0x21 && code[4] == 0xD9 && code[5] == checksum) {
          Serial.println("Case Unlocked by User1");
          digitalWrite(12, HIGH);
          delay(3000);
          Serial.println("Case Locked");
          digitalWrite(12, LOW);
        }
        if (code[0] == 0x01 && code[1] == 0x07 && code[2] == 0x7A && code[3] == 0x1A && code[4] == 0xBA && code[5] == checksum) {
          Serial.println("Case Unlocked by User2");
          digitalWrite(12, HIGH);
          delay(3000);
          Serial.println("Case Locked");
          digitalWrite(12, LOW);
        }
      }

      bytesread = 0;
    }
  }
}

Categories: Arduino Tags: , , , , , , ,

Ethernet TV

After my last success with the Serial TV, I’ve got the idea making it possible for you to the television using a browser.

I’m still using my Serial TV, but now it’s connected to an Arduino instead of the computer. The Arduino has an Ethernet Shield on top, and it’s programmed to make a homepage with a text-field and a submit button!

Here is some pictures of the project:

Ethernet TV - Full

Ethernet TV - Full


Ethernet TV - Arduino

Ethernet TV - Arduino


Ethernet TV - iphone

Ethernet TV - iphone


Ethernet TV - iphone + TV

Ethernet TV - iphone + TV


Ethernet TV - Test Text

Ethernet TV - Test Text

Categories: Arduino, PIC Tags: , , ,

Serial PAL TV

Finally I’ve finished my Serial TV project.
It uses a PIC18F4620 running 32 Mhz (8 Mhz crystal + HS PLL), so I’m using the EasyPIC5 for the testing. It is also possible to use other PIC’s, but the available TV Pixel lines will be reduced, caused by the limited RAM.

First I’m going to give alot of the credit to Bruno from Micro-Examples, as I’ve used his PAL TV Code: http://www.micro-examples.com/public/microex-navig/doc/089-pic-pal-tv

Then I’ve wrote some extra code, to make it possible, to write text strings to the television, via a serial communication.

You can download the MikroC project here: Serial TV – MikroC

Here is some pictures of the project:

Serial TV - EasyPIC5

Serial TV - EasyPIC5


Composite Video Resistor Array

Composite Video Resistor Array


Serial TV - Test Text

Serial TV - Test Text

Categories: PIC Tags: , ,