http://demo.netfoucs.com/cpj_phone/article/details/40979771
FSMC (STM32) Categories:4.cortex_m |2014-11-10 13:39 |256 people reading
(i) fsmc:flexible static memory controller, variable (flexible) quiescent storage controllers
A small volume product is a flash memory capacity between 1 6K to 32K bytes of stm32f101xx,stm32f102xx, and
STM32F103XX microcontroller.
Medium capacity products are stm32f101xx,stm32f102xx, and/or flash memory capacities between 64K to 128K bytes.
STM32F103XX microcontroller.
High-capacity products refer to the stm32f101xx and stm32f103xx of flash memory capacity between 256K to 512K bytes
System.
Connected products refer to stm32f105xx and stm32f107xx microcontrollers.
For M3,
Then divide the 1.0GB external memory into 4 chunks.
1, why is each piece of 64M?
A: We know that the address line 26 and 2 of 26 is equal to 64M, so each block is 64M,
2, why are there 4 pieces in each piece?
A: It has a very ingenious method here each block has 4 pieces to choose, so that we use that piece;
therefore: 1.0GB = (4*64)
The following example of our liquid crystal is connected to the 4th piece in the Bank1;
First look at the interface diagram (Wildfire board)
1, why is slice 4?
For:
Our Lcd_cs is connected to the Fsmc_ne4 4 end of the film (it is plainly: the memory of the liquid crystal and the FSMC to correspond to each other)
2, why is block 1?
A: Because the ram inside the LCD is equal to nor FLASH, or psram, it is best to use block 1
3, why is the low-level light on the screen?
Answer: Look
For the control of the 38,39 pin, a PNP transistor is used, which is on when light is low.
Why did you pick up PB1?
Answer: PB1 through PWM modulation function
4, for the read-write control can be referenced in the diagram, but mainly for different LCD control chip read and write control may vary.
9341
RS we are fsmc_a23, then we control the FSMC address line 23 can control the sending command or the data.
Program Explanation:
1, loading ili9341 driver files
2, open
/* #include "stm32f10x_flash.h" */#include "stm32f10x_fsmc.h"
3, port configuration
4, operating mode configuration (refer to ili9341 manual)
void Lcd_fsmc_config (void) {fsmc_norsraminittypedef fsmc_norsraminitstructure; Fsmc_norsramtiminginittypedef p; P.fsmc_addresssetuptime = 0x02; Address settling time p.fsmc_addressholdtime = 0x00; Address hold time p.fsmc_datasetuptime = 0x05; Data settling time p.fsmc_busturnaroundduration = 0x00; P.fsmc_clkdivision = 0x00; P.fsmc_datalatency = 0x00; P.fsmc_accessmode = Fsmc_accessmode_b; General use of mode B to control the LCD Fsmc_norsraminitstructure.fsmc_bank = FSMC_BANK1_NORSRAM4; Fsmc_norsraminitstructure.fsmc_dataaddressmux = fsmc_dataaddressmux_disable; Fsmc_norsraminitstructure.fsmc_memorytype = Fsmc_memorytype_sram; Fsmc_norsraminitstructure.fsmc_memorytype = Fsmc_memorytype_nor; Fsmc_norsraminitstructure.fsmc_memorydatawidth = fsmc_memorydatawidth_16b; Fsmc_norsraminitstructure.fsmc_burstaccessmode = fsmc_burstaccessmode_disable; fsmc_norsraminitstructure.fsmc_waitsignalpolarity = Fsmc_waitsignalpolarity_low; Fsmc_norsraminitstructure.fsmc_wrapmode = Fsmc_wrapmode_diSable Fsmc_norsraminitstructure.fsmc_waitsignalactive = fsmc_waitsignalactive_beforewaitstate; Fsmc_norsraminitstructure.fsmc_writeoperation = fsmc_writeoperation_enable; Fsmc_norsraminitstructure.fsmc_waitsignal = fsmc_waitsignal_disable; Fsmc_norsraminitstructure.fsmc_extendedmode = fsmc_extendedmode_disable; Fsmc_norsraminitstructure.fsmc_writeburst = fsmc_writeburst_disable; Fsmc_norsraminitstructure.fsmc_readwritetimingstruct = &p; Fsmc_norsraminitstructure.fsmc_writetimingstruct = &p; Fsmc_norsraminit (&fsmc_norsraminitstructure); Fsmc_norsramcmd (FSMC_BANK1_NORSRAM4, ENABLE);}
Fsmc_norsraminitstructure.fsmc_bank = fsmc_bank1_norsram4;//Here we use the fourth piece of the Bank1.
Fsmc_norsraminitstructure.fsmc_bank = fsmc_bank1_norsram4;//Here we use the fourth piece of the Bank1.
5, LCD software reset (low reset, remember to keep the high level to maintain a bit)
void Lcd_rst (void) {gpio_resetbits (Gpiog, gpio_pin_11);//low-Power reset lcd_delay (0xafff<<2); Gpio_setbits (Gpiog, gpio_pin_11); Lcd_delay (0XAFFF<<2); }
6, write commands, data
void Lcd_reg_config (void)
Here is a description of the write command and the Write data function
Lcd_ili9341_cmd (0xCF); Write command Lcd_ili9341_parameter (0x00); Write Data
As follows:
#define Bank1_lcd_c ((u32) 0x6c000000) //disp Reg addr#define bank1_lcd_d ((u32) 0x6d000000) //disp Data ADDR //A23 pe2//selected LCD Specify Register # define LCD_WR_REG ( (* (__io U16 *) (Bank1_lcd_c)) = ((U16) index)//towards LCD Gram Write Data # define LCD_WR_DATA (val) ((* (__io U16 *) (bank1_lcd_d)) = ((U16) (Val))) #define LCD_ILI9341_CMD (Index) Lcd_wr_reg (Index) #define Lcd_ili9341_parameter (Val) lcd_wr_data (Val)
The explanations are as follows:
When the master to the pointer Volume (address) 0x6d000000 operation, the Fsmc_a23 is high, at this time for writing data;
Operation sequence: The CPU acts on the FSMC peripheral, the FSMC memory block acts on the gram of the TFT.
Can understand the CPU to 0x6c000000,0x6d000000 this address write data, even if the operation FSMC Block 1 of the chip select 4, resulting in FSMC peripheral address line and data line pin changes;
Why is 2^23?
For:
When the external device is 16-bit, the connection to the internal address bus haddr when left one bit, 0-1,,,,24-25; so in order to meet the corresponding relationship, we must be the pointer amount of * *, in order to find the correct address and corresponding;
If you connect to other address lines, you are calculating the same way.
7, Scanning mode
Debug_delay (); Lcd_ili9341_cmd (0x36); Lcd_ili9341_parameter (0xC8); Vertical screen Upper left corner (starting point) to the lower right corner (end) scanning mode debug_delay ();
Write the corresponding instruction to the "36" register.
/* Column Address control set * /X-axis lcd_ili9341_cmd (0X2A); Lcd_ili9341_parameter (0x00); Low eight-bit 0lcd_ili9341_parameter (0x00); High eight-bit lcd_ili9341_parameter (0x00); Lcd_ili9341_parameter (0xEF); 0XEF = 239/* page Address control set */y-axis debug_delay (); Lcd_ili9341_cmd (0X2B); Lcd_ili9341_parameter (0x00); 0lcd_ili9341_parameter (0x00); Lcd_ili9341_parameter (0x01); Lcd_ili9341_parameter (0x3F); 0x13f = 319
---------------------------------------------------------------------------
Function section:
① Clear Screen function (source)
void Lcd_clear (uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
such as clearing the entire screen
Lcd_clear (0, 0, +, BACKGROUND);
② Set coordinate points (source)
void Lcd_setcursor (uint16_t x, uint16_t y)
③ Open window (source)
Boundary setting, otherwise it will not be written in reverse (the first line is finished, then the second line is written), the address pointer is adjusted
void Lcd_openwindow (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
④ Draw Point (source)
The origin of all things
void Lcd_setpoint (uint16_t x, uint16_t y, uint16_t color) {lcd_setcursor (x, y); Lcd_ili9341_cmd (0x2c); Lcd_wr_data (color);}
⑤ Color (source)
uint16_t lcd_rd_data (void) {uint16_t r=0, g=0, b=0; R = * (__io uint16_t *) bank1_lcd_d; /*first READ out DUMMY data*/r = * (__io uint16_t *) bank1_lcd_d; /*read out RED DATA */b = * (__io uint16_t *) bank1_lcd_d; /*read out BLACK data*/g = * (__io uint16_t *) bank1_lcd_d; /*read out GREEN data*///translate the address into a pointer and manipulate the pointer to return (((r>>11) <<11) | ((g>>10) <<5) | (b>>11)); Convert to 16-bit width}
⑥ display a character (source)
void Lcd_dispchar (uint16_t x, uint16_t y, uint8_t ASCII, uint16_t color)
such as: Lcd_dispchar (., ' A ', RED); corresponding to a valid place to write the color, this function is also independent;
Of course, before using to have their own corresponding font
⑦ displays a string
void Lcd_dispstr (uint16_t x, uint16_t y, uint8_t *pstr, uint16_t color)
Such as:
LCD_DISPSTR (uint8_t *) "This was a LCD demo to display ASCII", RED);
⑧ Display Numbers
This white still uses Lcd_dispchar.
void Lcd_disnum (uint16_t x, uint16_t y, uint32_t num, uint16_t color)
The record of the Mad Son
About LCD and FSMC