Move to 32 bits ARM core
Recently I moved my projects to 32 bits ARM way. After some time thinking about various platforms, I’ve decide to abandon any Windows based tool, and trying to work only with Mac, without Parallels Desktop. For small 8 or 16 bits PIC projects, I still use MPLABX. For ARM core I’ve decide to use STM32 series.
As development tool I’ve chosen Rowley CrossWorks. They have a reasonably price for non-commercial use ($150) and the most important, a Mac Os Lion version. I’ve also bought some STM32 boards, and in that post I’ll show my steps with one of them: STM32L-DISCOVERY. The other boards I also have are STM32F4-DISCOVERY and WaveShare Port103R (great board! post more later).
STM32L-DISCOVERY Development Board
The STM32L-DISCOVERY helps you to discover the STM32L ultra low power features and to develop and share your applications.
It is based on an STM32L152RBT6 and includes an ST-Link/V2 embedded debugging tool interface, a LCD (24 segments, 4 commons), LEDs, push buttons, a linear touch sensor or touch keys.
Recent version of Rowley CrossWorks for ARM added support for ST-Link/V2 programmers, so you can connect STM32L-DISCOVERY board directly to your Mac and start ARM developing.
Environment preparation steps
To work with STM32L-DISCOVERY board in CrossWorks, we’ll need to do some preparations:
- Install CrossWorks “STMicroelectronics STM32 CPU Support Package”:
- Choose “Tools” menu, then “Package Manager…“
- In search box, write “STM32 CPU Support”
- Double click to change action to “Install”
- Install the “STM32L-DISCOVERY firmware package” (version 1.0.2):
- You’ll need to download it from the ST website;
- Unfortunately, ST doesn’t have a Mac friendly package. You will see that it’s a Windows “.exe” that install it under Program Files/STMicroelectronics directory.
- But you’re lucky. I’ve already unpack it and share over my dropbox account. Click here and unpack it on your CrossWorks projects directory.
CrossWorks project creation steps
- Creating a new STM32 project:
- Select menu “File“, then “New Project” menu item.
- Select the “STMicroelectronics” from the Categories list.
- Select the executable for STMicroelectronics STM32 from the Templates list.
- Enter the name of your project: AN3413-Current_consumption_touch_sensing
- Enter the location of your project. Create a new folder under “STM32L_Discovery_Firmware_Pack_V1.0.2/Projects/AN3413-Current_consumption_touch_sensing/CrossWorks/“
- Select the Target Processor as STM32L152RB. You can finish it from here.
- Next. Uncheck “main.c” (you don’t need that auto-generated file)
- Include Preprocessor Definitions
- Select menu “Project“, then “Properties…” menu item. The Project Manager window appears.
- Select View: Properties, Properties: All, Grouping: Categorize, Configuration: Common
- Navigating on “Settings:” and find “Preprocessor Options“
- In “Preprocessor Definitions“, include the following:
- Don’t close Project Manager window, yet.
- The “User Include Directories” uses project directory in path reference. Now we are going to include the various library include paths (.h):
- In “User Include Directories”, include the following:
- $(TargetsDir)/CMSIS_3/CMSIS/Include (necessary after after STM32 Support Package 2.14, see release notes)
- In “User Include Directories”, include the following:
- Go to Project Explorer to add the project source files (.c):
- Expand the Project
- Tap with two fingers in “Source Files”, chose “Add Existing file…”
- Add the files:
- Create a “Utilities” folder under Project ‘AN3413-Current_consumption_touch_sensing’ (Tap with two fingers and “New folder…”)
- Make it a Dynamic folder (Tap with two fingers on “Utilities” folder, then “Dynamic folder…”)
- In Directory, use “../../../Utilities/STM32L-DISCOVERY” (or navigate and find it on you STM32L_Discovery_Firmware_Pack_V1.0.2 folder)
- Create a “STM32L1xx_StdPeriph_Driver” folder, make it Dynamic, point it to “../../../Libraries/STM32L1xx_StdPeriph_Driver/src/“
- Create a “STM32_TouchSensing_Driver” folder, make it Dynamic, point it to “../../../Libraries/STM32_TouchSensing_Driver/src/“
- Your project Items need to look like this (“System Files” folder is automatically added):
At this point we can build that solution. Click on “Build” menu, then “Build AN3413-Current…” . You’ll see a little devil error like that:
Well, one fix at time. Let’s start with the message:
- THUMB Debug/AN3413-Current_consumption_touch_sensing.elf section `.DataFlash’ will not fit in region `UNPLACED_SECTIONS’
– region `UNPLACED_SECTIONS’ overflowed by 2 bytes
There’s nothing about “UNPLACED_SECTIONS” under CrossWorks for ARM Reference manual, so I’ve been opened a trouble ticket for CrossWorks support team. They are very smart and always catch what you need (if you provide them all the details).
According to support, the variable is being placed in a “.DataFlash” section which needs to be allocated into the EEPROM segment. “UNPLACED_SECTIONS” exists to catch errors when sections haven’t been placed. (Thank’s Michael Johnson from Rowley!).
And, if you look at Symbol Browser (“Tools” menu) you’ll find the “.DataFlash” 2 bytes section on the range:
Reading STM32L152RB datasheet, in the memory map section it confirms it’s the EEPROM region, so they are right. But that ugly name “.DataFlash” makes me believe that it’s Flash Memory related. Bad name, bad name…
They told me how to initialize it:
- Tap two fingers in Project ‘AN3413-Current_consumption_touch_sensing’ and select “Import Section Placement” to get a project local copy of the section placement file “flash_placement.xml“.
- Tap two fingers on file “flash_placement.xml” and select “Open With” then “Code Editor“.
Add a new segment:
<MemorySegment name="EEPROM" > <ProgramSection alignment="4" load="No" name=".DataFlash" /> </MemorySegment>
After that, your file looks like that:
Let’s work on the rest errors:
- THUMB Debug/stm32l15x_tsl_ct_acquisition.o: In function `TSL_IO_Acquisition_P1′:
– undefined reference to `__TSL_wait_CLWHTA’
– undefined reference to `__TSL_wait_CLWLTA’
A double click in that lines let you go to “stm32l15x_tsl_ct_acquisition.c” source file, from STM32_TouchSensing_Driver. Let’s do a search on it, looking for “__TSL_wait_CLWHTA“, and you’ll find the follow piece of code:
So, your problem is here: “__INLINE” isn’t supported by CrossWorks. Remove only the “__INLINE” and repeat it for “__TSL_wait_CLWLTA” function. Now, Clean and Rebuild the entire solution. That’s it! Compile Ok!
Running it on board!
Connect the STM32L-DISCOVERY board to your Mac.
- Select “Target“, “Connect…“, then select ST/LINK-V2;
- In Properties Window, select “Target Interface Type: SWD“;
- Target, Download it to board and see… it’s works!
If you want my entire project files, you download it on my downloads page. Unpack it under your CrossWorks project directory. These files contains all my entire folder.
Next post I’ll show how to compiling the other example, AN3964-Temperature_sensor.
One thing that all us need know is that the project power requirements not only besides on efficiency and quality. Efficiency and quality are subjective terms and you (like me) break and open some market products, you’ll found some really dirty way to power up a electronic device.
Well, with that in mind I’m working in power my Samsung Infrared Decoder with a transformerless power supply. Transformerless Power Supplies, instead of use regular transformer-rectifier circuit or switched power circuitry, use direct coupling of AC line to passive components, like resistors and capacitors, to obtain a desired voltage. Yes, it’s a very dangerous idea, but you can control it and minimize risks too.
Some projects are really cheaper, and don’t require much power. Think in a microcontroller circuit that do the following things:
- Wake-up from sleeping;
- Reading temperature (ADC);
- Transmit it (802.3.15.4);
- Return to sleep;
These steps doesn’t require more that 20mA (aprox), and most market components are cheaper. But if you want to really make this cheaper and smaller, a transformer/wall adapter supply it’s a big monster. The bad news is that transformerless power supplies, not only are dangerous but less current capable of other supplies. If you need more than a few mA, your circuit will be exposed to a great risk.
The two basic types of transformerless power supplies are resistive and capacitive. You can view nice example after Google it. My idea it’s use a capacitive version. My circuit simulation is based on bellow (ignore V2 for now, I’ll explain it later):
The main rule to keep in mind is that “R1” and “XC1” (capacitive reactance) are the only input current limiters. So, more current, need other values. The other rule is to keep the supply working: keep output current requirements less than input current calculated. See:
We need to resolve the input voltage in terms of RMS (Root Mean Square) value. The voltage is the RMS value of a half-wave, because D2 rectifies it. So:
Put all it together to resolve:
I’ve chosen values to meet approximately 5V@20mA. The RMS voltage value in Brazil is 127V. The frequency is 60Hz. The zener used have 5.1V drop across.
For circuit simulation I’ve used MacSpice, a great Berkeley Spice 3f5 clone. In this circuit you view another voltage source (V2) with zero voltage output. That’s a way to measure output current on transient analysis on Spice. You can download my circuit file for run your own simulation here. The results are:
The voltage drop on zener diode and common diode D2 is determinant for output voltage. In really, I never reach desired 5V output because of voltage drop across D2. But it’s ok, most modern microcontrollers operate on a wide range of voltages. The output voltage is given by:
The next step is test a real circuit with real load. So long I’ve news, I’ll post them here.
Remember again that transformerless power supplies are naturally unsafety. After decide make that circuit, and finish it, you have in your hands live AC voltage very close to low power electronics, with is a great danger. Stay as advised.
Well, I can’t finish the PCB for this project yet (I’m planning make it with a Transformerless Power Supply), but I’m posting the Microchip C18 code for all that want work with this protocol.
Please, visit my download page.
I had ear some time ago that laziness sometimes is the best thing for inspiration. That week I discover that’s true. Some nights, I lay on my bed to watch some thing on TV and doing some electronic research, before sleep. And, I don’t like to put off the lights (effficient ilumination is the best friend for a good reading) . Then, obviously, before sleep, I need to stand up to turn lights off. At my side, on bed, always resides a great remote control TV, with a set of unused buttons, telling “use us to turn the lights off“.
That’s a project that I was retarding because other, but now I decide to initiate and finish it.
The Basic Idea
The first step is recognize what my remote control is send to TV. It’s a Samsung remote control, with TV, VCR, DVD and STB specific and shared functions. My basic idea is: use some of this unused buttons to turn the lighst ON and OFF. But, why not dimmer the lamp? Why not doing some other useful thing? (Yes, thats because some projects growing up…)
So, the basic idea now is:
- Make a device that recognize when a command is addressed to it self or not;
- Recognize different commands;
- Save usuful states (dimmer regulation);
The Internet has a lot of information about RC5, NEC and Sony IR protocols, but not the same for Samsung. After some search at Google, I found this usefull page with some information about Samsung IR protocol. Resuming Samsung protocol:
- 37.9KHz carrier wave (ON state is a burst of carrier with some duration, OFF is absense of it);
- 1 Start bit (4.5ms ON, and 4.5ms OFF);
- 32 data bits stream (data + address?);
- bit “1″ (590μs ON, 1690μs OFF) (thanks to Islam qabel, for the more precise bit duration);
- bit “0″ (590μs ON, 590μs OFF);
- 1 Stop bit (590μs ON, 590μs OFF);
I think that more information only with a test.
The test circuit is very simple, consisting on a IR receiver (with filter, carrier demodulation and output). My only device available at home is a TSOP2236. Well, let’s go see what hapens.
TSOP2236 is a dedicated IR receiver with PIN diode and preamplifier, assembled on lead frame. The epoxy
package is designed as IR filter, to improve sensibility. The demodulated output signal can directly be
decoded by a microprocessor, but it’s logical reversed:
- ON state (carrier presence): TSOP output LOW;
- OFF state (carrier absence): TSOP output HIGH;
To make measures and confirm my suspects, I had use my Logic Analyzer from Saleae on the follow circuit:
That’s the results for press button “1″:
The process to gathering all this information is very easy with Logic Analyzer. The measured times differs a little bit, but this isn’t a problem. I count the transitions after the START bit and there’s 32 bits in.
Look again at the sequence of high and down states. Remember that we have a reversed version of the original IR wave from remote, because TSOP OUT signal is inverted. But actually it’s really doesn’t matter. What I need is: pressing “1″ differs from pressing “2″ or other buttons on remote. I don’t wanna to create a compatible device.
Decoding the data stream
To decode the data stream I used a PIC18F2520 MCU. I already has working on 16bits and 32bits MCU, but this project is much simple to require a great MCU. My design goals are:
- Use internal clock (8Mhz, Instructiom Time TCy = 4/8MHz = 500ns);
- Use Timer0 as counter with 1us increment (Timer0 prescaler to 1:2);
- Use External Interrup 0 (INT0) to handle incoming IR waves and get the building IR code (final version);
That’s the circuit:
The code (for Microchip C18 compiler) consist in a set of functions to detect when the signal change it’s state from DOWN to UP or UP to DOWN. See the sequence (basic):
Note that for data bit identification, only HIGH time is important. It’s the difference between logic “1″ and “0″, so you don’t need to be very precise in that differentiation. The red right program branch, needs to run 32 times, for all 32 bits.
The test was a success! After all, I have a 32bits unique data, that contains (probably) a Address Part and a Data Part. Again, I don’t worry about what is address or data. Only need unique 32 bits codes. If address part repeats (because you are send codes to one device), data should be unique. Ok to me.
The stream is read as it is delivered from TSOP to MCU, from left to right (START BIT to right). I’m considering from LSB to MSB, so when you see the analyzer stream signal, you are viewing the reversed version. See:
After some nights adjusting some things, the code works great! I’ll publish it here in the next week.
As I think, some codes changes if you are using TV, DVD, VCR or STB buttons. See the codes for VCR function:
If you observe the first pictures, about button “1″ stream, you can see the sequence of 1110000 (reverse order, 0×07).
Proof of concept
To test my concept, I programing the device to waiting VCR signal functions (ended with ….0505) as you can see:
- Buttons 1,2 and 3 turn ON color RED, GREEN and BLUE;
- Buttons 4,5 and 6 turn OFF color RED, GREEN and BLUE;
- Button 9 turn ALL ON;
- Button 0 turn ALL OFF;
- VOLUME+ increase LED power (PWM duty cycle);
- VOLUME- decrease LED power (PWM duty cycle);
See my video:
Now I need to design a transformerless power supply and the power control circuitry (TRIAC, etc) to control the real lights. Some nice ideas to next version:
- Store dimming states on internal PIC EEPROM, so you can save desired conditions every time;
- TV Remote now can act in others projects too (robots, toys, other home automation, etc);
- With a small LCD, create a small menu, some configuration options, to more advanced projects;
I hope yours enjoy this project. From the first paper to here, I took one week to get it working properly. In a few weeks, I’ll share all the files here, in downloads page. Thank’s!
In 2010 year end, Microchip present to us the Microstick for dsPIC33F and PIC24H Development Board. The device is very portable, beauty, and Microchip list interesting features (from Microchip website):
- Low Cost – Priced at $24.99 at Microchip Direct
- Integrated USB programmer / debugger – No external debugger required
- USB Powered – Ease of use, No external power required
- Socketed dsPIC/PIC24 – Flexible, Easy device replacement
- 0.025” Pin headers – Enables plug-in to Breadboard with room for jumper wires
- Easy access to all device signals for probing
- Small size – Smaller than a stick of gum at 20 x76mm – Easily Portable
- On board debug LED, Utility LED and Reset Switch
- Free demo code
I ordering one and I’m very confident because it’s the first way Microchip creates a breadboard friendly device (I really don’t like Explorer16 board’s kit and companion). I spec to use this device on rapid prototypes, tests, code optimizations, etc. Also other thing I want to do is know about dsPIC.
The package comes and here is the content:
Very well documented, comes with printed schematics (great Microchip!). And other chip! a dsPIC33FJ64MC802. Again, point to Microchip.
I plug the device on my notebook (a Macbook Pro running Parallels Desktop) and easily upload some example codes (free demo code). Led blinks as a signal that board it’s ok. The debugger has a PIC18F67J50 control and a small ICSP header to upgrades (I think).
When I’ll gonna replace the original PIC on device (PIC24HJ64GP502) to one mine more powerful (PIC24HJ128GP502) the MPLAB won’t recognize the board yet. After some tests and explorations, the explanation comes from the MicroStick box: designed to work only with the two devices inside the box (dsPIC33FJ64MC802 and PIC24HJ64GP502). Wow… what? Why no use other devices? Why no support other PIC24H (or even PIC24F) and dsPIC on 28 DIP packages? All from the same Microchip?
Ok. That’s a lost point. Now, I’ll put the MicroStick on breadboard and wire up it to some device, maybe a LCD, or a triple-axis accelerometer. PORTA RA0, PORTA RA1, GND and +3V3… Where? Where is the +3V3 pin on headers to power external circuitry? Look at schematics again, and, there’s no +3V3 pin on headers to power external circuitry. The 28 pin PIC (+3V3) isn’t connected to 28 socket pin on bottom side.
Because of that (and other things), I’m change my opinion about MicroStick. The device still great, very straight use, ideal for a School Lab, but with limitations. Some of them you need to know (most easy to fix):
- Total absence of +3V3 pin on headers to power external circuitry on breadboard;
- Don’t support other 28pin PIC24H and dsPIC devices;
- Machine headers, DIP-28 socket 600MIL and breadboards don’t form a great team. They won’t attach firmly on breadboards. Maybe a two single-line header work’s well;
- PGD(RB0) and PGC(RB1) program data lines don’t available on DIP-28 socket 600MIL;
But, aside these things, there’s great goals too, not easy to understand on a first view:
- J3 header looks like a 6pin ICSP header, but actually not. It’s a 6pin header where only three pins it’s useful: USART RXD(4), TXD(5) and GND(1). Other pins rest unconnected. It’s match exactly the same cross position (RXD->TX and TXD->RX) to use it with common USB/RS232 breakout boards, like that, and with Bluetooth Mate Gold, both from SparkFun
Well, that’s it. My review to help other users that need know more about this little evil until spend $24,99. I like it, really. And yours will see some project with it here. Maybe some fix to the limitations listed above.
Suggestion to Microchip: update the PIC18F67J50 firmware on MicroStick debugger (and MPLAB, off course) to support the others 28pin devices. Even PIC24F family. Please?