Wednesday, February 19, 2014

Getting Started with STEM32

We are going to use STM32F4 Discovery Board. 

Things you need


1) STM32F4-Discovery Board
2) Keil uVision

STM32F4DISCOVERY board includes an ST-LINK/V2 embedded debug tool interface. The embedded ST-LINK/V2 supports only SWD interface for STM32 devices

Documentation


The library documents, examples etc are difficult to find even in ST website. For library documentation, you can check this website.

All resources in general here


Discovery Board support library
http://web.eece.maine.edu/~hummels/classes/ece486/docs/libstm32f4_doc/modules.html

STM32F4 Peripheral Library
http://web.eece.maine.edu/~hummels/classes/ece486/docs/libperiph_doc/modules.html

To document follow this guide line

Features of STM32F4 uC


- Three 12-bit ADCs. They can be used separately or combined. When used in combined mode sampling rate unto 1MSPS can be achieved.
- Two DACs
- One low-power real-time clock (RTC)
-  Twelve general-purpose 16-bit timers including two PWM timers for motor control, two general-purpose 32-bit timers. a true random number generator (RNG). TIM1 and TIM8 are advanced timer.

Note on RX/TX pins of Discovery board:  Discovery board has uC which has LQFP100 pin-out. PC10 is pin 78 which is UART4_TX and PC11 is pin 79 which is UART4_RX. 


VCP using CDC Library

The buffer reseaving data in STM32F4 part is defined as uint8 so whatever data you send from MATLAB or any other serial port device should be of the form character or uint8. If you want to set some value of register (say DAC register to set some output value) send it as uint8 in matlab (check interpret data as hex..) in tmtool. Use the following command

fwrite(obj1, [hex2dec('B')], 'uint8');

If the register is uint16, then find a way to use two uint8 to make one uint16
uint8_t d1=0x01; 
uint8_t d2=0x02;  
uint16_t wd = (d2 << 8) | d1;

For rest you can use %c\n or %s\n for communication.








Once the code is successfully uploaded, use the reset button to run the code.



Using STLink/v2 for Debugging and Programming

1 - Download and install STM32 ST-Link Utility
2 - Connect the discovery board via USB. Reset board
3 - In 


Using DACs

First ready DAC section in refernce manual to get a little idea. Then read stm32f4xx_dac.c get idea about various functions available to program DACs.
DAQOUT = Vref*(DOR/4095);   
note: 4095 is in decimal (0FFF in hex);In discovery board
DOR value -  DAC output
0x0FFF (4095)  - 2.87
0x0800 (2048) - 1.41
DAC conversion can be triggerd by counter, or software or external trigger line.

DACs have ability to DMA and use data there to convert. It needs to be periodically triggered (using say counter) to continuously generate waveform. Period of the waveform is obviously determined by the period with it is triggered.

General Procedure

Configure the GPIO pins using
GPIO_InitStruct->GPIO_Mode = 
GPIO_Mode_AN for DAC/ADC


Source Code documentaiton

The peripheral library provided by ST is documented using DoxyGen. Things like @param etc are for doxygen. It integrate doxygen to Keil to generate documentation using Doxygen, follow the following steps-

1 - Download Doxygen from here and install. 
2 - Instructions here










Matlab + STM32F4


Download package for STM32F4 Discovery board from here

To install package go to MATLAB toolstrip and click Add-Ons > Get Hardware Support Packages.During installtion "Support Package Installer" will ask to install third-party software "CMSIS" which you can download from ARM website. Copy paste the downloaded folder to C:\ and rename as CMSIS. Matlab will identify this folder and add into the package.

Could compile the code and blink green LED in board.



Simplifying code

Example code from ST website are usually everthing hoch puch together for example they have code for all evaluation board in one project to simply it simply go to project - manange - component..  and remove all other targets.

No comments:

Post a Comment