W7200 | WIZnet System
W7200 User's Guide for STM32F10x Standard Library - USART - GPIO - Timer Version 1.0.0 © 2012 WIZnet Co., Ltd. All Rights Reserved. For more information, visit our website at http://www.wiznet.co.kr Table of Contents 1 Introduction ............................................................................................... 1 2 Environment Setting for Development ............................................................... 1 3 STM32F10x Standard Library Structures ............................................................. 2 4 Configuration ............................................................................................. 4 4.1 Check points .................................................................................. 4 4.2 How to use it ................................................................................. 4 5 Examples Demonstration ............................................................................... 7 5.1 USART .......................................................................................... 7 5.2 GPIO .......................................................................................... 10 5.3 Timer ......................................................................................... 12 W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 1 Introduction W7200 ARM 32-bit Cortex-M3 MCU core STM32F103CB hardwired TCP/IP, MAC PHY (WIZnet W5200) WIZnet iMCU . STMicroelectronics MCU ST peripheral library . Figure 1. iMCU W7200 Block Diagram STMicroelectronics Standard Library , peripheral example . , MCU . . - USART : printf (+Echoback) - GPIO : IO Toggle (+LED control) - Timer : Time Base 2 Environment Setting for Development W7200 Startup Guide IAR EWARM (Embedded Workbench for ARM) , STMicroelectronics STM32 F10x Standard Peripheral Library . (STMicroelectronics website, www.st.com/STM32) STM32 F10x Standard Peripheral Library version 3.5.0 , IAR EWARM version 6.5(30-day time limited evaluation license) . W7200 Startup Guide WIZnet website Link . http://www.wiznet.co.kr/UpLoad_Files/ReferenceFiles/W7200_StartUpGuide_EWARM_v100K.pdf W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 1 3 STM32F10x Standard Library Structures STM32 F10x Standard Peripheral Library [Libraries], [Project], [Utilities] . STM32 F10x Standard Peripheral Library HTML (stm32f10x_stdperiph_lib_um.chm) library . [Project] . [STM32F10x_StdPeriph_Examples] : STM peripheral drivers [STM32F10x_StdPeriph_Template] : Compiler project template (W7200: EWARM) Figure 2. Folders List of Project W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 2 [Libraries] . [CMSIS] : ARM Cortex-M MCU library CMSIS : Cortex Microcontroller Software Interface Standard [STM32F10x_StdPeriph_Driver] : STMicroelectronics drivers Figure 3. Folders List of Libraries [Utilities] . [STM32_EVAL] : STM MCU MCU(EVB) Set-up Figure 4. Folders list of STM32_EVAL W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 3 4 Configuration 4.1 Check points W7200 STM32 MCU W5200 SPI . SPI Table 1 . Table 1. W7200 Internal Connected (Unused) Pin List W7200 No STM32F103CB W5200 Description Pins, Pin name Pins, Pin name 1 2, PC13/TAMPER_RTC 49, W_INT W5200 Interrupt pin 2 14, PA4/SPI_NSS 50, CSN 3 15, PA5/SPI_SCK 51, SCLK STM32 MCU(SPI1) W5200 4 16, PA6/SPI_MISO 53, MISO SPI Interface pin 5 17, PA7/SPI_MOSI 52, MOSI 6 45, PB8 53, W_RESET W5200 Reset pin 7 46, PB9 54, PWDN W5200 Power-down pin 4.2 How to use it STMicroelectronics . 1. STM32 F10x Standard Peripheral Library 2. Examples source code template $PROJ_DIR$ \ STM32F10x_StdPeriph_Template 3. IAR EWARM Template EWARM project 4. Rebuild Binary image , W7200 5. W7200 STM32F103CB MCU(128Kbytes Flash memory) Medium-density devices , IAR EWARM Workspace STM3210B-EVAL Set-up . Binary image W7200 W7200 Startup Guide `2 Configuration and Start the Project' . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 4 Note Setting for C Compiler Preprocessor include library . STM32 F10x Standard Peripheral Library Version 3.5.0 , Project > Options C/C++ Compiler Preprocessor directory symbol . Figure 5. Setting for C/C++ Compiler Preprocessor Additional include directories: (one per line) $PROJ_DIR$\..\ $PROJ_DIR$\..\..\..\Libraries\CMSIS\CM3\CoreSupport $PROJ_DIR$\..\..\..\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x $PROJ_DIR$\..\..\..\Libraries\STM32F10x_StdPeriph_Driver\inc $PROJ_DIR$\..\..\..\Utilities\STM32_EVAL $PROJ_DIR$\..\..\..\Utilities\STM32_EVAL\Common $PROJ_DIR$\..\..\..\Utilities\STM32_EVAL\STM3210B_EVAL Defined symbols: (one per line) USE_STDPERIPH_DRIVER STM32F10X_MD USE_STM3210B_EVAL . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 5 Note Make the Binary output file W7200 Startup guide Flash Loader Demonstrator W7200 , Make Binary image . STM32 F10x Standard Peripheral Library Version 3.5.0 , Output binary default, Project > Options Output Converter Generate additional output . Figure 6. Enable the Generate Additional Output Option W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 6 5 Examples Demonstration 5.1 USART STMicroelectronics USART USARTx Serial terminal `printf' . 4.2 `How to use it' USART > printf STM32F10x_StdPeriph_Template . `printf' . Table 2. Source code list of the 'printf' example File name main.c stm32f10x_conf.h stm32f10x_it.c stm32f10x_it.h system_stm32f10x.c readme.txt Description main , USART configuration printf Library configuration Interrupt service routine Interrupt handler header System clock configuration system initialization `printf' Note USART interrupt handling routine , USART interrupt handling routine USART `Interrupt' . Main USART initialization code . USART_InitStructure STM_EVAL_COMInit UASRT configuration enable . Example code: USART Initialization USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); printf USART fputc . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 7 Example code: Retarget the C library printf function to the USART #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) PUTCHAR_PROTOTYPE { /* Place your implementation of fputc here */ /* e.g. write a character to the USART */ USART_SendData(EVAL_COM1, (uint8_t) ch); /* Loop until the end of transmission */ while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET) {} return ch; } , printf() Serial terminal . Serial terminal Initialization Table 3 . Table 3. Serial Terminal Setting /(Baud rate) Data 115200 8 1 printf main USART Serial Serial Echoback . Echoback while . USART stm32f10x_usart.c . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 8 Note Example code iMCU7200EVB . . Example code: Main Function Int main(void) { unsigned char c; /* USART1 Initialization */ ... STM_EVAL_COMInit(COM1, &USART_InitStructure); /* Output a message on Hyperterminal using printf function */ printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r"); // USART Echoback while(1) { while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET) { } c = USART_ReceiveData(USART1); // Read a character from the USART USART_SendData(USART1, c); // Send a character to the USART } } iMCU7200EVB Echoback . printf Serial terminal , `Hello! WIZnet!' Echoback . Figure 7. USART Demonstration on iMCU7200EVB W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 9 5.2 GPIO GPIO STMicroelectronics GPIO GPIO Pin Set Reset `IO Toggle'. Note STM32 library PD0 PD2 toggling , W7200 STM32F103CB-48PIN PD0 PD2 . PD0 PD2 iMCU7200EVB LED3, 4 PB0 PB1 . IO toggle EVB LED GPIO toggle . Main GPIO Initialization . USART InitStructure , GPIO_Init configuration . GPIO STM32 library IO Toggle PB0 PB1 . Example code: GPIO Initialization /* GPIOB Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure PB0 and PB1 in output push-pull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); PB0 PB1 SET / RESET BSRR BRR . GPIO_BSRR (Port Bit Set/Reset Register) 32bit, 16bit (mapping) SET . GPIO_BRR (Port Bit Reset Register) BSRR RESET . BSRR BRR General purpose I/O stm32f10x.h . Pin0 SET BSRR register 0x00000001, Pin15 RESET BRR register 0x00008000 . PB0 PB1 SET / RESET . PB0 0x00000001, PB1 0x00000002 SET RESET . BSRR SET, BRR register RESET . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 10 LED Delay . Delay STM library . Example code: GPIO Toggle while (1) { /* Set PB0 and PB1 */ GPIOB->BSRR = 0x00000003; Delay(10); /* Reset PB0 and PB1 */ GPIOB->BRR = 0x00000003; Delay(10); } // 0x00000001 | 0x00000002 // Delay for LED(I/O) toggling indication // Delay for LED(I/O) toggling indication iMCU7200EVB LED IO toggle . Figure 8. IO Toggle - LED on Figure 9. IO Toggle - LED off W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 11 5.3 Timer STMicroelectronics Timer TIM Time Base . TIM2 Output Compare Timing mode TIM peripheral configuration 4 Time base Interrupt request . Note STM32 library PC6, 7, 8, 9 4 Timer Interrupt channel , W7200 STM32F103CB-48PIN . GPIO PB11, 12, 13, 14 output port . 4 Interrupt request . Table 4. Time base Configuration Pin PB11 PB12 PB13 PB14 TIM2 CC CC1 CC2 CC3 CC4 CC Register value 40961 27309 13654 6826 Description CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48Hz TIM2 Channel 1 generates an interrupt each 6.8ms CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7Hz TIM2 Channel 2 generates an interrupt each 4.55ms CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4Hz TIM2 Channel 3 generates an interrupt each 2.27ms CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9Hz TIM2 Channel 4 generates an interrupt each 1.13ms CC Register value main.c . Example code: CCR Value Declarations __IO uint16_t CCR1_Val = 40961; __IO uint16_t CCR2_Val = 27309; __IO uint16_t CCR3_Val = 13654; __IO uint16_t CCR4_Val = 6826; Pin . 1. RCC_Configuration : System clocks configuration 2. GPIO_Configuration : General purpose I/O configuration 3. TIM2_IRQHandler : TIM2 Interrupt service routine - NVIC_Configuration : Nested vectored interrupt controller configuration W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 12 Pin . . RCC_Configuration GPIOC clock enable GPIOB clock enable . Example code: RCC Configuration void RCC_Configuration(void) { /* PCLK1 = HCLK/4 */ RCC_PCLK1Config(RCC_HCLK_Div4); /* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* GPIOB clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); } GPIO_Configuration Timer interrupt GPIO Pin . Pin TIM2 interrupt request , Pin . Example code: GPIO Configuration void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* GPIOB Configuration: Pin4, 5, 6 and 7 as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); } TIM2_IRQHandler Timer interrupt interrupt handling routine. Interrupt request GPIO . GPIO Pin . W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 13 Example code: TIM2_IRQHandler void TIM2_IRQHandler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); /* Pin PB.11 toggling with frequency = 73.24 Hz */ GPIO_WriteBit(GPIOB, GPIO_Pin_11, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_11))); capture = TIM_GetCapture1(TIM2); TIM_SetCompare1(TIM2, capture + CCR1_Val); } else if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); /* Pin PB.12 toggling with frequency = 109.8 Hz */ GPIO_WriteBit(GPIOB, GPIO_Pin_12, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12))); capture = TIM_GetCapture2(TIM2); TIM_SetCompare2(TIM2, capture + CCR2_Val); } else if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC3); /* Pin PB.13 toggling with frequency = 219.7 Hz */ GPIO_WriteBit(GPIOB, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_13))); capture = TIM_GetCapture3(TIM2); TIM_SetCompare3(TIM2, capture + CCR3_Val); } else { TIM_ClearITPendingBit(TIM2, TIM_IT_CC4); /* Pin PB.14 toggling with frequency = 439.4 Hz */ GPIO_WriteBit(GPIOB, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_14))); capture = TIM_GetCapture4(TIM2); TIM_SetCompare4(TIM2, capture + CCR4_Val); } } W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 14 NVIC_Configuration Timer2 global interrupt . Timer2 , Timer2 . Example code: NVIC Configuration void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } Binary image iMCU7200EVB , PinPB11, 12, 13, 14 Oscilloscope Timer Interrupt . CC1, CC2, CC3, CC4 . Figure 10. Oscilloscope Measurements : Timer interrupts W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 15 Document History Information Version Date Descriptions Ver. 1.0.0 6Dec2012 Document Released Copyright Notice Copyright 2012 WIZnet, Co., Ltd. All Rights Reserved. Technical Support: support@wiznet.co.kr Sales & Distribution: sales@wiznet.co.kr For more information, visit our website at http://www.wiznet.co.kr W7200 User's Guide for STM32 F10x Standard Library v1.0.0K 16Microsoft Word 2010 Microsoft Word 2010