├── Output ├── mb.crf ├── mbfuncdiag.d ├── led.crf ├── main.crf ├── mbcrc.crf ├── mbrtu.crf ├── mbtcp.crf ├── misc.crf ├── mbascii.crf ├── mbutils.crf ├── STM32-DEMO.axf ├── STM32-DEMO.plg ├── core_cm3.crf ├── mbfuncdiag.crf ├── mbfuncdisc.crf ├── portevent.crf ├── portserial.crf ├── porttimer.crf ├── mbfunccoils.crf ├── mbfuncinput.crf ├── mbfuncother.crf ├── stm32f10x_it.crf ├── mbfuncholding.crf ├── startup_stm32f10x_hd.d ├── stm32f10x_gpio.crf ├── stm32f10x_rcc.crf ├── stm32f10x_tim.crf ├── stm32f10x_usart.crf ├── system_stm32f10x.crf ├── core_cm3.d ├── main.__i ├── led.d ├── misc.d ├── mbcrc.d ├── stm32f10x_it.d ├── system_stm32f10x.d ├── stm32f10x_rcc.d ├── stm32f10x_tim.d ├── stm32f10x_gpio.d ├── stm32f10x_usart.d ├── main.d ├── portevent.d ├── porttimer.d ├── portserial.d ├── mbutils.d ├── STM32-DEMO.lnp ├── mbrtu.d ├── mbtcp.d ├── mb.d ├── mbfuncdisc.d ├── mbfunccoils.d ├── mbfuncinput.d ├── mbfuncother.d ├── mbascii.d ├── mbfuncholding.d └── STM32-DEMO.tra ├── README.md ├── CMSIS ├── stm32f10x.h └── system_stm32f10x.h ├── modbus ├── port │ ├── porttimer.c │ ├── portserial.c │ ├── portevent.c │ └── port.h ├── functions │ ├── mbfuncdiag.c │ ├── mbfuncother.c │ ├── mbfuncdisc.c │ ├── mbfuncinput.c │ └── mbutils.c ├── rtu │ ├── mbcrc.h │ ├── mbrtu.h │ └── mbcrc.c ├── tcp │ ├── mbtcp.h │ └── mbtcp.c ├── ascii │ └── mbascii.h └── include │ ├── mbfunc.h │ ├── mbproto.h │ ├── mbframe.h │ ├── mbutils.h │ ├── mbport.h │ └── mbconfig.h ├── FWlib ├── inc │ ├── stm32f10x_gpio.h │ ├── stm32f10x_crc.h │ ├── stm32f10x_wwdg.h │ ├── stm32f10x_dbgmcu.h │ ├── stm32f10x_rtc.h │ ├── stm32f10x_iwdg.h │ ├── stm32f10x_pwr.h │ ├── misc.h │ ├── stm32f10x_exti.h │ └── stm32f10x_bkp.h └── src │ ├── stm32f10x_adc.c │ ├── stm32f10x_can.c │ ├── stm32f10x_dma.c │ ├── stm32f10x_exti.c │ ├── stm32f10x_fsmc.c │ ├── stm32f10x_i2c.c │ ├── stm32f10x_rcc.c │ ├── stm32f10x_rtc.c │ ├── stm32f10x_sdio.c │ ├── stm32f10x_tim.c │ ├── stm32f10x_flash.c │ ├── stm32f10x_usart.c │ ├── stm32f10x_crc.c │ ├── stm32f10x_dbgmcu.c │ ├── stm32f10x_iwdg.c │ ├── stm32f10x_wwdg.c │ ├── misc.c │ ├── stm32f10x_bkp.c │ └── stm32f10x_pwr.c ├── ModbusMaster ├── ModbusMaster.h ├── ModbusMaster.cpp ├── examples │ ├── Basic │ │ └── Basic.pde │ └── PhoenixContact_nanoLC │ │ └── PhoenixContact_nanoLC.pde └── INSTALL ├── .gitignore └── USER ├── JLinkSettings.ini ├── stm32f10x_it.h ├── stm32f10x_conf.h ├── main.c └── stm32f10x_it.c /Output/mb.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mb.crf -------------------------------------------------------------------------------- /Output/mbfuncdiag.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfuncdiag.o: ..\modbus\functions\mbfuncdiag.c 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | stm32_modbus 2 | ============ 3 | 4 | a freemodbus port to stm32 platform -------------------------------------------------------------------------------- /Output/led.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/led.crf -------------------------------------------------------------------------------- /Output/main.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/main.crf -------------------------------------------------------------------------------- /Output/mbcrc.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbcrc.crf -------------------------------------------------------------------------------- /Output/mbrtu.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbrtu.crf -------------------------------------------------------------------------------- /Output/mbtcp.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbtcp.crf -------------------------------------------------------------------------------- /Output/misc.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/misc.crf -------------------------------------------------------------------------------- /CMSIS/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/CMSIS/stm32f10x.h -------------------------------------------------------------------------------- /Output/mbascii.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbascii.crf -------------------------------------------------------------------------------- /Output/mbutils.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbutils.crf -------------------------------------------------------------------------------- /Output/STM32-DEMO.axf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/STM32-DEMO.axf -------------------------------------------------------------------------------- /Output/STM32-DEMO.plg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/STM32-DEMO.plg -------------------------------------------------------------------------------- /Output/core_cm3.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/core_cm3.crf -------------------------------------------------------------------------------- /Output/mbfuncdiag.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfuncdiag.crf -------------------------------------------------------------------------------- /Output/mbfuncdisc.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfuncdisc.crf -------------------------------------------------------------------------------- /Output/portevent.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/portevent.crf -------------------------------------------------------------------------------- /Output/portserial.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/portserial.crf -------------------------------------------------------------------------------- /Output/porttimer.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/porttimer.crf -------------------------------------------------------------------------------- /Output/mbfunccoils.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfunccoils.crf -------------------------------------------------------------------------------- /Output/mbfuncinput.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfuncinput.crf -------------------------------------------------------------------------------- /Output/mbfuncother.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfuncother.crf -------------------------------------------------------------------------------- /Output/stm32f10x_it.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/stm32f10x_it.crf -------------------------------------------------------------------------------- /modbus/port/porttimer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/modbus/port/porttimer.c -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_gpio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/inc/stm32f10x_gpio.h -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_adc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_adc.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_can.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_can.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_dma.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_dma.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_exti.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_exti.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_fsmc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_fsmc.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_rcc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_rcc.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_rtc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_rtc.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_sdio.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_sdio.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_tim.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_tim.c -------------------------------------------------------------------------------- /Output/mbfuncholding.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/mbfuncholding.crf -------------------------------------------------------------------------------- /Output/startup_stm32f10x_hd.d: -------------------------------------------------------------------------------- 1 | ..\Output\startup_stm32f10x_hd.o: ..\CMSIS\startup\startup_stm32f10x_hd.s 2 | -------------------------------------------------------------------------------- /Output/stm32f10x_gpio.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/stm32f10x_gpio.crf -------------------------------------------------------------------------------- /Output/stm32f10x_rcc.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/stm32f10x_rcc.crf -------------------------------------------------------------------------------- /Output/stm32f10x_tim.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/stm32f10x_tim.crf -------------------------------------------------------------------------------- /Output/stm32f10x_usart.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/stm32f10x_usart.crf -------------------------------------------------------------------------------- /modbus/port/portserial.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/modbus/port/portserial.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/FWlib/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /ModbusMaster/ModbusMaster.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/ModbusMaster/ModbusMaster.h -------------------------------------------------------------------------------- /Output/system_stm32f10x.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/Output/system_stm32f10x.crf -------------------------------------------------------------------------------- /ModbusMaster/ModbusMaster.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/ModbusMaster/ModbusMaster.cpp -------------------------------------------------------------------------------- /Output/core_cm3.d: -------------------------------------------------------------------------------- 1 | ..\Output\core_cm3.o: ..\CMSIS\core_cm3.c 2 | ..\Output\core_cm3.o: h:\Keil\ARM\RV31\INC\stdint.h 3 | -------------------------------------------------------------------------------- /ModbusMaster/examples/Basic/Basic.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/ModbusMaster/examples/Basic/Basic.pde -------------------------------------------------------------------------------- /ModbusMaster/examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyyyuna/stm32_modbus/HEAD/ModbusMaster/examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde -------------------------------------------------------------------------------- /Output/main.__i: -------------------------------------------------------------------------------- 1 | -c --device DARMSTM -D__MICROLIB -g -O0 --apcs=interwork -I..\CMSIS -I..\FWlib\inc -I..\USER -I "C:\Keil\ARM\INC\ST\STM32F10x" -DUSE_STDPERIPH_DRIVER -DSTM32F10X_HD -o "..\Output\main.o" --omf_browse "..\Output\main.crf" --depend "..\Output\main.d" "main.c" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | 20 | # project related # 21 | *.lst 22 | *.txt 23 | *.Bak 24 | *.map 25 | *.cbp 26 | *.dep 27 | *.crf 28 | *.d 29 | *.lnp 30 | *.plg 31 | *.tra 32 | -------------------------------------------------------------------------------- /Output/led.d: -------------------------------------------------------------------------------- 1 | ..\Output\led.o: led.c 2 | ..\Output\led.o: led.h 3 | ..\Output\led.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\led.o: ..\CMSIS\core_cm3.h 5 | ..\Output\led.o: C:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\led.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\led.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\led.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\led.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\led.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | -------------------------------------------------------------------------------- /ModbusMaster/INSTALL: -------------------------------------------------------------------------------- 1 | INSTALL 2 | 3 | Arduino 17 (or later): 4 | Determine the location of your sketchbook by selecting File > 5 | Preferences from within the Arduino IDE. If you don't already have a 6 | libraries folder within your sketchbook, create one and unzip the 7 | archive there. See http://arduino.cc/blog/?p=313 for more information. 8 | 9 | 10 | Arduino 16 (or earlier): 11 | Download the zip file, extract and copy the ModbusMaster folder to 12 | ARDUINO_HOME/hardware/libraries. If you are upgrading from a previous 13 | version, be sure to delete ModbusMaster.o. 14 | -------------------------------------------------------------------------------- /Output/misc.d: -------------------------------------------------------------------------------- 1 | ..\Output\misc.o: ..\FWlib\src\misc.c 2 | ..\Output\misc.o: ..\FWlib\inc\misc.h 3 | ..\Output\misc.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\misc.o: ..\CMSIS\core_cm3.h 5 | ..\Output\misc.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\misc.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\misc.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\misc.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\misc.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\misc.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\misc.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\misc.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\misc.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/mbcrc.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbcrc.o: ..\modbus\rtu\mbcrc.c 2 | ..\Output\mbcrc.o: ..\modbus\port\port.h 3 | ..\Output\mbcrc.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\mbcrc.o: ..\CMSIS\core_cm3.h 5 | ..\Output\mbcrc.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\mbcrc.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\mbcrc.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\mbcrc.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\mbcrc.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\mbcrc.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\mbcrc.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\mbcrc.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\mbcrc.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /USER/JLinkSettings.ini: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ShowInfoWin = 1 3 | EnableFlashBP = 2 4 | BPDuringExecution = 0 5 | [CFI] 6 | CFISize = 0x00 7 | CFIAddr = 0x00 8 | [CPU] 9 | OverrideMemMap = 0 10 | AllowSimulation = 1 11 | ScriptFile="" 12 | [FLASH] 13 | MinNumBytesFlashDL = 64 14 | SkipProgOnCRCMatch = 1 15 | VerifyDownload = 1 16 | AllowCaching = 1 17 | EnableFlashDL = 2 18 | Override = 0 19 | Device="AD7160" 20 | [GENERAL] 21 | WorkRAMSize = 0x00 22 | WorkRAMAddr = 0x00 23 | [SWO] 24 | SWOLogFile="" 25 | [MEM] 26 | RdOverrideOrMask = 0x00 27 | RdOverrideAndMask = 0xFFFFFFFF 28 | RdOverrideAddr = 0xFFFFFFFF 29 | WrOverrideOrMask = 0x00 30 | WrOverrideAndMask = 0xFFFFFFFF 31 | WrOverrideAddr = 0xFFFFFFFF 32 | -------------------------------------------------------------------------------- /Output/stm32f10x_it.d: -------------------------------------------------------------------------------- 1 | ..\Output\stm32f10x_it.o: stm32f10x_it.c 2 | ..\Output\stm32f10x_it.o: stm32f10x_it.h 3 | ..\Output\stm32f10x_it.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\stm32f10x_it.o: ..\CMSIS\core_cm3.h 5 | ..\Output\stm32f10x_it.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\stm32f10x_it.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\stm32f10x_it.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\stm32f10x_it.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\stm32f10x_it.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\stm32f10x_it.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\stm32f10x_it.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\stm32f10x_it.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\stm32f10x_it.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/system_stm32f10x.d: -------------------------------------------------------------------------------- 1 | ..\Output\system_stm32f10x.o: ..\CMSIS\system_stm32f10x.c 2 | ..\Output\system_stm32f10x.o: ..\CMSIS\stm32f10x.h 3 | ..\Output\system_stm32f10x.o: ..\CMSIS\core_cm3.h 4 | ..\Output\system_stm32f10x.o: h:\Keil\ARM\RV31\INC\stdint.h 5 | ..\Output\system_stm32f10x.o: ..\CMSIS\system_stm32f10x.h 6 | ..\Output\system_stm32f10x.o: ..\USER\stm32f10x_conf.h 7 | ..\Output\system_stm32f10x.o: ..\FWlib\inc\stm32f10x_gpio.h 8 | ..\Output\system_stm32f10x.o: ..\CMSIS\stm32f10x.h 9 | ..\Output\system_stm32f10x.o: ..\FWlib\inc\stm32f10x_rcc.h 10 | ..\Output\system_stm32f10x.o: ..\FWlib\inc\stm32f10x_tim.h 11 | ..\Output\system_stm32f10x.o: ..\FWlib\inc\stm32f10x_usart.h 12 | ..\Output\system_stm32f10x.o: ..\FWlib\inc\misc.h 13 | -------------------------------------------------------------------------------- /Output/stm32f10x_rcc.d: -------------------------------------------------------------------------------- 1 | ..\Output\stm32f10x_rcc.o: ..\FWlib\src\stm32f10x_rcc.c 2 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\stm32f10x_rcc.h 3 | ..\Output\stm32f10x_rcc.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\stm32f10x_rcc.o: ..\CMSIS\core_cm3.h 5 | ..\Output\stm32f10x_rcc.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\stm32f10x_rcc.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\stm32f10x_rcc.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\stm32f10x_rcc.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\stm32f10x_rcc.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/stm32f10x_tim.d: -------------------------------------------------------------------------------- 1 | ..\Output\stm32f10x_tim.o: ..\FWlib\src\stm32f10x_tim.c 2 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\stm32f10x_tim.h 3 | ..\Output\stm32f10x_tim.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\stm32f10x_tim.o: ..\CMSIS\core_cm3.h 5 | ..\Output\stm32f10x_tim.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\stm32f10x_tim.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\stm32f10x_tim.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\stm32f10x_tim.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\stm32f10x_tim.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/stm32f10x_gpio.d: -------------------------------------------------------------------------------- 1 | ..\Output\stm32f10x_gpio.o: ..\FWlib\src\stm32f10x_gpio.c 2 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\stm32f10x_gpio.h 3 | ..\Output\stm32f10x_gpio.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\stm32f10x_gpio.o: ..\CMSIS\core_cm3.h 5 | ..\Output\stm32f10x_gpio.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\stm32f10x_gpio.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\stm32f10x_gpio.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\stm32f10x_rcc.h 10 | ..\Output\stm32f10x_gpio.o: ..\CMSIS\stm32f10x.h 11 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\stm32f10x_gpio.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/stm32f10x_usart.d: -------------------------------------------------------------------------------- 1 | ..\Output\stm32f10x_usart.o: ..\FWlib\src\stm32f10x_usart.c 2 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\stm32f10x_usart.h 3 | ..\Output\stm32f10x_usart.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\stm32f10x_usart.o: ..\CMSIS\core_cm3.h 5 | ..\Output\stm32f10x_usart.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\stm32f10x_usart.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\stm32f10x_usart.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\stm32f10x_usart.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\stm32f10x_usart.o: ..\FWlib\inc\misc.h 14 | -------------------------------------------------------------------------------- /Output/main.d: -------------------------------------------------------------------------------- 1 | ..\Output\main.o: main.c 2 | ..\Output\main.o: h:\Keil\ARM\RV31\INC\stdio.h 3 | ..\Output\main.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\main.o: ..\CMSIS\core_cm3.h 5 | ..\Output\main.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\main.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\main.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\main.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\main.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\main.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\main.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\main.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\main.o: ..\FWlib\inc\misc.h 14 | ..\Output\main.o: ..\modbus\include\mb.h 15 | ..\Output\main.o: ..\modbus\port\port.h 16 | ..\Output\main.o: ..\modbus\include\mbport.h 17 | ..\Output\main.o: ..\modbus\include\mbproto.h 18 | -------------------------------------------------------------------------------- /Output/portevent.d: -------------------------------------------------------------------------------- 1 | ..\Output\portevent.o: ..\modbus\port\portevent.c 2 | ..\Output\portevent.o: ..\modbus\include\mb.h 3 | ..\Output\portevent.o: ..\modbus\port\port.h 4 | ..\Output\portevent.o: ..\CMSIS\stm32f10x.h 5 | ..\Output\portevent.o: ..\CMSIS\core_cm3.h 6 | ..\Output\portevent.o: h:\Keil\ARM\RV31\INC\stdint.h 7 | ..\Output\portevent.o: ..\CMSIS\system_stm32f10x.h 8 | ..\Output\portevent.o: ..\USER\stm32f10x_conf.h 9 | ..\Output\portevent.o: ..\FWlib\inc\stm32f10x_gpio.h 10 | ..\Output\portevent.o: ..\CMSIS\stm32f10x.h 11 | ..\Output\portevent.o: ..\FWlib\inc\stm32f10x_rcc.h 12 | ..\Output\portevent.o: ..\FWlib\inc\stm32f10x_tim.h 13 | ..\Output\portevent.o: ..\FWlib\inc\stm32f10x_usart.h 14 | ..\Output\portevent.o: ..\FWlib\inc\misc.h 15 | ..\Output\portevent.o: ..\modbus\include\mbport.h 16 | ..\Output\portevent.o: ..\modbus\include\mbproto.h 17 | -------------------------------------------------------------------------------- /Output/porttimer.d: -------------------------------------------------------------------------------- 1 | ..\Output\porttimer.o: ..\modbus\port\porttimer.c 2 | ..\Output\porttimer.o: ..\modbus\port\port.h 3 | ..\Output\porttimer.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\porttimer.o: ..\CMSIS\core_cm3.h 5 | ..\Output\porttimer.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\porttimer.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\porttimer.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\porttimer.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\porttimer.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\porttimer.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\porttimer.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\porttimer.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\porttimer.o: ..\FWlib\inc\misc.h 14 | ..\Output\porttimer.o: ..\modbus\include\mb.h 15 | ..\Output\porttimer.o: ..\modbus\include\mbport.h 16 | ..\Output\porttimer.o: ..\modbus\include\mbproto.h 17 | -------------------------------------------------------------------------------- /Output/portserial.d: -------------------------------------------------------------------------------- 1 | ..\Output\portserial.o: ..\modbus\port\portserial.c 2 | ..\Output\portserial.o: ..\modbus\port\port.h 3 | ..\Output\portserial.o: ..\CMSIS\stm32f10x.h 4 | ..\Output\portserial.o: ..\CMSIS\core_cm3.h 5 | ..\Output\portserial.o: h:\Keil\ARM\RV31\INC\stdint.h 6 | ..\Output\portserial.o: ..\CMSIS\system_stm32f10x.h 7 | ..\Output\portserial.o: ..\USER\stm32f10x_conf.h 8 | ..\Output\portserial.o: ..\FWlib\inc\stm32f10x_gpio.h 9 | ..\Output\portserial.o: ..\CMSIS\stm32f10x.h 10 | ..\Output\portserial.o: ..\FWlib\inc\stm32f10x_rcc.h 11 | ..\Output\portserial.o: ..\FWlib\inc\stm32f10x_tim.h 12 | ..\Output\portserial.o: ..\FWlib\inc\stm32f10x_usart.h 13 | ..\Output\portserial.o: ..\FWlib\inc\misc.h 14 | ..\Output\portserial.o: ..\modbus\include\mb.h 15 | ..\Output\portserial.o: ..\modbus\include\mbport.h 16 | ..\Output\portserial.o: ..\modbus\include\mbproto.h 17 | -------------------------------------------------------------------------------- /Output/mbutils.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbutils.o: ..\modbus\functions\mbutils.c 2 | ..\Output\mbutils.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbutils.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbutils.o: ..\modbus\port\port.h 5 | ..\Output\mbutils.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbutils.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbutils.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbutils.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbutils.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbutils.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbutils.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbutils.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbutils.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbutils.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbutils.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbutils.o: ..\modbus\include\mb.h 17 | ..\Output\mbutils.o: ..\modbus\include\mbport.h 18 | ..\Output\mbutils.o: ..\modbus\include\mbproto.h 19 | -------------------------------------------------------------------------------- /Output/STM32-DEMO.lnp: -------------------------------------------------------------------------------- 1 | --cpu Cortex-M3 "..\output\startup_stm32f10x_hd.o" "..\output\main.o" "..\output\stm32f10x_it.o" "..\output\stm32f10x_gpio.o" "..\output\stm32f10x_rcc.o" "..\output\stm32f10x_tim.o" "..\output\stm32f10x_usart.o" "..\output\misc.o" "..\output\core_cm3.o" "..\output\system_stm32f10x.o" "..\output\mbtcp.o" "..\output\mbcrc.o" "..\output\mbrtu.o" "..\output\mbascii.o" "..\output\mbfunccoils.o" "..\output\mbfuncdiag.o" "..\output\mbfuncdisc.o" "..\output\mbfuncholding.o" "..\output\mbfuncinput.o" "..\output\mbfuncother.o" "..\output\mbutils.o" "..\output\mb.o" "..\output\portevent.o" "..\output\portserial.o" "..\output\porttimer.o" --library_type=microlib --ro-base 0x08000000 --entry 0x08000000 --rw-base 0x20000000 --entry Reset_Handler --first __Vectors --strict --autoat --summary_stderr --info summarysizes --map --xref --callgraph --symbols 2 | --info sizes --info totals --info unused --info veneers 3 | --list "..\Listing\STM32-DEMO.map" -o "..\Output\STM32-DEMO.axf" -------------------------------------------------------------------------------- /Output/mbrtu.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbrtu.o: ..\modbus\rtu\mbrtu.c 2 | ..\Output\mbrtu.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbrtu.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbrtu.o: ..\modbus\port\port.h 5 | ..\Output\mbrtu.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbrtu.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbrtu.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbrtu.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbrtu.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbrtu.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbrtu.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbrtu.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbrtu.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbrtu.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbrtu.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbrtu.o: ..\modbus\include\mb.h 17 | ..\Output\mbrtu.o: ..\modbus\include\mbport.h 18 | ..\Output\mbrtu.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbrtu.o: ..\modbus\rtu\mbrtu.h 20 | ..\Output\mbrtu.o: ..\modbus\include\mbframe.h 21 | ..\Output\mbrtu.o: ..\modbus\rtu\mbcrc.h 22 | -------------------------------------------------------------------------------- /Output/mbtcp.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbtcp.o: ..\modbus\tcp\mbtcp.c 2 | ..\Output\mbtcp.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbtcp.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbtcp.o: ..\modbus\port\port.h 5 | ..\Output\mbtcp.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbtcp.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbtcp.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbtcp.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbtcp.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbtcp.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbtcp.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbtcp.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbtcp.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbtcp.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbtcp.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbtcp.o: ..\modbus\include\mb.h 17 | ..\Output\mbtcp.o: ..\modbus\include\mbport.h 18 | ..\Output\mbtcp.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbtcp.o: ..\modbus\include\mbconfig.h 20 | ..\Output\mbtcp.o: ..\modbus\tcp\mbtcp.h 21 | ..\Output\mbtcp.o: ..\modbus\include\mbframe.h 22 | -------------------------------------------------------------------------------- /Output/mb.d: -------------------------------------------------------------------------------- 1 | ..\Output\mb.o: ..\modbus\mb.c 2 | ..\Output\mb.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mb.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mb.o: ..\modbus\port\port.h 5 | ..\Output\mb.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mb.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mb.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mb.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mb.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mb.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mb.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mb.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mb.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mb.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mb.o: ..\FWlib\inc\misc.h 16 | ..\Output\mb.o: ..\modbus\include\mb.h 17 | ..\Output\mb.o: ..\modbus\include\mbport.h 18 | ..\Output\mb.o: ..\modbus\include\mbproto.h 19 | ..\Output\mb.o: ..\modbus\include\mbconfig.h 20 | ..\Output\mb.o: ..\modbus\include\mbframe.h 21 | ..\Output\mb.o: ..\modbus\include\mbfunc.h 22 | ..\Output\mb.o: ..\modbus\rtu\mbrtu.h 23 | ..\Output\mb.o: ..\modbus\ascii\mbascii.h 24 | -------------------------------------------------------------------------------- /Output/mbfuncdisc.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfuncdisc.o: ..\modbus\functions\mbfuncdisc.c 2 | ..\Output\mbfuncdisc.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbfuncdisc.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbfuncdisc.o: ..\modbus\port\port.h 5 | ..\Output\mbfuncdisc.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbfuncdisc.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbfuncdisc.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbfuncdisc.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbfuncdisc.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbfuncdisc.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbfuncdisc.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbfuncdisc.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbfuncdisc.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbfuncdisc.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbfuncdisc.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbfuncdisc.o: ..\modbus\include\mb.h 17 | ..\Output\mbfuncdisc.o: ..\modbus\include\mbport.h 18 | ..\Output\mbfuncdisc.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbfuncdisc.o: ..\modbus\include\mbframe.h 20 | ..\Output\mbfuncdisc.o: ..\modbus\include\mbconfig.h 21 | -------------------------------------------------------------------------------- /Output/mbfunccoils.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfunccoils.o: ..\modbus\functions\mbfunccoils.c 2 | ..\Output\mbfunccoils.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbfunccoils.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbfunccoils.o: ..\modbus\port\port.h 5 | ..\Output\mbfunccoils.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbfunccoils.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbfunccoils.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbfunccoils.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbfunccoils.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbfunccoils.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbfunccoils.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbfunccoils.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbfunccoils.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbfunccoils.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbfunccoils.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbfunccoils.o: ..\modbus\include\mb.h 17 | ..\Output\mbfunccoils.o: ..\modbus\include\mbport.h 18 | ..\Output\mbfunccoils.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbfunccoils.o: ..\modbus\include\mbframe.h 20 | ..\Output\mbfunccoils.o: ..\modbus\include\mbconfig.h 21 | -------------------------------------------------------------------------------- /Output/mbfuncinput.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfuncinput.o: ..\modbus\functions\mbfuncinput.c 2 | ..\Output\mbfuncinput.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbfuncinput.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbfuncinput.o: ..\modbus\port\port.h 5 | ..\Output\mbfuncinput.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbfuncinput.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbfuncinput.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbfuncinput.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbfuncinput.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbfuncinput.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbfuncinput.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbfuncinput.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbfuncinput.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbfuncinput.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbfuncinput.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbfuncinput.o: ..\modbus\include\mb.h 17 | ..\Output\mbfuncinput.o: ..\modbus\include\mbport.h 18 | ..\Output\mbfuncinput.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbfuncinput.o: ..\modbus\include\mbframe.h 20 | ..\Output\mbfuncinput.o: ..\modbus\include\mbconfig.h 21 | -------------------------------------------------------------------------------- /Output/mbfuncother.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfuncother.o: ..\modbus\functions\mbfuncother.c 2 | ..\Output\mbfuncother.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbfuncother.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbfuncother.o: ..\modbus\port\port.h 5 | ..\Output\mbfuncother.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbfuncother.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbfuncother.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbfuncother.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbfuncother.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbfuncother.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbfuncother.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbfuncother.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbfuncother.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbfuncother.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbfuncother.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbfuncother.o: ..\modbus\include\mb.h 17 | ..\Output\mbfuncother.o: ..\modbus\include\mbport.h 18 | ..\Output\mbfuncother.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbfuncother.o: ..\modbus\include\mbframe.h 20 | ..\Output\mbfuncother.o: ..\modbus\include\mbconfig.h 21 | -------------------------------------------------------------------------------- /Output/mbascii.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbascii.o: ..\modbus\ascii\mbascii.c 2 | ..\Output\mbascii.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbascii.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbascii.o: ..\modbus\port\port.h 5 | ..\Output\mbascii.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbascii.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbascii.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbascii.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbascii.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbascii.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbascii.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbascii.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbascii.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbascii.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbascii.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbascii.o: ..\modbus\include\mb.h 17 | ..\Output\mbascii.o: ..\modbus\include\mbport.h 18 | ..\Output\mbascii.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbascii.o: ..\modbus\include\mbconfig.h 20 | ..\Output\mbascii.o: ..\modbus\ascii\mbascii.h 21 | ..\Output\mbascii.o: ..\modbus\include\mbframe.h 22 | ..\Output\mbascii.o: ..\modbus\rtu\mbcrc.h 23 | -------------------------------------------------------------------------------- /Output/mbfuncholding.d: -------------------------------------------------------------------------------- 1 | ..\Output\mbfuncholding.o: ..\modbus\functions\mbfuncholding.c 2 | ..\Output\mbfuncholding.o: h:\Keil\ARM\RV31\INC\stdlib.h 3 | ..\Output\mbfuncholding.o: h:\Keil\ARM\RV31\INC\string.h 4 | ..\Output\mbfuncholding.o: ..\modbus\port\port.h 5 | ..\Output\mbfuncholding.o: ..\CMSIS\stm32f10x.h 6 | ..\Output\mbfuncholding.o: ..\CMSIS\core_cm3.h 7 | ..\Output\mbfuncholding.o: h:\Keil\ARM\RV31\INC\stdint.h 8 | ..\Output\mbfuncholding.o: ..\CMSIS\system_stm32f10x.h 9 | ..\Output\mbfuncholding.o: ..\USER\stm32f10x_conf.h 10 | ..\Output\mbfuncholding.o: ..\FWlib\inc\stm32f10x_gpio.h 11 | ..\Output\mbfuncholding.o: ..\CMSIS\stm32f10x.h 12 | ..\Output\mbfuncholding.o: ..\FWlib\inc\stm32f10x_rcc.h 13 | ..\Output\mbfuncholding.o: ..\FWlib\inc\stm32f10x_tim.h 14 | ..\Output\mbfuncholding.o: ..\FWlib\inc\stm32f10x_usart.h 15 | ..\Output\mbfuncholding.o: ..\FWlib\inc\misc.h 16 | ..\Output\mbfuncholding.o: ..\modbus\include\mb.h 17 | ..\Output\mbfuncholding.o: ..\modbus\include\mbport.h 18 | ..\Output\mbfuncholding.o: ..\modbus\include\mbproto.h 19 | ..\Output\mbfuncholding.o: ..\modbus\include\mbframe.h 20 | ..\Output\mbfuncholding.o: ..\modbus\include\mbconfig.h 21 | -------------------------------------------------------------------------------- /modbus/functions/mbfuncdiag.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbfuncdiag.c,v 1.3 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | -------------------------------------------------------------------------------- /modbus/rtu/mbcrc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbcrc.h,v 1.5 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_CRC_H 32 | #define _MB_CRC_H 33 | 34 | USHORT usMBCRC16( UCHAR * pucFrame, USHORT usLen ); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /modbus/port/portevent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: MSP430 Port 3 | * Copyright (C) 2006 Christian Walter 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | * File: $Id: portevent.c,v 1.1 2006/11/19 03:00:34 wolti Exp $ 20 | */ 21 | 22 | /* ----------------------- Modbus includes ----------------------------------*/ 23 | #include "mb.h" 24 | #include "mbport.h" 25 | 26 | /* ----------------------- Variables ----------------------------------------*/ 27 | static eMBEventType eQueuedEvent; 28 | static BOOL xEventInQueue; 29 | 30 | /* ----------------------- Start implementation -----------------------------*/ 31 | BOOL 32 | xMBPortEventInit( void ) 33 | { 34 | xEventInQueue = FALSE; 35 | return TRUE; 36 | } 37 | 38 | BOOL 39 | xMBPortEventPost( eMBEventType eEvent ) 40 | { 41 | xEventInQueue = TRUE; 42 | eQueuedEvent = eEvent; 43 | return TRUE; 44 | } 45 | 46 | BOOL 47 | xMBPortEventGet( eMBEventType * eEvent ) 48 | { 49 | BOOL xEventHappened = FALSE; 50 | 51 | if( xEventInQueue ) 52 | { 53 | *eEvent = eQueuedEvent; 54 | xEventInQueue = FALSE; 55 | xEventHappened = TRUE; 56 | } 57 | return xEventHappened; 58 | } 59 | -------------------------------------------------------------------------------- /USER/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/Template/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F10x_IT_H 23 | #define __STM32F10x_IT_H 24 | 25 | /* Includes ------------------------------------------------------------------*/ 26 | #include "stm32f10x.h" 27 | 28 | /* Exported types ------------------------------------------------------------*/ 29 | /* Exported constants --------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | /* Exported functions ------------------------------------------------------- */ 32 | 33 | void NMI_Handler(void); 34 | void HardFault_Handler(void); 35 | void MemManage_Handler(void); 36 | void BusFault_Handler(void); 37 | void UsageFault_Handler(void); 38 | void SVC_Handler(void); 39 | void DebugMon_Handler(void); 40 | void PendSV_Handler(void); 41 | void SysTick_Handler(void); 42 | 43 | #endif /* __STM32F10x_IT_H */ 44 | 45 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 46 | -------------------------------------------------------------------------------- /modbus/port/port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: MSP430 Port 3 | * Copyright (C) 2006 Christian Walter 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | * File: $Id: port.h,v 1.2 2006/11/19 03:36:01 wolti Exp $ 20 | */ 21 | 22 | #ifndef _PORT_H 23 | #define _PORT_H 24 | 25 | /* ----------------------- Platform includes --------------------------------*/ 26 | 27 | #include "stm32f10x.h" 28 | #if defined (__GNUC__) 29 | #include 30 | #endif 31 | #undef CHAR 32 | 33 | /* ----------------------- Defines ------------------------------------------*/ 34 | #define INLINE 35 | #define PR_BEGIN_EXTERN_C extern "C" { 36 | #define PR_END_EXTERN_C } 37 | 38 | #define ENTER_CRITICAL_SECTION( ) EnterCriticalSection( ) 39 | #define EXIT_CRITICAL_SECTION( ) ExitCriticalSection( ) 40 | #define assert( expr ) 41 | 42 | #define SMCLK ( 4000000UL ) 43 | #define ACLK ( 32768UL ) 44 | 45 | typedef char BOOL; 46 | 47 | typedef unsigned char UCHAR; 48 | 49 | typedef char CHAR; 50 | 51 | typedef unsigned short USHORT; 52 | typedef short SHORT; 53 | 54 | typedef unsigned long ULONG; 55 | typedef long LONG; 56 | 57 | #ifndef TRUE 58 | #define TRUE 1 59 | #endif 60 | 61 | #ifndef FALSE 62 | #define FALSE 0 63 | #endif 64 | 65 | void EnterCriticalSection( void ); 66 | void ExitCriticalSection( void ); 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CRC_H 24 | #define __STM32F10x_CRC_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup CRC 34 | * @{ 35 | */ 36 | 37 | /** @defgroup CRC_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup CRC_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** @defgroup CRC_Exported_Macros 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup CRC_Exported_Functions 62 | * @{ 63 | */ 64 | 65 | void CRC_ResetDR(void); 66 | uint32_t CRC_CalcCRC(uint32_t Data); 67 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 68 | uint32_t CRC_GetCRC(void); 69 | void CRC_SetIDRegister(uint8_t IDValue); 70 | uint8_t CRC_GetIDRegister(void); 71 | 72 | #endif /* __STM32F10x_CRC_H */ 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 86 | -------------------------------------------------------------------------------- /CMSIS/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 5 | * @author STMicroelectronics - MCD Application Team 6 | * @version V3.0.0 7 | * @date 04/06/2009 8 | ****************************************************************************** 9 | * 10 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 12 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 13 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 14 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 15 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 16 | * 17 | *

© COPYRIGHT 2009 STMicroelectronics

18 | ****************************************************************************** 19 | */ 20 | 21 | /** 22 | * @brief Define to prevent recursive inclusion 23 | */ 24 | #ifndef __SYSTEM_STM32F10X_H 25 | #define __SYSTEM_STM32F10X_H 26 | 27 | /** @addtogroup Includes 28 | * @{ 29 | */ 30 | 31 | /** 32 | * @} 33 | */ 34 | 35 | 36 | /** @addtogroup Exported_types 37 | * @{ 38 | */ 39 | 40 | extern const uint32_t SystemFrequency; /*!< System Clock Frequency (Core Clock) */ 41 | extern const uint32_t SystemFrequency_SysClk; /*!< System clock */ 42 | extern const uint32_t SystemFrequency_AHBClk; /*!< AHB System bus speed */ 43 | extern const uint32_t SystemFrequency_APB1Clk; /*!< APB Peripheral Bus 1 (low) speed */ 44 | extern const uint32_t SystemFrequency_APB2Clk; /*!< APB Peripheral Bus 2 (high) speed */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @addtogroup Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @addtogroup Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup Exported_Functions 67 | * @{ 68 | */ 69 | 70 | extern void SystemInit(void); 71 | /** 72 | * @} 73 | */ 74 | 75 | #endif /*__SYSTEM_STM32F10X_H */ 76 | 77 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /modbus/rtu/mbrtu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbrtu.h,v 1.9 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_RTU_H 32 | #define _MB_RTU_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | eMBErrorCode eMBRTUInit( UCHAR slaveAddress, UCHAR ucPort, ULONG ulBaudRate, 38 | eMBParity eParity ); 39 | void eMBRTUStart( void ); 40 | void eMBRTUStop( void ); 41 | eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ); 42 | eMBErrorCode eMBRTUSend( UCHAR slaveAddress, const UCHAR * pucFrame, USHORT usLength ); 43 | BOOL xMBRTUReceiveFSM( void ); 44 | BOOL xMBRTUTransmitFSM( void ); 45 | BOOL xMBRTUTimerT15Expired( void ); 46 | BOOL xMBRTUTimerT35Expired( void ); 47 | 48 | #ifdef __cplusplus 49 | PR_END_EXTERN_C 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /modbus/tcp/mbtcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbtcp.h,v 1.2 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_TCP_H 32 | #define _MB_TCP_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | 38 | /* ----------------------- Defines ------------------------------------------*/ 39 | #define MB_TCP_PSEUDO_ADDRESS 255 40 | 41 | /* ----------------------- Function prototypes ------------------------------*/ 42 | eMBErrorCode eMBTCPDoInit( USHORT ucTCPPort ); 43 | void eMBTCPStart( void ); 44 | void eMBTCPStop( void ); 45 | eMBErrorCode eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, 46 | USHORT * pusLength ); 47 | eMBErrorCode eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame, 48 | USHORT usLength ); 49 | 50 | #ifdef __cplusplus 51 | PR_END_EXTERN_C 52 | #endif 53 | #endif 54 | -------------------------------------------------------------------------------- /modbus/ascii/mbascii.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbascii.h,v 1.8 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_ASCII_H 32 | #define _MB_ASCII_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | 38 | #if MB_ASCII_ENABLED > 0 39 | eMBErrorCode eMBASCIIInit( UCHAR slaveAddress, UCHAR ucPort, 40 | ULONG ulBaudRate, eMBParity eParity ); 41 | void eMBASCIIStart( void ); 42 | void eMBASCIIStop( void ); 43 | 44 | eMBErrorCode eMBASCIIReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, 45 | USHORT * pusLength ); 46 | eMBErrorCode eMBASCIISend( UCHAR slaveAddress, const UCHAR * pucFrame, 47 | USHORT usLength ); 48 | BOOL xMBASCIIReceiveFSM( void ); 49 | BOOL xMBASCIITransmitFSM( void ); 50 | BOOL xMBASCIITimerT1SExpired( void ); 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | PR_END_EXTERN_C 55 | #endif 56 | #endif 57 | -------------------------------------------------------------------------------- /Output/STM32-DEMO.tra: -------------------------------------------------------------------------------- 1 | *** Creating Trace Output File '..\Output\STM32-DEMO.tra' Ok. 2 | ### Preparing for ADS-LD. 3 | ### Creating ADS-LD Command Line 4 | ### List of Objects: adding '"..\output\startup_stm32f10x_hd.o"' 5 | ### List of Objects: adding '"..\output\main.o"' 6 | ### List of Objects: adding '"..\output\stm32f10x_it.o"' 7 | ### List of Objects: adding '"..\output\stm32f10x_gpio.o"' 8 | ### List of Objects: adding '"..\output\stm32f10x_rcc.o"' 9 | ### List of Objects: adding '"..\output\stm32f10x_tim.o"' 10 | ### List of Objects: adding '"..\output\stm32f10x_usart.o"' 11 | ### List of Objects: adding '"..\output\misc.o"' 12 | ### List of Objects: adding '"..\output\core_cm3.o"' 13 | ### List of Objects: adding '"..\output\system_stm32f10x.o"' 14 | ### List of Objects: adding '"..\output\mbtcp.o"' 15 | ### List of Objects: adding '"..\output\mbcrc.o"' 16 | ### List of Objects: adding '"..\output\mbrtu.o"' 17 | ### List of Objects: adding '"..\output\mbascii.o"' 18 | ### List of Objects: adding '"..\output\mbfunccoils.o"' 19 | ### List of Objects: adding '"..\output\mbfuncdiag.o"' 20 | ### List of Objects: adding '"..\output\mbfuncdisc.o"' 21 | ### List of Objects: adding '"..\output\mbfuncholding.o"' 22 | ### List of Objects: adding '"..\output\mbfuncinput.o"' 23 | ### List of Objects: adding '"..\output\mbfuncother.o"' 24 | ### List of Objects: adding '"..\output\mbutils.o"' 25 | ### List of Objects: adding '"..\output\mb.o"' 26 | ### List of Objects: adding '"..\output\portevent.o"' 27 | ### List of Objects: adding '"..\output\portserial.o"' 28 | ### List of Objects: adding '"..\output\porttimer.o"' 29 | ### ADS-LD Command completed: 30 | --cpu Cortex-M3 "..\output\startup_stm32f10x_hd.o" "..\output\main.o" "..\output\stm32f10x_it.o" "..\output\stm32f10x_gpio.o" "..\output\stm32f10x_rcc.o" "..\output\stm32f10x_tim.o" "..\output\stm32f10x_usart.o" "..\output\misc.o" "..\output\core_cm3.o" "..\output\system_stm32f10x.o" "..\output\mbtcp.o" "..\output\mbcrc.o" "..\output\mbrtu.o" "..\output\mbascii.o" "..\output\mbfunccoils.o" "..\output\mbfuncdiag.o" "..\output\mbfuncdisc.o" "..\output\mbfuncholding.o" "..\output\mbfuncinput.o" "..\output\mbfuncother.o" "..\output\mbutils.o" "..\output\mb.o" "..\output\portevent.o" "..\output\portserial.o" "..\output\porttimer.o" --library_type=microlib --ro-base 0x08000000 --entry 0x08000000 --rw-base 0x20000000 --entry Reset_Handler --first __Vectors --strict --autoat --summary_stderr --info summarysizes --map --xref --callgraph --symbols 31 | --info sizes --info totals --info unused --info veneers 32 | --list "..\Listing\STM32-DEMO.map" -o "..\Output\STM32-DEMO.axf"### Preparing Environment (PrepEnvAds) 33 | ### ADS-LD Output File: '..\Output\STM32-DEMO.axf' 34 | ### ADS-LD Command File: '..\Output\STM32-DEMO.lnp' 35 | ### Checking for dirty Components... 36 | ### Creating CmdFile '..\Output\STM32-DEMO.lnp', Handle=0x00000240 37 | ### Writing '.lnp' file 38 | ### ADS-LD Command file '..\Output\STM32-DEMO.lnp' is ready. 39 | ### ADS-LD: About to start ADS-LD Thread. 40 | ### ADS-LD: executed with 0 errors 41 | ### Updating obj list 42 | ### LDADS_file() completed. 43 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the WWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_WWDG_H 24 | #define __STM32F10x_WWDG_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup WWDG 34 | * @{ 35 | */ 36 | 37 | /** @defgroup WWDG_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup WWDG_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** @defgroup WWDG_Prescaler 50 | * @{ 51 | */ 52 | 53 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 54 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 55 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 56 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 57 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 58 | ((PRESCALER) == WWDG_Prescaler_2) || \ 59 | ((PRESCALER) == WWDG_Prescaler_4) || \ 60 | ((PRESCALER) == WWDG_Prescaler_8)) 61 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 62 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup WWDG_Exported_Macros 73 | * @{ 74 | */ 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup WWDG_Exported_Functions 80 | * @{ 81 | */ 82 | 83 | void WWDG_DeInit(void); 84 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 85 | void WWDG_SetWindowValue(uint8_t WindowValue); 86 | void WWDG_EnableIT(void); 87 | void WWDG_SetCounter(uint8_t Counter); 88 | void WWDG_Enable(uint8_t Counter); 89 | FlagStatus WWDG_GetFlagStatus(void); 90 | void WWDG_ClearFlag(void); 91 | 92 | #endif /* __STM32F10x_WWDG_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 107 | -------------------------------------------------------------------------------- /modbus/include/mbfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbfunc.h,v 1.12 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_FUNC_H 32 | #define _MB_FUNC_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | #if MB_FUNC_OTHER_REP_SLAVEID_BUF > 0 38 | eMBException eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen ); 39 | #endif 40 | 41 | #if MB_FUNC_READ_INPUT_ENABLED > 0 42 | eMBException eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen ); 43 | #endif 44 | 45 | #if MB_FUNC_READ_HOLDING_ENABLED > 0 46 | eMBException eMBFuncReadHoldingRegister( UCHAR * pucFrame, USHORT * usLen ); 47 | #endif 48 | 49 | #if MB_FUNC_WRITE_HOLDING_ENABLED > 0 50 | eMBException eMBFuncWriteHoldingRegister( UCHAR * pucFrame, USHORT * usLen ); 51 | #endif 52 | 53 | #if MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED > 0 54 | eMBException eMBFuncWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen ); 55 | #endif 56 | 57 | #if MB_FUNC_READ_COILS_ENABLED > 0 58 | eMBException eMBFuncReadCoils( UCHAR * pucFrame, USHORT * usLen ); 59 | #endif 60 | 61 | #if MB_FUNC_WRITE_COIL_ENABLED > 0 62 | eMBException eMBFuncWriteCoil( UCHAR * pucFrame, USHORT * usLen ); 63 | #endif 64 | 65 | #if MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED > 0 66 | eMBException eMBFuncWriteMultipleCoils( UCHAR * pucFrame, USHORT * usLen ); 67 | #endif 68 | 69 | #if MB_FUNC_READ_DISCRETE_INPUTS_ENABLED > 0 70 | eMBException eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen ); 71 | #endif 72 | 73 | #if MB_FUNC_READWRITE_HOLDING_ENABLED > 0 74 | eMBException eMBFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen ); 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | PR_END_EXTERN_C 79 | #endif 80 | #endif 81 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_DBGMCU_H 24 | #define __STM32F10x_DBGMCU_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup DBGMCU 34 | * @{ 35 | */ 36 | 37 | /** @defgroup DBGMCU_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup DBGMCU_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 50 | #define DBGMCU_STOP ((uint32_t)0x00000002) 51 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 52 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 53 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 54 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 55 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 56 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 57 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 58 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 59 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 60 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 61 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 62 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 63 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 64 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 65 | 66 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFE000F8) == 0x00) && ((PERIPH) != 0x00)) 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup DBGMCU_Exported_Macros 72 | * @{ 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup DBGMCU_Exported_Functions 80 | * @{ 81 | */ 82 | 83 | uint32_t DBGMCU_GetREVID(void); 84 | uint32_t DBGMCU_GetDEVID(void); 85 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 86 | 87 | #endif /* __STM32F10x_DBGMCU_H */ 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /USER/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file RCC/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F10x_CONF_H 23 | #define __STM32F10x_CONF_H 24 | 25 | /* Includes ------------------------------------------------------------------*/ 26 | /* Uncomment the line below to enable peripheral header file inclusion */ 27 | /* #include "stm32f10x_adc.h" */ 28 | /* #include "stm32f10x_bkp.h" */ 29 | /* #include "stm32f10x_can.h" */ 30 | /* #include "stm32f10x_crc.h" */ 31 | /* #include "stm32f10x_dac.h" */ 32 | /* #include "stm32f10x_dbgmcu.h" */ 33 | /* #include "stm32f10x_dma.h" */ 34 | /* #include "stm32f10x_exti.h" */ 35 | /*#include "stm32f10x_flash.h"*/ 36 | /* #include "stm32f10x_fsmc.h" */ 37 | #include "stm32f10x_gpio.h" 38 | /* #include "stm32f10x_i2c.h" */ 39 | /* #include "stm32f10x_iwdg.h" */ 40 | /* #include "stm32f10x_pwr.h" */ 41 | #include "stm32f10x_rcc.h" 42 | /* #include "stm32f10x_rtc.h" */ 43 | /* #include "stm32f10x_sdio.h" */ 44 | /* #include "stm32f10x_spi.h" */ 45 | #include "stm32f10x_tim.h" 46 | #include "stm32f10x_usart.h" 47 | /* #include "stm32f10x_wwdg.h" */ 48 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | /* Exported constants --------------------------------------------------------*/ 52 | /* Uncomment the line below to expanse the "assert_param" macro in the 53 | Standard Peripheral Library drivers code */ 54 | /* #define USE_FULL_ASSERT 1 */ 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | #ifdef USE_FULL_ASSERT 58 | 59 | /** 60 | * @brief The assert_param macro is used for function's parameters check. 61 | * @param expr: If expr is false, it calls assert_failed function 62 | * which reports the name of the source file and the source 63 | * line number of the call that failed. 64 | * If expr is true, it returns no value. 65 | * @retval : None 66 | */ 67 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 68 | /* Exported functions ------------------------------------------------------- */ 69 | void assert_failed(uint8_t* file, uint32_t line); 70 | #else 71 | #define assert_param(expr) ((void)0) 72 | #endif /* USE_FULL_ASSERT */ 73 | 74 | #endif /* __STM32F10x_CONF_H */ 75 | 76 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /modbus/functions/mbfuncother.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbfuncother.c,v 1.8 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | /* ----------------------- System includes ----------------------------------*/ 32 | #include "stdlib.h" 33 | #include "string.h" 34 | 35 | /* ----------------------- Platform includes --------------------------------*/ 36 | #include "port.h" 37 | 38 | /* ----------------------- Modbus includes ----------------------------------*/ 39 | #include "mb.h" 40 | #include "mbframe.h" 41 | #include "mbproto.h" 42 | #include "mbconfig.h" 43 | 44 | #if MB_FUNC_OTHER_REP_SLAVEID_ENABLED > 0 45 | 46 | /* ----------------------- Static variables ---------------------------------*/ 47 | static UCHAR ucMBSlaveID[MB_FUNC_OTHER_REP_SLAVEID_BUF]; 48 | static USHORT usMBSlaveIDLen; 49 | 50 | /* ----------------------- Start implementation -----------------------------*/ 51 | 52 | eMBErrorCode 53 | eMBSetSlaveID( UCHAR ucSlaveID, BOOL xIsRunning, 54 | UCHAR const *pucAdditional, USHORT usAdditionalLen ) 55 | { 56 | eMBErrorCode eStatus = MB_ENOERR; 57 | 58 | /* the first byte and second byte in the buffer is reserved for 59 | * the parameter ucSlaveID and the running flag. The rest of 60 | * the buffer is available for additional data. */ 61 | if( usAdditionalLen + 2 < MB_FUNC_OTHER_REP_SLAVEID_BUF ) 62 | { 63 | usMBSlaveIDLen = 0; 64 | ucMBSlaveID[usMBSlaveIDLen++] = ucSlaveID; 65 | ucMBSlaveID[usMBSlaveIDLen++] = ( UCHAR )( xIsRunning ? 0xFF : 0x00 ); 66 | if( usAdditionalLen > 0 ) 67 | { 68 | memcpy( &ucMBSlaveID[usMBSlaveIDLen], pucAdditional, 69 | ( size_t )usAdditionalLen ); 70 | usMBSlaveIDLen += usAdditionalLen; 71 | } 72 | } 73 | else 74 | { 75 | eStatus = MB_ENORES; 76 | } 77 | return eStatus; 78 | } 79 | 80 | eMBException 81 | eMBFuncReportSlaveID( UCHAR * pucFrame, USHORT * usLen ) 82 | { 83 | memcpy( &pucFrame[MB_PDU_DATA_OFF], &ucMBSlaveID[0], ( size_t )usMBSlaveIDLen ); 84 | *usLen = ( USHORT )( MB_PDU_DATA_OFF + usMBSlaveIDLen ); 85 | return MB_EX_NONE; 86 | } 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /modbus/include/mbproto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_PROTO_H 32 | #define _MB_PROTO_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | /* ----------------------- Defines ------------------------------------------*/ 38 | #define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */ 39 | #define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */ 40 | #define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */ 41 | #define MB_FUNC_NONE ( 0 ) 42 | #define MB_FUNC_READ_COILS ( 1 ) 43 | #define MB_FUNC_READ_DISCRETE_INPUTS ( 2 ) 44 | #define MB_FUNC_WRITE_SINGLE_COIL ( 5 ) 45 | #define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 ) 46 | #define MB_FUNC_READ_HOLDING_REGISTER ( 3 ) 47 | #define MB_FUNC_READ_INPUT_REGISTER ( 4 ) 48 | #define MB_FUNC_WRITE_REGISTER ( 6 ) 49 | #define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 ) 50 | #define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 ) 51 | #define MB_FUNC_DIAG_READ_EXCEPTION ( 7 ) 52 | #define MB_FUNC_DIAG_DIAGNOSTIC ( 8 ) 53 | #define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 ) 54 | #define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 ) 55 | #define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 ) 56 | #define MB_FUNC_ERROR ( 128 ) 57 | /* ----------------------- Type definitions ---------------------------------*/ 58 | typedef enum 59 | { 60 | MB_EX_NONE = 0x00, 61 | MB_EX_ILLEGAL_FUNCTION = 0x01, 62 | MB_EX_ILLEGAL_DATA_ADDRESS = 0x02, 63 | MB_EX_ILLEGAL_DATA_VALUE = 0x03, 64 | MB_EX_SLAVE_DEVICE_FAILURE = 0x04, 65 | MB_EX_ACKNOWLEDGE = 0x05, 66 | MB_EX_SLAVE_BUSY = 0x06, 67 | MB_EX_MEMORY_PARITY_ERROR = 0x08, 68 | MB_EX_GATEWAY_PATH_FAILED = 0x0A, 69 | MB_EX_GATEWAY_TGT_FAILED = 0x0B 70 | } eMBException; 71 | 72 | typedef eMBException( *pxMBFunctionHandler ) ( UCHAR * pucFrame, USHORT * pusLength ); 73 | 74 | typedef struct 75 | { 76 | UCHAR ucFunctionCode; 77 | pxMBFunctionHandler pxHandler; 78 | } xMBFunctionHandler; 79 | 80 | #ifdef __cplusplus 81 | PR_END_EXTERN_C 82 | #endif 83 | #endif 84 | -------------------------------------------------------------------------------- /modbus/include/mbframe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbframe.h,v 1.9 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_FRAME_H 32 | #define _MB_FRAME_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | 38 | /*! 39 | * Constants which defines the format of a modbus frame. The example is 40 | * shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not 41 | * dependent on the underlying transport. 42 | * 43 | * 44 | * <------------------------ MODBUS SERIAL LINE PDU (1) -------------------> 45 | * <----------- MODBUS PDU (1') ----------------> 46 | * +-----------+---------------+----------------------------+-------------+ 47 | * | Address | Function Code | Data | CRC/LRC | 48 | * +-----------+---------------+----------------------------+-------------+ 49 | * | | | | 50 | * (2) (3/2') (3') (4) 51 | * 52 | * (1) ... MB_SER_PDU_SIZE_MAX = 256 53 | * (2) ... MB_SER_PDU_ADDR_OFF = 0 54 | * (3) ... MB_SER_PDU_PDU_OFF = 1 55 | * (4) ... MB_SER_PDU_SIZE_CRC = 2 56 | * 57 | * (1') ... MB_PDU_SIZE_MAX = 253 58 | * (2') ... MB_PDU_FUNC_OFF = 0 59 | * (3') ... MB_PDU_DATA_OFF = 1 60 | * 61 | */ 62 | 63 | /* ----------------------- Defines ------------------------------------------*/ 64 | #define MB_PDU_SIZE_MAX 253 /*!< Maximum size of a PDU. */ 65 | #define MB_PDU_SIZE_MIN 1 /*!< Function Code */ 66 | #define MB_PDU_FUNC_OFF 0 /*!< Offset of function code in PDU. */ 67 | #define MB_PDU_DATA_OFF 1 /*!< Offset for response data in PDU. */ 68 | 69 | /* ----------------------- Prototypes 0-------------------------------------*/ 70 | typedef void ( *pvMBFrameStart ) ( void ); 71 | 72 | typedef void ( *pvMBFrameStop ) ( void ); 73 | 74 | typedef eMBErrorCode( *peMBFrameReceive ) ( UCHAR * pucRcvAddress, 75 | UCHAR ** pucFrame, 76 | USHORT * pusLength ); 77 | 78 | typedef eMBErrorCode( *peMBFrameSend ) ( UCHAR slaveAddress, 79 | const UCHAR * pucFrame, 80 | USHORT usLength ); 81 | 82 | typedef void( *pvMBFrameClose ) ( void ); 83 | 84 | #ifdef __cplusplus 85 | PR_END_EXTERN_C 86 | #endif 87 | #endif 88 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_crc.h" 23 | 24 | /** @addtogroup StdPeriph_Driver 25 | * @{ 26 | */ 27 | 28 | /** @defgroup CRC 29 | * @brief CRC driver modules 30 | * @{ 31 | */ 32 | 33 | /** @defgroup CRC_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @} 39 | */ 40 | 41 | /** @defgroup CRC_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /* CR register bit mask */ 46 | 47 | #define CR_RESET_Set ((uint32_t)0x00000001) 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /** @defgroup CRC_Private_Macros 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup CRC_Private_Variables 62 | * @{ 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup CRC_Private_FunctionPrototypes 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup CRC_Private_Functions 78 | * @{ 79 | */ 80 | 81 | /** 82 | * @brief Resets the CRC Data register (DR). 83 | * @param None 84 | * @retval : None 85 | */ 86 | void CRC_ResetDR(void) 87 | { 88 | /* Reset CRC generator */ 89 | CRC->CR = CR_RESET_Set; 90 | } 91 | 92 | /** 93 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 94 | * @param Data: data word(32-bit) to compute its CRC 95 | * @retval : 32-bit CRC 96 | */ 97 | uint32_t CRC_CalcCRC(uint32_t Data) 98 | { 99 | CRC->DR = Data; 100 | 101 | return (CRC->DR); 102 | } 103 | 104 | /** 105 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 106 | * @param pBuffer: pointer to the buffer containing the data to be 107 | * computed 108 | * @param BufferLength: length of the buffer to be computed 109 | * @retval : 32-bit CRC 110 | */ 111 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 112 | { 113 | uint32_t index = 0; 114 | 115 | for(index = 0; index < BufferLength; index++) 116 | { 117 | CRC->DR = pBuffer[index]; 118 | } 119 | return (CRC->DR); 120 | } 121 | 122 | /** 123 | * @brief Returns the current CRC value. 124 | * @param None 125 | * @retval : 32-bit CRC 126 | */ 127 | uint32_t CRC_GetCRC(void) 128 | { 129 | return (CRC->DR); 130 | } 131 | 132 | /** 133 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 134 | * @param IDValue: 8-bit value to be stored in the ID register 135 | * @retval : None 136 | */ 137 | void CRC_SetIDRegister(uint8_t IDValue) 138 | { 139 | CRC->IDR = IDValue; 140 | } 141 | 142 | /** 143 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 144 | * @param None 145 | * @retval : 8-bit value of the ID register 146 | */ 147 | uint8_t CRC_GetIDRegister(void) 148 | { 149 | return (CRC->IDR); 150 | } 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 165 | -------------------------------------------------------------------------------- /USER/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f10x.h" 3 | #include "mb.h" 4 | 5 | void NVIC_Configuration(void) 6 | { 7 | NVIC_InitTypeDef NVIC_InitStructure; 8 | 9 | /* Enable the TIM2 gloabal Interrupt */ 10 | NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; 11 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 12 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; 13 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 14 | 15 | NVIC_Init(&NVIC_InitStructure); 16 | 17 | /* Enable the TIM2 gloabal Interrupt */ 18 | NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; 19 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 20 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; 21 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 22 | 23 | NVIC_Init(&NVIC_InitStructure); 24 | } 25 | 26 | int main(void) 27 | { 28 | SystemInit(); 29 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); 30 | NVIC_Configuration(); 31 | 32 | eMBInit( MB_RTU, 0x01, 0, 9600, MB_PAR_NONE ); 33 | 34 | /* Enable the Modbus Protocol Stack. */ 35 | eMBEnable( ); 36 | 37 | for( ;; ) 38 | { 39 | ( void )eMBPoll( ); 40 | /* Here we simply count the number of poll cycles. */ 41 | } 42 | } 43 | 44 | eMBErrorCode 45 | eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs ) 46 | { 47 | eMBErrorCode eStatus = MB_ENOERR; 48 | static uint8_t flag = 0; 49 | 50 | flag == 0 ? GPIO_SetBits(GPIOC,GPIO_Pin_1) : GPIO_ResetBits(GPIOC,GPIO_Pin_1); 51 | flag ^= 1; 52 | return eStatus; 53 | } 54 | 55 | /* add test */ 56 | /* holding register address */ 57 | #define REG_HOLDING_START 0x0000 58 | /* number of regs */ 59 | #define REG_HOLDING_NREGS 8 60 | /* content of the holding regs 61 | the test data is from xukai's port */ 62 | uint16_t usRegHoldingBuf[REG_HOLDING_NREGS] = {0x147b,0x3f8e, 63 | 0x147b,0x400e,0x1eb8,0x4055,0x147b,0x408e}; 64 | eMBErrorCode 65 | eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode ) 66 | { 67 | /* error state */ 68 | eMBErrorCode eStatus = MB_ENOERR; 69 | /* offset */ 70 | int16_t iRegIndex; 71 | 72 | /* test if the reg is in the range */ 73 | if (((int16_t)usAddress-1 >= REG_HOLDING_START) 74 | && (usAddress-1 + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS)) 75 | { 76 | /* compute the reg's offset */ 77 | iRegIndex = (int16_t)(usAddress-1 - REG_HOLDING_START); 78 | switch (eMode) 79 | { 80 | case MB_REG_READ: 81 | while (usNRegs > 0) 82 | { 83 | *pucRegBuffer++ = (uint8_t)( usRegHoldingBuf[iRegIndex] >> 8 ); 84 | *pucRegBuffer++ = (uint8_t)( usRegHoldingBuf[iRegIndex] & 0xff); 85 | iRegIndex ++; 86 | usNRegs --; 87 | } 88 | break; 89 | case MB_REG_WRITE: 90 | while (usNRegs > 0) 91 | { 92 | usRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8; 93 | usRegHoldingBuf[iRegIndex] |= *pucRegBuffer++; 94 | iRegIndex ++; 95 | usNRegs --; 96 | } 97 | break; 98 | 99 | } 100 | } 101 | else{ 102 | eStatus = MB_ENOREG; 103 | } 104 | 105 | return eStatus; 106 | 107 | } 108 | 109 | 110 | eMBErrorCode 111 | eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode ) 112 | { 113 | static uint8_t flag = 0; 114 | 115 | flag == 0 ? GPIO_SetBits(GPIOC,GPIO_Pin_3) : GPIO_ResetBits(GPIOC,GPIO_Pin_3); 116 | flag ^= 1; 117 | return MB_ENOREG; 118 | } 119 | 120 | eMBErrorCode 121 | eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete ) 122 | { 123 | static uint8_t flag = 0; 124 | 125 | flag == 0 ? GPIO_SetBits(GPIOC,GPIO_Pin_4) : GPIO_ResetBits(GPIOC,GPIO_Pin_4); 126 | flag ^= 1; 127 | return MB_ENOREG; 128 | } -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_RTC_H 24 | #define __STM32F10x_RTC_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup RTC 34 | * @{ 35 | */ 36 | 37 | /** @defgroup RTC_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup RTC_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** @defgroup RTC_interrupts_define 50 | * @{ 51 | */ 52 | 53 | #define RTC_IT_OW ((uint16_t)0x0004) /* Overflow interrupt */ 54 | #define RTC_IT_ALR ((uint16_t)0x0002) /* Alarm interrupt */ 55 | #define RTC_IT_SEC ((uint16_t)0x0001) /* Second interrupt */ 56 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 57 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 58 | ((IT) == RTC_IT_SEC)) 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup RTC_interrupts_flags 64 | * @{ 65 | */ 66 | 67 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /* RTC Operation OFF flag */ 68 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /* Registers Synchronized flag */ 69 | #define RTC_FLAG_OW ((uint16_t)0x0004) /* Overflow flag */ 70 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /* Alarm flag */ 71 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /* Second flag */ 72 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 73 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 74 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 75 | ((FLAG) == RTC_FLAG_SEC)) 76 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup RTC_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup RTC_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 99 | void RTC_EnterConfigMode(void); 100 | void RTC_ExitConfigMode(void); 101 | uint32_t RTC_GetCounter(void); 102 | void RTC_SetCounter(uint32_t CounterValue); 103 | void RTC_SetPrescaler(uint32_t PrescalerValue); 104 | void RTC_SetAlarm(uint32_t AlarmValue); 105 | uint32_t RTC_GetDivider(void); 106 | void RTC_WaitForLastTask(void); 107 | void RTC_WaitForSynchro(void); 108 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 109 | void RTC_ClearFlag(uint16_t RTC_FLAG); 110 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 111 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 112 | 113 | #endif /* __STM32F10x_RTC_H */ 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** 123 | * @} 124 | */ 125 | 126 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 127 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IWDG_H 24 | #define __STM32F10x_IWDG_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup IWDG 34 | * @{ 35 | */ 36 | 37 | /** @defgroup IWDG_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup IWDG_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** @defgroup Write_access_to_IWDG_PR_and_IWDG_RLR_registers 50 | * @{ 51 | */ 52 | 53 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 54 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 55 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 56 | ((ACCESS) == IWDG_WriteAccess_Disable)) 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup IWDG_prescaler 62 | * @{ 63 | */ 64 | 65 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 66 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 67 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 68 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 69 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 70 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 71 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 72 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 73 | ((PRESCALER) == IWDG_Prescaler_8) || \ 74 | ((PRESCALER) == IWDG_Prescaler_16) || \ 75 | ((PRESCALER) == IWDG_Prescaler_32) || \ 76 | ((PRESCALER) == IWDG_Prescaler_64) || \ 77 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 78 | ((PRESCALER) == IWDG_Prescaler_256)) 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup IWDG_Flag 84 | * @{ 85 | */ 86 | 87 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 88 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 89 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 90 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup IWDG_Exported_Macros 100 | * @{ 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** @defgroup IWDG_Exported_Functions 108 | * @{ 109 | */ 110 | 111 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 112 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 113 | void IWDG_SetReload(uint16_t Reload); 114 | void IWDG_ReloadCounter(void); 115 | void IWDG_Enable(void); 116 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 117 | 118 | #endif /* __STM32F10x_IWDG_H */ 119 | /** 120 | * @} 121 | */ 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /modbus/include/mbutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_UTILS_H 32 | #define _MB_UTILS_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | /*! \defgroup modbus_utils Utilities 38 | * 39 | * This module contains some utility functions which can be used by 40 | * the application. It includes some special functions for working with 41 | * bitfields backed by a character array buffer. 42 | * 43 | */ 44 | /*! \addtogroup modbus_utils 45 | * @{ 46 | */ 47 | /*! \brief Function to set bits in a byte buffer. 48 | * 49 | * This function allows the efficient use of an array to implement bitfields. 50 | * The array used for storing the bits must always be a multiple of two 51 | * bytes. Up to eight bits can be set or cleared in one operation. 52 | * 53 | * \param ucByteBuf A buffer where the bit values are stored. Must be a 54 | * multiple of 2 bytes. No length checking is performed and if 55 | * usBitOffset / 8 is greater than the size of the buffer memory contents 56 | * is overwritten. 57 | * \param usBitOffset The starting address of the bits to set. The first 58 | * bit has the offset 0. 59 | * \param ucNBits Number of bits to modify. The value must always be smaller 60 | * than 8. 61 | * \param ucValues Thew new values for the bits. The value for the first bit 62 | * starting at usBitOffset is the LSB of the value 63 | * ucValues 64 | * 65 | * \code 66 | * ucBits[2] = {0, 0}; 67 | * 68 | * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1) 69 | * xMBUtilSetBits( ucBits, 4, 1, 1 ); 70 | * 71 | * // Set bit 7 to 1 and bit 8 to 0. 72 | * xMBUtilSetBits( ucBits, 7, 2, 0x01 ); 73 | * 74 | * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A; 75 | * xMBUtilSetBits( ucBits, 8, 8, 0x5A); 76 | * \endcode 77 | */ 78 | void xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, 79 | UCHAR ucNBits, UCHAR ucValues ); 80 | 81 | /*! \brief Function to read bits in a byte buffer. 82 | * 83 | * This function is used to extract up bit values from an array. Up to eight 84 | * bit values can be extracted in one step. 85 | * 86 | * \param ucByteBuf A buffer where the bit values are stored. 87 | * \param usBitOffset The starting address of the bits to set. The first 88 | * bit has the offset 0. 89 | * \param ucNBits Number of bits to modify. The value must always be smaller 90 | * than 8. 91 | * 92 | * \code 93 | * UCHAR ucBits[2] = {0, 0}; 94 | * UCHAR ucResult; 95 | * 96 | * // Extract the bits 3 - 10. 97 | * ucResult = xMBUtilGetBits( ucBits, 3, 8 ); 98 | * \endcode 99 | */ 100 | UCHAR xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, 101 | UCHAR ucNBits ); 102 | 103 | /*! @} */ 104 | 105 | #ifdef __cplusplus 106 | PR_END_EXTERN_C 107 | #endif 108 | #endif 109 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_PWR_H 24 | #define __STM32F10x_PWR_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup PWR 34 | * @{ 35 | */ 36 | 37 | /** @defgroup PWR_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup PWR_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** @defgroup PVD_detection_level 50 | * @{ 51 | */ 52 | 53 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 54 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 55 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 56 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 57 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 58 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 59 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 60 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 61 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 62 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 63 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 64 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup Regulator_state_is_STOP_mode 70 | * @{ 71 | */ 72 | 73 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 74 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 75 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 76 | ((REGULATOR) == PWR_Regulator_LowPower)) 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup STOP_mode_entry 82 | * @{ 83 | */ 84 | 85 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 86 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 87 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** @defgroup PWR_Flag 94 | * @{ 95 | */ 96 | 97 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 98 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 99 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 100 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 101 | ((FLAG) == PWR_FLAG_PVDO)) 102 | 103 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** @defgroup PWR_Exported_Macros 113 | * @{ 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** @defgroup PWR_Exported_Functions 121 | * @{ 122 | */ 123 | 124 | void PWR_DeInit(void); 125 | void PWR_BackupAccessCmd(FunctionalState NewState); 126 | void PWR_PVDCmd(FunctionalState NewState); 127 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 128 | void PWR_WakeUpPinCmd(FunctionalState NewState); 129 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 130 | void PWR_EnterSTANDBYMode(void); 131 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 132 | void PWR_ClearFlag(uint32_t PWR_FLAG); 133 | 134 | #endif /* __STM32F10x_PWR_H */ 135 | /** 136 | * @} 137 | */ 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /** 144 | * @} 145 | */ 146 | 147 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 148 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the DBGMCU firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_dbgmcu.h" 23 | 24 | /** @addtogroup StdPeriph_Driver 25 | * @{ 26 | */ 27 | 28 | /** @defgroup DBGMCU 29 | * @brief DBGMCU driver modules 30 | * @{ 31 | */ 32 | 33 | /** @defgroup DBGMCU_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @} 39 | */ 40 | 41 | /** @defgroup DBGMCU_Private_Defines 42 | * @{ 43 | */ 44 | 45 | #define IDCODE_DEVID_Mask ((uint32_t)0x00000FFF) 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup DBGMCU_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup DBGMCU_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup DBGMCU_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Returns the device revision identifier. 80 | * @param None 81 | * @retval : Device revision identifier 82 | */ 83 | uint32_t DBGMCU_GetREVID(void) 84 | { 85 | return(DBGMCU->IDCODE >> 16); 86 | } 87 | 88 | /** 89 | * @brief Returns the device identifier. 90 | * @param None 91 | * @retval : Device identifier 92 | */ 93 | uint32_t DBGMCU_GetDEVID(void) 94 | { 95 | return(DBGMCU->IDCODE & IDCODE_DEVID_Mask); 96 | } 97 | 98 | /** 99 | * @brief Configures the specified peripheral and low power mode behavior 100 | * when the MCU under Debug mode. 101 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 102 | * This parameter can be any combination of the following values: 103 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 104 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 105 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 106 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 107 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 108 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 109 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 112 | * @arg DBGMCU_CAN1_STOP: Debug CAN 1 stopped when Core is halted 113 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is 114 | * halted 115 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is 116 | * halted 117 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 119 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 120 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 121 | * @param NewState: new state of the specified peripheral in Debug mode. 122 | * This parameter can be: ENABLE or DISABLE. 123 | * @retval : None 124 | */ 125 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 126 | { 127 | /* Check the parameters */ 128 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 129 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 130 | if (NewState != DISABLE) 131 | { 132 | DBGMCU->CR |= DBGMCU_Periph; 133 | } 134 | else 135 | { 136 | DBGMCU->CR &= ~DBGMCU_Periph; 137 | } 138 | } 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 153 | -------------------------------------------------------------------------------- /modbus/functions/mbfuncdisc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Modbus Libary: A Modbus serial implementation for FreeRTOS 3 | * Copyright (C) 2006 Christian Walter 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | 21 | 22 | /* ----------------------- System includes ----------------------------------*/ 23 | #include "stdlib.h" 24 | #include "string.h" 25 | 26 | /* ----------------------- Platform includes --------------------------------*/ 27 | #include "port.h" 28 | 29 | /* ----------------------- Modbus includes ----------------------------------*/ 30 | #include "mb.h" 31 | #include "mbframe.h" 32 | #include "mbproto.h" 33 | #include "mbconfig.h" 34 | 35 | /* ----------------------- Defines ------------------------------------------*/ 36 | #define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF ) 37 | #define MB_PDU_FUNC_READ_DISCCNT_OFF ( MB_PDU_DATA_OFF + 2 ) 38 | #define MB_PDU_FUNC_READ_SIZE ( 4 ) 39 | #define MB_PDU_FUNC_READ_DISCCNT_MAX ( 0x07D0 ) 40 | 41 | /* ----------------------- Static functions ---------------------------------*/ 42 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode ); 43 | 44 | /* ----------------------- Start implementation -----------------------------*/ 45 | 46 | #if MB_FUNC_READ_COILS_ENABLED > 0 47 | 48 | eMBException 49 | eMBFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen ) 50 | { 51 | USHORT usRegAddress; 52 | USHORT usDiscreteCnt; 53 | UCHAR ucNBytes; 54 | UCHAR *pucFrameCur; 55 | 56 | eMBException eStatus = MB_EX_NONE; 57 | eMBErrorCode eRegStatus; 58 | 59 | if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) ) 60 | { 61 | usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 ); 62 | usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] ); 63 | usRegAddress++; 64 | 65 | usDiscreteCnt = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF] << 8 ); 66 | usDiscreteCnt |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_DISCCNT_OFF + 1] ); 67 | 68 | /* Check if the number of registers to read is valid. If not 69 | * return Modbus illegal data value exception. 70 | */ 71 | if( ( usDiscreteCnt >= 1 ) && 72 | ( usDiscreteCnt < MB_PDU_FUNC_READ_DISCCNT_MAX ) ) 73 | { 74 | /* Set the current PDU data pointer to the beginning. */ 75 | pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF]; 76 | *usLen = MB_PDU_FUNC_OFF; 77 | 78 | /* First byte contains the function code. */ 79 | *pucFrameCur++ = MB_FUNC_READ_DISCRETE_INPUTS; 80 | *usLen += 1; 81 | 82 | /* Test if the quantity of coils is a multiple of 8. If not last 83 | * byte is only partially field with unused coils set to zero. */ 84 | if( ( usDiscreteCnt & 0x0007 ) != 0 ) 85 | { 86 | ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 + 1 ); 87 | } 88 | else 89 | { 90 | ucNBytes = ( UCHAR ) ( usDiscreteCnt / 8 ); 91 | } 92 | *pucFrameCur++ = ucNBytes; 93 | *usLen += 1; 94 | 95 | eRegStatus = 96 | eMBRegDiscreteCB( pucFrameCur, usRegAddress, usDiscreteCnt ); 97 | 98 | /* If an error occured convert it into a Modbus exception. */ 99 | if( eRegStatus != MB_ENOERR ) 100 | { 101 | eStatus = prveMBError2Exception( eRegStatus ); 102 | } 103 | else 104 | { 105 | /* The response contains the function code, the starting address 106 | * and the quantity of registers. We reuse the old values in the 107 | * buffer because they are still valid. */ 108 | *usLen += ucNBytes;; 109 | } 110 | } 111 | else 112 | { 113 | eStatus = MB_EX_ILLEGAL_DATA_VALUE; 114 | } 115 | } 116 | else 117 | { 118 | /* Can't be a valid read coil register request because the length 119 | * is incorrect. */ 120 | eStatus = MB_EX_ILLEGAL_DATA_VALUE; 121 | } 122 | return eStatus; 123 | } 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /USER/stm32f10x_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/Template/stm32f10x_it.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and 9 | * peripherals interrupt service routine. 10 | ****************************************************************************** 11 | * @copy 12 | * 13 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 15 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 16 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 17 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 18 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 19 | * 20 | *

© COPYRIGHT 2009 STMicroelectronics

21 | */ 22 | 23 | /* Includes ------------------------------------------------------------------*/ 24 | #include "stm32f10x_it.h" 25 | 26 | /** @addtogroup Template_Project 27 | * @{ 28 | */ 29 | 30 | /* Private typedef -----------------------------------------------------------*/ 31 | /* Private define ------------------------------------------------------------*/ 32 | /* Private macro -------------------------------------------------------------*/ 33 | /* Private variables ---------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | /* Private functions ---------------------------------------------------------*/ 36 | 37 | /******************************************************************************/ 38 | /* Cortex-M3 Processor Exceptions Handlers */ 39 | /******************************************************************************/ 40 | 41 | /** 42 | * @brief This function handles NMI exception. 43 | * @param None 44 | * @retval : None 45 | */ 46 | void NMI_Handler(void) 47 | { 48 | } 49 | 50 | /** 51 | * @brief This function handles Hard Fault exception. 52 | * @param None 53 | * @retval : None 54 | */ 55 | void HardFault_Handler(void) 56 | { 57 | /* Go to infinite loop when Hard Fault exception occurs */ 58 | while (1) 59 | { 60 | } 61 | } 62 | 63 | /** 64 | * @brief This function handles Memory Manage exception. 65 | * @param None 66 | * @retval : None 67 | */ 68 | void MemManage_Handler(void) 69 | { 70 | /* Go to infinite loop when Memory Manage exception occurs */ 71 | while (1) 72 | { 73 | } 74 | } 75 | 76 | /** 77 | * @brief This function handles Bus Fault exception. 78 | * @param None 79 | * @retval : None 80 | */ 81 | void BusFault_Handler(void) 82 | { 83 | /* Go to infinite loop when Bus Fault exception occurs */ 84 | while (1) 85 | { 86 | } 87 | } 88 | 89 | /** 90 | * @brief This function handles Usage Fault exception. 91 | * @param None 92 | * @retval : None 93 | */ 94 | void UsageFault_Handler(void) 95 | { 96 | /* Go to infinite loop when Usage Fault exception occurs */ 97 | while (1) 98 | { 99 | } 100 | } 101 | 102 | /** 103 | * @brief This function handles SVCall exception. 104 | * @param None 105 | * @retval : None 106 | */ 107 | void SVC_Handler(void) 108 | { 109 | } 110 | 111 | /** 112 | * @brief This function handles Debug Monitor exception. 113 | * @param None 114 | * @retval : None 115 | */ 116 | void DebugMon_Handler(void) 117 | { 118 | } 119 | 120 | /** 121 | * @brief This function handles PendSVC exception. 122 | * @param None 123 | * @retval : None 124 | */ 125 | void PendSV_Handler(void) 126 | { 127 | } 128 | 129 | /** 130 | * @brief This function handles SysTick Handler. 131 | * @param None 132 | * @retval : None 133 | */ 134 | void SysTick_Handler(void) 135 | { 136 | } 137 | 138 | /******************************************************************************/ 139 | /* STM32F10x Peripherals Interrupt Handlers */ 140 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 141 | /* available peripheral interrupt handler's name please refer to the startup */ 142 | /* file (startup_stm32f10x_xx.s). */ 143 | /******************************************************************************/ 144 | 145 | void UART1_IRQ(void); 146 | void USART1_IRQHandler(void) 147 | { 148 | UART1_IRQ(); 149 | } 150 | 151 | extern void prvvTIMERExpiredISR( void ); 152 | void TIM2_IRQHandler(void) 153 | { 154 | prvvTIMERExpiredISR(); 155 | } 156 | /** 157 | * @brief This function handles PPP interrupt request. 158 | * @param None 159 | * @retval : None 160 | */ 161 | /*void PPP_IRQHandler(void) 162 | { 163 | }*/ 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | 170 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 171 | -------------------------------------------------------------------------------- /modbus/functions/mbfuncinput.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbfuncinput.c,v 1.10 2007/09/12 10:15:56 wolti Exp $ 29 | */ 30 | 31 | /* ----------------------- System includes ----------------------------------*/ 32 | #include "stdlib.h" 33 | #include "string.h" 34 | 35 | /* ----------------------- Platform includes --------------------------------*/ 36 | #include "port.h" 37 | 38 | /* ----------------------- Modbus includes ----------------------------------*/ 39 | #include "mb.h" 40 | #include "mbframe.h" 41 | #include "mbproto.h" 42 | #include "mbconfig.h" 43 | 44 | /* ----------------------- Defines ------------------------------------------*/ 45 | #define MB_PDU_FUNC_READ_ADDR_OFF ( MB_PDU_DATA_OFF ) 46 | #define MB_PDU_FUNC_READ_REGCNT_OFF ( MB_PDU_DATA_OFF + 2 ) 47 | #define MB_PDU_FUNC_READ_SIZE ( 4 ) 48 | #define MB_PDU_FUNC_READ_REGCNT_MAX ( 0x007D ) 49 | 50 | #define MB_PDU_FUNC_READ_RSP_BYTECNT_OFF ( MB_PDU_DATA_OFF ) 51 | 52 | /* ----------------------- Static functions ---------------------------------*/ 53 | eMBException prveMBError2Exception( eMBErrorCode eErrorCode ); 54 | 55 | /* ----------------------- Start implementation -----------------------------*/ 56 | #if MB_FUNC_READ_INPUT_ENABLED > 0 57 | 58 | eMBException 59 | eMBFuncReadInputRegister( UCHAR * pucFrame, USHORT * usLen ) 60 | { 61 | USHORT usRegAddress; 62 | USHORT usRegCount; 63 | UCHAR *pucFrameCur; 64 | 65 | eMBException eStatus = MB_EX_NONE; 66 | eMBErrorCode eRegStatus; 67 | 68 | if( *usLen == ( MB_PDU_FUNC_READ_SIZE + MB_PDU_SIZE_MIN ) ) 69 | { 70 | usRegAddress = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF] << 8 ); 71 | usRegAddress |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_ADDR_OFF + 1] ); 72 | usRegAddress++; 73 | 74 | usRegCount = ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF] << 8 ); 75 | usRegCount |= ( USHORT )( pucFrame[MB_PDU_FUNC_READ_REGCNT_OFF + 1] ); 76 | 77 | /* Check if the number of registers to read is valid. If not 78 | * return Modbus illegal data value exception. 79 | */ 80 | if( ( usRegCount >= 1 ) 81 | && ( usRegCount < MB_PDU_FUNC_READ_REGCNT_MAX ) ) 82 | { 83 | /* Set the current PDU data pointer to the beginning. */ 84 | pucFrameCur = &pucFrame[MB_PDU_FUNC_OFF]; 85 | *usLen = MB_PDU_FUNC_OFF; 86 | 87 | /* First byte contains the function code. */ 88 | *pucFrameCur++ = MB_FUNC_READ_INPUT_REGISTER; 89 | *usLen += 1; 90 | 91 | /* Second byte in the response contain the number of bytes. */ 92 | *pucFrameCur++ = ( UCHAR )( usRegCount * 2 ); 93 | *usLen += 1; 94 | 95 | eRegStatus = 96 | eMBRegInputCB( pucFrameCur, usRegAddress, usRegCount ); 97 | 98 | /* If an error occured convert it into a Modbus exception. */ 99 | if( eRegStatus != MB_ENOERR ) 100 | { 101 | eStatus = prveMBError2Exception( eRegStatus ); 102 | } 103 | else 104 | { 105 | *usLen += usRegCount * 2; 106 | } 107 | } 108 | else 109 | { 110 | eStatus = MB_EX_ILLEGAL_DATA_VALUE; 111 | } 112 | } 113 | else 114 | { 115 | /* Can't be a valid read input register request because the length 116 | * is incorrect. */ 117 | eStatus = MB_EX_ILLEGAL_DATA_VALUE; 118 | } 119 | return eStatus; 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /modbus/include/mbport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbport.h,v 1.19 2010/06/06 13:54:40 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_PORT_H 32 | #define _MB_PORT_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | 38 | /* ----------------------- Type definitions ---------------------------------*/ 39 | 40 | typedef enum 41 | { 42 | EV_READY, /*!< Startup finished. */ 43 | EV_FRAME_RECEIVED, /*!< Frame received. */ 44 | EV_EXECUTE, /*!< Execute function. */ 45 | EV_FRAME_SENT /*!< Frame sent. */ 46 | } eMBEventType; 47 | 48 | /*! \ingroup modbus 49 | * \brief Parity used for characters in serial mode. 50 | * 51 | * The parity which should be applied to the characters sent over the serial 52 | * link. Please note that this values are actually passed to the porting 53 | * layer and therefore not all parity modes might be available. 54 | */ 55 | typedef enum 56 | { 57 | MB_PAR_NONE, /*!< No parity. */ 58 | MB_PAR_ODD, /*!< Odd parity. */ 59 | MB_PAR_EVEN /*!< Even parity. */ 60 | } eMBParity; 61 | 62 | /* ----------------------- Supporting functions -----------------------------*/ 63 | BOOL xMBPortEventInit( void ); 64 | 65 | BOOL xMBPortEventPost( eMBEventType eEvent ); 66 | 67 | BOOL xMBPortEventGet( /*@out@ */ eMBEventType * eEvent ); 68 | 69 | /* ----------------------- Serial port functions ----------------------------*/ 70 | 71 | BOOL xMBPortSerialInit( UCHAR ucPort, ULONG ulBaudRate, 72 | UCHAR ucDataBits, eMBParity eParity ); 73 | 74 | void vMBPortClose( void ); 75 | 76 | void xMBPortSerialClose( void ); 77 | 78 | void vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable ); 79 | 80 | BOOL xMBPortSerialGetByte( CHAR * pucByte ); 81 | 82 | BOOL xMBPortSerialPutByte( CHAR ucByte ); 83 | 84 | /* ----------------------- Timers functions ---------------------------------*/ 85 | BOOL xMBPortTimersInit( USHORT usTimeOut50us ); 86 | 87 | void xMBPortTimersClose( void ); 88 | 89 | void vMBPortTimersEnable( void ); 90 | 91 | void vMBPortTimersDisable( void ); 92 | 93 | void vMBPortTimersDelay( USHORT usTimeOutMS ); 94 | 95 | /* ----------------------- Callback for the protocol stack ------------------*/ 96 | 97 | /*! 98 | * \brief Callback function for the porting layer when a new byte is 99 | * available. 100 | * 101 | * Depending upon the mode this callback function is used by the RTU or 102 | * ASCII transmission layers. In any case a call to xMBPortSerialGetByte() 103 | * must immediately return a new character. 104 | * 105 | * \return TRUE if a event was posted to the queue because 106 | * a new byte was received. The port implementation should wake up the 107 | * tasks which are currently blocked on the eventqueue. 108 | */ 109 | extern BOOL( *pxMBFrameCBByteReceived ) ( void ); 110 | 111 | extern BOOL( *pxMBFrameCBTransmitterEmpty ) ( void ); 112 | 113 | extern BOOL( *pxMBPortCBTimerExpired ) ( void ); 114 | 115 | /* ----------------------- TCP port functions -------------------------------*/ 116 | BOOL xMBTCPPortInit( USHORT usTCPPort ); 117 | 118 | void vMBTCPPortClose( void ); 119 | 120 | void vMBTCPPortDisable( void ); 121 | 122 | BOOL xMBTCPPortGetRequest( UCHAR **ppucMBTCPFrame, USHORT * usTCPLength ); 123 | 124 | BOOL xMBTCPPortSendResponse( const UCHAR *pucMBTCPFrame, USHORT usTCPLength ); 125 | 126 | #ifdef __cplusplus 127 | PR_END_EXTERN_C 128 | #endif 129 | #endif 130 | -------------------------------------------------------------------------------- /FWlib/inc/misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the 8 | * miscellaneous firmware library functions. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MISC_H 24 | #define __MISC_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup MISC 34 | * @{ 35 | */ 36 | 37 | /** @defgroup MISC_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief NVIC Init Structure definition 43 | */ 44 | 45 | typedef struct 46 | { 47 | uint8_t NVIC_IRQChannel; 48 | uint8_t NVIC_IRQChannelPreemptionPriority; 49 | uint8_t NVIC_IRQChannelSubPriority; 50 | FunctionalState NVIC_IRQChannelCmd; 51 | } NVIC_InitTypeDef; 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @defgroup MISC_Exported_Constants 58 | * @{ 59 | */ 60 | 61 | /** @defgroup Vector_Table_Base 62 | * @{ 63 | */ 64 | 65 | #define NVIC_VectTab_RAM ((uint32_t)0x20000000) 66 | #define NVIC_VectTab_FLASH ((uint32_t)0x08000000) 67 | #define IS_NVIC_VECTTAB(VECTTAB) (((VECTTAB) == NVIC_VectTab_RAM) || \ 68 | ((VECTTAB) == NVIC_VectTab_FLASH)) 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup System_Low_Power 74 | * @{ 75 | */ 76 | 77 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 78 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 79 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 80 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 81 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 82 | ((LP) == NVIC_LP_SLEEPONEXIT)) 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @defgroup Preemption_Priority_Group 88 | * @{ 89 | */ 90 | 91 | #define NVIC_PriorityGroup_0 ((uint32_t)0x700) /* 0 bits for pre-emption priority 92 | 4 bits for subpriority */ 93 | #define NVIC_PriorityGroup_1 ((uint32_t)0x600) /* 1 bits for pre-emption priority 94 | 3 bits for subpriority */ 95 | #define NVIC_PriorityGroup_2 ((uint32_t)0x500) /* 2 bits for pre-emption priority 96 | 2 bits for subpriority */ 97 | #define NVIC_PriorityGroup_3 ((uint32_t)0x400) /* 3 bits for pre-emption priority 98 | 1 bits for subpriority */ 99 | #define NVIC_PriorityGroup_4 ((uint32_t)0x300) /* 4 bits for pre-emption priority 100 | 0 bits for subpriority */ 101 | 102 | #define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) || \ 103 | ((GROUP) == NVIC_PriorityGroup_1) || \ 104 | ((GROUP) == NVIC_PriorityGroup_2) || \ 105 | ((GROUP) == NVIC_PriorityGroup_3) || \ 106 | ((GROUP) == NVIC_PriorityGroup_4)) 107 | 108 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 109 | 110 | #define IS_NVIC_SUB_PRIORITY(PRIORITY) ((PRIORITY) < 0x10) 111 | 112 | #define IS_NVIC_OFFSET(OFFSET) ((OFFSET) < 0x0007FFFF) 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup SysTick_clock_source 119 | * @{ 120 | */ 121 | 122 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 123 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 124 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 125 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 126 | /** 127 | * @} 128 | */ 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /** @defgroup MISC_Exported_Macros 135 | * @{ 136 | */ 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** @defgroup MISC_Exported_Functions 143 | * @{ 144 | */ 145 | 146 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); 147 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 148 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset); 149 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 150 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 151 | 152 | #endif /* __MISC_H */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 167 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_iwdg.h" 23 | 24 | /** @addtogroup StdPeriph_Driver 25 | * @{ 26 | */ 27 | 28 | /** @defgroup IWDG 29 | * @brief IWDG driver modules 30 | * @{ 31 | */ 32 | 33 | /** @defgroup IWDG_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @} 39 | */ 40 | 41 | /** @defgroup IWDG_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /* ---------------------- IWDG registers bit mask ----------------------------*/ 46 | 47 | /* KR register bit mask */ 48 | #define KR_KEY_Reload ((uint16_t)0xAAAA) 49 | #define KR_KEY_Enable ((uint16_t)0xCCCC) 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /** @defgroup IWDG_Private_Macros 56 | * @{ 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup IWDG_Private_Variables 64 | * @{ 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup IWDG_Private_FunctionPrototypes 72 | * @{ 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup IWDG_Private_Functions 80 | * @{ 81 | */ 82 | 83 | /** 84 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR 85 | * registers. 86 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and 87 | * IWDG_RLR registers. 88 | * This parameter can be one of the following values: 89 | * @arg IWDG_WriteAccess_Enable: Enable write access to 90 | * IWDG_PR and IWDG_RLR registers 91 | * @arg IWDG_WriteAccess_Disable: Disable write access to 92 | * IWDG_PR and IWDG_RLR registers 93 | * @retval : None 94 | */ 95 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 96 | { 97 | /* Check the parameters */ 98 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 99 | IWDG->KR = IWDG_WriteAccess; 100 | } 101 | 102 | /** 103 | * @brief Sets IWDG Prescaler value. 104 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 105 | * This parameter can be one of the following values: 106 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 107 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 108 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 109 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 110 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 111 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 112 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 113 | * @retval : None 114 | */ 115 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 116 | { 117 | /* Check the parameters */ 118 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 119 | IWDG->PR = IWDG_Prescaler; 120 | } 121 | 122 | /** 123 | * @brief Sets IWDG Reload value. 124 | * @param Reload: specifies the IWDG Reload value. 125 | * This parameter must be a number between 0 and 0x0FFF. 126 | * @retval : None 127 | */ 128 | void IWDG_SetReload(uint16_t Reload) 129 | { 130 | /* Check the parameters */ 131 | assert_param(IS_IWDG_RELOAD(Reload)); 132 | IWDG->RLR = Reload; 133 | } 134 | 135 | /** 136 | * @brief Reloads IWDG counter with value defined in the reload register 137 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 138 | * @param None 139 | * @retval : None 140 | */ 141 | void IWDG_ReloadCounter(void) 142 | { 143 | IWDG->KR = KR_KEY_Reload; 144 | } 145 | 146 | /** 147 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers 148 | * disabled). 149 | * @param None 150 | * @retval : None 151 | */ 152 | void IWDG_Enable(void) 153 | { 154 | IWDG->KR = KR_KEY_Enable; 155 | } 156 | 157 | /** 158 | * @brief Checks whether the specified IWDG flag is set or not. 159 | * @param IWDG_FLAG: specifies the flag to check. 160 | * This parameter can be one of the following values: 161 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 162 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 163 | * @retval : The new state of IWDG_FLAG (SET or RESET). 164 | */ 165 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 166 | { 167 | FlagStatus bitstatus = RESET; 168 | /* Check the parameters */ 169 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 170 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 171 | { 172 | bitstatus = SET; 173 | } 174 | else 175 | { 176 | bitstatus = RESET; 177 | } 178 | /* Return the flag status */ 179 | return bitstatus; 180 | } 181 | 182 | /** 183 | * @} 184 | */ 185 | 186 | /** 187 | * @} 188 | */ 189 | 190 | /** 191 | * @} 192 | */ 193 | 194 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 195 | -------------------------------------------------------------------------------- /modbus/functions/mbutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbutils.c,v 1.6 2007/02/18 23:49:07 wolti Exp $ 29 | */ 30 | 31 | /* ----------------------- System includes ----------------------------------*/ 32 | #include "stdlib.h" 33 | #include "string.h" 34 | 35 | /* ----------------------- Platform includes --------------------------------*/ 36 | #include "port.h" 37 | 38 | /* ----------------------- Modbus includes ----------------------------------*/ 39 | #include "mb.h" 40 | #include "mbproto.h" 41 | 42 | /* ----------------------- Defines ------------------------------------------*/ 43 | #define BITS_UCHAR 8U 44 | 45 | /* ----------------------- Start implementation -----------------------------*/ 46 | void 47 | xMBUtilSetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits, 48 | UCHAR ucValue ) 49 | { 50 | USHORT usWordBuf; 51 | USHORT usMask; 52 | USHORT usByteOffset; 53 | USHORT usNPreBits; 54 | USHORT usValue = ucValue; 55 | 56 | assert( ucNBits <= 8 ); 57 | assert( ( size_t )BITS_UCHAR == sizeof( UCHAR ) * 8 ); 58 | 59 | /* Calculate byte offset for first byte containing the bit values starting 60 | * at usBitOffset. */ 61 | usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR ); 62 | 63 | /* How many bits precede our bits to set. */ 64 | usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR ); 65 | 66 | /* Move bit field into position over bits to set */ 67 | usValue <<= usNPreBits; 68 | 69 | /* Prepare a mask for setting the new bits. */ 70 | usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 ); 71 | usMask <<= usBitOffset - usByteOffset * BITS_UCHAR; 72 | 73 | /* copy bits into temporary storage. */ 74 | usWordBuf = ucByteBuf[usByteOffset]; 75 | usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR; 76 | 77 | /* Zero out bit field bits and then or value bits into them. */ 78 | usWordBuf = ( USHORT )( ( usWordBuf & ( ~usMask ) ) | usValue ); 79 | 80 | /* move bits back into storage */ 81 | ucByteBuf[usByteOffset] = ( UCHAR )( usWordBuf & 0xFF ); 82 | ucByteBuf[usByteOffset + 1] = ( UCHAR )( usWordBuf >> BITS_UCHAR ); 83 | } 84 | 85 | UCHAR 86 | xMBUtilGetBits( UCHAR * ucByteBuf, USHORT usBitOffset, UCHAR ucNBits ) 87 | { 88 | USHORT usWordBuf; 89 | USHORT usMask; 90 | USHORT usByteOffset; 91 | USHORT usNPreBits; 92 | 93 | /* Calculate byte offset for first byte containing the bit values starting 94 | * at usBitOffset. */ 95 | usByteOffset = ( USHORT )( ( usBitOffset ) / BITS_UCHAR ); 96 | 97 | /* How many bits precede our bits to set. */ 98 | usNPreBits = ( USHORT )( usBitOffset - usByteOffset * BITS_UCHAR ); 99 | 100 | /* Prepare a mask for setting the new bits. */ 101 | usMask = ( USHORT )( ( 1 << ( USHORT ) ucNBits ) - 1 ); 102 | 103 | /* copy bits into temporary storage. */ 104 | usWordBuf = ucByteBuf[usByteOffset]; 105 | usWordBuf |= ucByteBuf[usByteOffset + 1] << BITS_UCHAR; 106 | 107 | /* throw away unneeded bits. */ 108 | usWordBuf >>= usNPreBits; 109 | 110 | /* mask away bits above the requested bitfield. */ 111 | usWordBuf &= usMask; 112 | 113 | return ( UCHAR ) usWordBuf; 114 | } 115 | 116 | eMBException 117 | prveMBError2Exception( eMBErrorCode eErrorCode ) 118 | { 119 | eMBException eStatus; 120 | 121 | switch ( eErrorCode ) 122 | { 123 | case MB_ENOERR: 124 | eStatus = MB_EX_NONE; 125 | break; 126 | 127 | case MB_ENOREG: 128 | eStatus = MB_EX_ILLEGAL_DATA_ADDRESS; 129 | break; 130 | 131 | case MB_ETIMEDOUT: 132 | eStatus = MB_EX_SLAVE_BUSY; 133 | break; 134 | 135 | default: 136 | eStatus = MB_EX_SLAVE_DEVICE_FAILURE; 137 | break; 138 | } 139 | 140 | return eStatus; 141 | } 142 | -------------------------------------------------------------------------------- /modbus/rtu/mbcrc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbcrc.c,v 1.7 2007/02/18 23:50:27 wolti Exp $ 29 | */ 30 | 31 | /* ----------------------- Platform includes --------------------------------*/ 32 | #include "port.h" 33 | 34 | static const UCHAR aucCRCHi[] = { 35 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 36 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 37 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 38 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 39 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 40 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 41 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 42 | 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 43 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 44 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 45 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 46 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 47 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 48 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 49 | 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 50 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 51 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 52 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 53 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 54 | 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 55 | 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 56 | 0x00, 0xC1, 0x81, 0x40 57 | }; 58 | 59 | static const UCHAR aucCRCLo[] = { 60 | 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 61 | 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 62 | 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 63 | 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 64 | 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 65 | 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 66 | 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 67 | 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 68 | 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 69 | 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 70 | 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 71 | 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 72 | 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 73 | 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 74 | 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 75 | 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 76 | 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 77 | 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 78 | 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 79 | 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 80 | 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 81 | 0x41, 0x81, 0x80, 0x40 82 | }; 83 | 84 | USHORT 85 | usMBCRC16( UCHAR * pucFrame, USHORT usLen ) 86 | { 87 | UCHAR ucCRCHi = 0xFF; 88 | UCHAR ucCRCLo = 0xFF; 89 | int iIndex; 90 | 91 | while( usLen-- ) 92 | { 93 | iIndex = ucCRCLo ^ *( pucFrame++ ); 94 | ucCRCLo = ( UCHAR )( ucCRCHi ^ aucCRCHi[iIndex] ); 95 | ucCRCHi = aucCRCLo[iIndex]; 96 | } 97 | return ( USHORT )( ucCRCHi << 8 | ucCRCLo ); 98 | } 99 | -------------------------------------------------------------------------------- /modbus/include/mbconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbconfig.h,v 1.15 2010/06/06 13:54:40 wolti Exp $ 29 | */ 30 | 31 | #ifndef _MB_CONFIG_H 32 | #define _MB_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | PR_BEGIN_EXTERN_C 36 | #endif 37 | /* ----------------------- Defines ------------------------------------------*/ 38 | /*! \defgroup modbus_cfg Modbus Configuration 39 | * 40 | * Most modules in the protocol stack are completly optional and can be 41 | * excluded. This is specially important if target resources are very small 42 | * and program memory space should be saved.
43 | * 44 | * All of these settings are available in the file mbconfig.h 45 | */ 46 | /*! \addtogroup modbus_cfg 47 | * @{ 48 | */ 49 | /*! \brief If Modbus ASCII support is enabled. */ 50 | #define MB_ASCII_ENABLED ( 1 ) 51 | 52 | /*! \brief If Modbus RTU support is enabled. */ 53 | #define MB_RTU_ENABLED ( 1 ) 54 | 55 | /*! \brief If Modbus TCP support is enabled. */ 56 | #define MB_TCP_ENABLED ( 0 ) 57 | 58 | /*! \brief The character timeout value for Modbus ASCII. 59 | * 60 | * The character timeout value is not fixed for Modbus ASCII and is therefore 61 | * a configuration option. It should be set to the maximum expected delay 62 | * time of the network. 63 | */ 64 | #define MB_ASCII_TIMEOUT_SEC ( 1 ) 65 | 66 | /*! \brief Timeout to wait in ASCII prior to enabling transmitter. 67 | * 68 | * If defined the function calls vMBPortSerialDelay with the argument 69 | * MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS to allow for a delay before 70 | * the serial transmitter is enabled. This is required because some 71 | * targets are so fast that there is no time between receiving and 72 | * transmitting the frame. If the master is to slow with enabling its 73 | * receiver then he will not receive the response correctly. 74 | */ 75 | #ifndef MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS 76 | #define MB_ASCII_TIMEOUT_WAIT_BEFORE_SEND_MS ( 0 ) 77 | #endif 78 | 79 | /*! \brief Maximum number of Modbus functions codes the protocol stack 80 | * should support. 81 | * 82 | * The maximum number of supported Modbus functions must be greater than 83 | * the sum of all enabled functions in this file and custom function 84 | * handlers. If set to small adding more functions will fail. 85 | */ 86 | #define MB_FUNC_HANDLERS_MAX ( 16 ) 87 | 88 | /*! \brief Number of bytes which should be allocated for the Report Slave ID 89 | * command. 90 | * 91 | * This number limits the maximum size of the additional segment in the 92 | * report slave id function. See eMBSetSlaveID( ) for more information on 93 | * how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED 94 | * is set to 1. 95 | */ 96 | #define MB_FUNC_OTHER_REP_SLAVEID_BUF ( 32 ) 97 | 98 | /*! \brief If the Report Slave ID function should be enabled. */ 99 | #define MB_FUNC_OTHER_REP_SLAVEID_ENABLED ( 1 ) 100 | 101 | /*! \brief If the Read Input Registers function should be enabled. */ 102 | #define MB_FUNC_READ_INPUT_ENABLED ( 1 ) 103 | 104 | /*! \brief If the Read Holding Registers function should be enabled. */ 105 | #define MB_FUNC_READ_HOLDING_ENABLED ( 1 ) 106 | 107 | /*! \brief If the Write Single Register function should be enabled. */ 108 | #define MB_FUNC_WRITE_HOLDING_ENABLED ( 1 ) 109 | 110 | /*! \brief If the Write Multiple registers function should be enabled. */ 111 | #define MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED ( 1 ) 112 | 113 | /*! \brief If the Read Coils function should be enabled. */ 114 | #define MB_FUNC_READ_COILS_ENABLED ( 1 ) 115 | 116 | /*! \brief If the Write Coils function should be enabled. */ 117 | #define MB_FUNC_WRITE_COIL_ENABLED ( 1 ) 118 | 119 | /*! \brief If the Write Multiple Coils function should be enabled. */ 120 | #define MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED ( 1 ) 121 | 122 | /*! \brief If the Read Discrete Inputs function should be enabled. */ 123 | #define MB_FUNC_READ_DISCRETE_INPUTS_ENABLED ( 1 ) 124 | 125 | /*! \brief If the Read/Write Multiple Registers function should be enabled. */ 126 | #define MB_FUNC_READWRITE_HOLDING_ENABLED ( 1 ) 127 | 128 | /*! @} */ 129 | #ifdef __cplusplus 130 | PR_END_EXTERN_C 131 | #endif 132 | #endif 133 | -------------------------------------------------------------------------------- /modbus/tcp/mbtcp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU. 3 | * Copyright (c) 2006 Christian Walter 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * File: $Id: mbtcp.c,v 1.3 2006/12/07 22:10:34 wolti Exp $ 29 | */ 30 | 31 | /* ----------------------- System includes ----------------------------------*/ 32 | #include "stdlib.h" 33 | #include "string.h" 34 | 35 | /* ----------------------- Platform includes --------------------------------*/ 36 | #include "port.h" 37 | 38 | /* ----------------------- Modbus includes ----------------------------------*/ 39 | #include "mb.h" 40 | #include "mbconfig.h" 41 | #include "mbtcp.h" 42 | #include "mbframe.h" 43 | #include "mbport.h" 44 | 45 | #if MB_TCP_ENABLED > 0 46 | 47 | /* ----------------------- Defines ------------------------------------------*/ 48 | 49 | /* ----------------------- MBAP Header --------------------------------------*/ 50 | /* 51 | * 52 | * <------------------------ MODBUS TCP/IP ADU(1) -------------------------> 53 | * <----------- MODBUS PDU (1') ----------------> 54 | * +-----------+---------------+------------------------------------------+ 55 | * | TID | PID | Length | UID |Code | Data | 56 | * +-----------+---------------+------------------------------------------+ 57 | * | | | | | 58 | * (2) (3) (4) (5) (6) 59 | * 60 | * (2) ... MB_TCP_TID = 0 (Transaction Identifier - 2 Byte) 61 | * (3) ... MB_TCP_PID = 2 (Protocol Identifier - 2 Byte) 62 | * (4) ... MB_TCP_LEN = 4 (Number of bytes - 2 Byte) 63 | * (5) ... MB_TCP_UID = 6 (Unit Identifier - 1 Byte) 64 | * (6) ... MB_TCP_FUNC = 7 (Modbus Function Code) 65 | * 66 | * (1) ... Modbus TCP/IP Application Data Unit 67 | * (1') ... Modbus Protocol Data Unit 68 | */ 69 | 70 | #define MB_TCP_TID 0 71 | #define MB_TCP_PID 2 72 | #define MB_TCP_LEN 4 73 | #define MB_TCP_UID 6 74 | #define MB_TCP_FUNC 7 75 | 76 | #define MB_TCP_PROTOCOL_ID 0 /* 0 = Modbus Protocol */ 77 | 78 | 79 | /* ----------------------- Start implementation -----------------------------*/ 80 | eMBErrorCode 81 | eMBTCPDoInit( USHORT ucTCPPort ) 82 | { 83 | eMBErrorCode eStatus = MB_ENOERR; 84 | 85 | if( xMBTCPPortInit( ucTCPPort ) == FALSE ) 86 | { 87 | eStatus = MB_EPORTERR; 88 | } 89 | return eStatus; 90 | } 91 | 92 | void 93 | eMBTCPStart( void ) 94 | { 95 | } 96 | 97 | void 98 | eMBTCPStop( void ) 99 | { 100 | /* Make sure that no more clients are connected. */ 101 | vMBTCPPortDisable( ); 102 | } 103 | 104 | eMBErrorCode 105 | eMBTCPReceive( UCHAR * pucRcvAddress, UCHAR ** ppucFrame, USHORT * pusLength ) 106 | { 107 | eMBErrorCode eStatus = MB_EIO; 108 | UCHAR *pucMBTCPFrame; 109 | USHORT usLength; 110 | USHORT usPID; 111 | 112 | if( xMBTCPPortGetRequest( &pucMBTCPFrame, &usLength ) != FALSE ) 113 | { 114 | usPID = pucMBTCPFrame[MB_TCP_PID] << 8U; 115 | usPID |= pucMBTCPFrame[MB_TCP_PID + 1]; 116 | 117 | if( usPID == MB_TCP_PROTOCOL_ID ) 118 | { 119 | *ppucFrame = &pucMBTCPFrame[MB_TCP_FUNC]; 120 | *pusLength = usLength - MB_TCP_FUNC; 121 | eStatus = MB_ENOERR; 122 | 123 | /* Modbus TCP does not use any addresses. Fake the source address such 124 | * that the processing part deals with this frame. 125 | */ 126 | *pucRcvAddress = MB_TCP_PSEUDO_ADDRESS; 127 | } 128 | } 129 | else 130 | { 131 | eStatus = MB_EIO; 132 | } 133 | return eStatus; 134 | } 135 | 136 | eMBErrorCode 137 | eMBTCPSend( UCHAR _unused, const UCHAR * pucFrame, USHORT usLength ) 138 | { 139 | eMBErrorCode eStatus = MB_ENOERR; 140 | UCHAR *pucMBTCPFrame = ( UCHAR * ) pucFrame - MB_TCP_FUNC; 141 | USHORT usTCPLength = usLength + MB_TCP_FUNC; 142 | 143 | /* The MBAP header is already initialized because the caller calls this 144 | * function with the buffer returned by the previous call. Therefore we 145 | * only have to update the length in the header. Note that the length 146 | * header includes the size of the Modbus PDU and the UID Byte. Therefore 147 | * the length is usLength plus one. 148 | */ 149 | pucMBTCPFrame[MB_TCP_LEN] = ( usLength + 1 ) >> 8U; 150 | pucMBTCPFrame[MB_TCP_LEN + 1] = ( usLength + 1 ) & 0xFF; 151 | if( xMBTCPPortSendResponse( pucMBTCPFrame, usTCPLength ) == FALSE ) 152 | { 153 | eStatus = MB_EIO; 154 | } 155 | return eStatus; 156 | } 157 | 158 | #endif 159 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the EXTI 8 | * firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_EXTI_H 24 | #define __STM32F10x_EXTI_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup EXTI 34 | * @{ 35 | */ 36 | 37 | /** @defgroup EXTI_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief EXTI mode enumeration 43 | */ 44 | 45 | typedef enum 46 | { 47 | EXTI_Mode_Interrupt = 0x00, 48 | EXTI_Mode_Event = 0x04 49 | }EXTIMode_TypeDef; 50 | 51 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 52 | 53 | /** 54 | * @brief EXTI Trigger enumeration 55 | */ 56 | 57 | typedef enum 58 | { 59 | EXTI_Trigger_Rising = 0x08, 60 | EXTI_Trigger_Falling = 0x0C, 61 | EXTI_Trigger_Rising_Falling = 0x10 62 | }EXTITrigger_TypeDef; 63 | 64 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 65 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 66 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 67 | /** 68 | * @brief EXTI Init Structure definition 69 | */ 70 | 71 | typedef struct 72 | { 73 | uint32_t EXTI_Line; 74 | EXTIMode_TypeDef EXTI_Mode; 75 | EXTITrigger_TypeDef EXTI_Trigger; 76 | FunctionalState EXTI_LineCmd; 77 | }EXTI_InitTypeDef; 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup EXTI_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** @defgroup EXTI_Lines 88 | * @{ 89 | */ 90 | 91 | #define EXTI_Line0 ((uint32_t)0x00001) /* External interrupt line 0 */ 92 | #define EXTI_Line1 ((uint32_t)0x00002) /* External interrupt line 1 */ 93 | #define EXTI_Line2 ((uint32_t)0x00004) /* External interrupt line 2 */ 94 | #define EXTI_Line3 ((uint32_t)0x00008) /* External interrupt line 3 */ 95 | #define EXTI_Line4 ((uint32_t)0x00010) /* External interrupt line 4 */ 96 | #define EXTI_Line5 ((uint32_t)0x00020) /* External interrupt line 5 */ 97 | #define EXTI_Line6 ((uint32_t)0x00040) /* External interrupt line 6 */ 98 | #define EXTI_Line7 ((uint32_t)0x00080) /* External interrupt line 7 */ 99 | #define EXTI_Line8 ((uint32_t)0x00100) /* External interrupt line 8 */ 100 | #define EXTI_Line9 ((uint32_t)0x00200) /* External interrupt line 9 */ 101 | #define EXTI_Line10 ((uint32_t)0x00400) /* External interrupt line 10 */ 102 | #define EXTI_Line11 ((uint32_t)0x00800) /* External interrupt line 11 */ 103 | #define EXTI_Line12 ((uint32_t)0x01000) /* External interrupt line 12 */ 104 | #define EXTI_Line13 ((uint32_t)0x02000) /* External interrupt line 13 */ 105 | #define EXTI_Line14 ((uint32_t)0x04000) /* External interrupt line 14 */ 106 | #define EXTI_Line15 ((uint32_t)0x08000) /* External interrupt line 15 */ 107 | #define EXTI_Line16 ((uint32_t)0x10000) /* External interrupt line 16 108 | Connected to the PVD Output */ 109 | #define EXTI_Line17 ((uint32_t)0x20000) /* External interrupt line 17 110 | Connected to the RTC Alarm event */ 111 | #define EXTI_Line18 ((uint32_t)0x40000) /* External interrupt line 18 112 | Connected to the USB Wakeup from 113 | suspend event */ 114 | 115 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF80000) == 0x00) && ((LINE) != (uint16_t)0x00)) 116 | 117 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 118 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 119 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 120 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 121 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 122 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 123 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 124 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 125 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 126 | ((LINE) == EXTI_Line18)) 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** @defgroup EXTI_Exported_Macros 137 | * @{ 138 | */ 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | /** @defgroup EXTI_Exported_Functions 145 | * @{ 146 | */ 147 | 148 | void EXTI_DeInit(void); 149 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 150 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 151 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 152 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 153 | void EXTI_ClearFlag(uint32_t EXTI_Line); 154 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 155 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 156 | 157 | #endif /* __STM32F10x_EXTI_H */ 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /** 167 | * @} 168 | */ 169 | 170 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 171 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_wwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the WWDG firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_wwdg.h" 23 | #include "stm32f10x_rcc.h" 24 | 25 | /** @addtogroup StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup WWDG 30 | * @brief WWDG driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup WWDG_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup WWDG_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /* ----------- WWDG registers bit address in the alias region ----------- */ 47 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE) 48 | 49 | /* Alias word address of EWI bit */ 50 | #define CFR_OFFSET (WWDG_OFFSET + 0x04) 51 | #define EWI_BitNumber 0x09 52 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4)) 53 | 54 | /* --------------------- WWDG registers bit mask ------------------------ */ 55 | 56 | /* CR register bit mask */ 57 | #define CR_WDGA_Set ((uint32_t)0x00000080) 58 | 59 | /* CFR register bit mask */ 60 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F) 61 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80) 62 | #define BIT_Mask ((uint8_t)0x7F) 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup WWDG_Private_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup WWDG_Private_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Private_FunctionPrototypes 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup WWDG_Private_Functions 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @brief Deinitializes the WWDG peripheral registers to their default 98 | * reset values. 99 | * @param None 100 | * @retval : None 101 | */ 102 | void WWDG_DeInit(void) 103 | { 104 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 105 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 106 | } 107 | 108 | /** 109 | * @brief Sets the WWDG Prescaler. 110 | * @param WWDG_Prescaler: specifies the WWDG Prescaler. 111 | * This parameter can be one of the following values: 112 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 113 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 114 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 115 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 116 | * @retval : None 117 | */ 118 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 119 | { 120 | uint32_t tmpreg = 0; 121 | /* Check the parameters */ 122 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 123 | /* Clear WDGTB[1:0] bits */ 124 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask; 125 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 126 | tmpreg |= WWDG_Prescaler; 127 | /* Store the new value */ 128 | WWDG->CFR = tmpreg; 129 | } 130 | 131 | /** 132 | * @brief Sets the WWDG window value. 133 | * @param WindowValue: specifies the window value to be compared to 134 | * the downcounter. 135 | * This parameter value must be lower than 0x80. 136 | * @retval : None 137 | */ 138 | void WWDG_SetWindowValue(uint8_t WindowValue) 139 | { 140 | uint32_t tmpreg = 0; 141 | /* Check the parameters */ 142 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 143 | /* Clear W[6:0] bits */ 144 | tmpreg = WWDG->CFR & CFR_W_Mask; 145 | /* Set W[6:0] bits according to WindowValue value */ 146 | tmpreg |= WindowValue & BIT_Mask; 147 | /* Store the new value */ 148 | WWDG->CFR = tmpreg; 149 | } 150 | 151 | /** 152 | * @brief Enables the WWDG Early Wakeup interrupt(EWI). 153 | * @param None 154 | * @retval : None 155 | */ 156 | void WWDG_EnableIT(void) 157 | { 158 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE; 159 | } 160 | 161 | /** 162 | * @brief Sets the WWDG counter value. 163 | * @param Counter: specifies the watchdog counter value. 164 | * This parameter must be a number between 0x40 and 0x7F. 165 | * @retval : None 166 | */ 167 | void WWDG_SetCounter(uint8_t Counter) 168 | { 169 | /* Check the parameters */ 170 | assert_param(IS_WWDG_COUNTER(Counter)); 171 | /* Write to T[6:0] bits to configure the counter value, no need to do 172 | a read-modify-write; writing a 0 to WDGA bit does nothing */ 173 | WWDG->CR = Counter & BIT_Mask; 174 | } 175 | 176 | /** 177 | * @brief Enables WWDG and load the counter value. 178 | * @param Counter: specifies the watchdog counter value. 179 | * This parameter must be a number between 0x40 and 0x7F. 180 | * @retval : None 181 | */ 182 | void WWDG_Enable(uint8_t Counter) 183 | { 184 | /* Check the parameters */ 185 | assert_param(IS_WWDG_COUNTER(Counter)); 186 | WWDG->CR = CR_WDGA_Set | Counter; 187 | } 188 | 189 | /** 190 | * @brief Checks whether the Early Wakeup interrupt flag is set or not. 191 | * @param None 192 | * @retval : The new state of the Early Wakeup interrupt flag (SET or RESET) 193 | */ 194 | FlagStatus WWDG_GetFlagStatus(void) 195 | { 196 | return (FlagStatus)(WWDG->SR); 197 | } 198 | 199 | /** 200 | * @brief Clears Early Wakeup interrupt flag. 201 | * @param None 202 | * @retval : None 203 | */ 204 | void WWDG_ClearFlag(void) 205 | { 206 | WWDG->SR = (uint32_t)RESET; 207 | } 208 | 209 | /** 210 | * @} 211 | */ 212 | 213 | /** 214 | * @} 215 | */ 216 | 217 | /** 218 | * @} 219 | */ 220 | 221 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 222 | -------------------------------------------------------------------------------- /FWlib/src/misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file misc.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the miscellaneous firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "misc.h" 23 | 24 | /** @addtogroup StdPeriph_Driver 25 | * @{ 26 | */ 27 | 28 | /** @defgroup MISC 29 | * @brief MISC driver modules 30 | * @{ 31 | */ 32 | 33 | /** @defgroup MISC_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | 37 | /** 38 | * @} 39 | */ 40 | 41 | /** @defgroup MISC_Private_Defines 42 | * @{ 43 | */ 44 | 45 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup MISC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup MISC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup MISC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup MISC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Configures the priority grouping: pre-emption priority and 80 | * subpriority. 81 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 82 | * This parameter can be one of the following values: 83 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 84 | * 4 bits for subpriority 85 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 86 | * 3 bits for subpriority 87 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 88 | * 2 bits for subpriority 89 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 90 | * 1 bits for subpriority 91 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 92 | * 0 bits for subpriority 93 | * @retval : None 94 | */ 95 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 96 | { 97 | /* Check the parameters */ 98 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 99 | 100 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 101 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 102 | } 103 | 104 | /** 105 | * @brief Initializes the NVIC peripheral according to the specified 106 | * parameters in the NVIC_InitStruct. 107 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure 108 | * that contains the configuration information for the 109 | * specified NVIC peripheral. 110 | * @retval : None 111 | */ 112 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 113 | { 114 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 115 | 116 | /* Check the parameters */ 117 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 118 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 119 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 120 | 121 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 122 | { 123 | /* Compute the Corresponding IRQ Priority --------------------------------*/ 124 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 125 | tmppre = (0x4 - tmppriority); 126 | tmpsub = tmpsub >> tmppriority; 127 | 128 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 129 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 130 | tmppriority = tmppriority << 0x04; 131 | 132 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 133 | 134 | /* Enable the Selected IRQ Channels --------------------------------------*/ 135 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 136 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 137 | } 138 | else 139 | { 140 | /* Disable the Selected IRQ Channels -------------------------------------*/ 141 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 142 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 143 | } 144 | } 145 | 146 | /** 147 | * @brief Sets the vector table location and Offset. 148 | * @param NVIC_VectTab: specifies if the vector table is in RAM or 149 | * FLASH memory. 150 | * This parameter can be one of the following values: 151 | * @arg NVIC_VectTab_RAM 152 | * @arg NVIC_VectTab_FLASH 153 | * @param Offset: Vector Table base offset field. 154 | * This value must be a multiple of 0x100. 155 | * @retval : None 156 | */ 157 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 158 | { 159 | /* Check the parameters */ 160 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 161 | assert_param(IS_NVIC_OFFSET(Offset)); 162 | 163 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 164 | } 165 | 166 | /** 167 | * @brief Selects the condition for the system to enter low power mode. 168 | * @param LowPowerMode: Specifies the new mode for the system to enter 169 | * low power mode. 170 | * This parameter can be one of the following values: 171 | * @arg NVIC_LP_SEVONPEND 172 | * @arg NVIC_LP_SLEEPDEEP 173 | * @arg NVIC_LP_SLEEPONEXIT 174 | * @param NewState: new state of LP condition. 175 | * This parameter can be: ENABLE or DISABLE. 176 | * @retval : None 177 | */ 178 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 179 | { 180 | /* Check the parameters */ 181 | assert_param(IS_NVIC_LP(LowPowerMode)); 182 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 183 | 184 | if (NewState != DISABLE) 185 | { 186 | SCB->SCR |= LowPowerMode; 187 | } 188 | else 189 | { 190 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 191 | } 192 | } 193 | 194 | /** 195 | * @brief Configures the SysTick clock source. 196 | * @param SysTick_CLKSource: specifies the SysTick clock source. 197 | * This parameter can be one of the following values: 198 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 199 | * selected as SysTick clock source. 200 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as 201 | * SysTick clock source. 202 | * @retval : None 203 | */ 204 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 205 | { 206 | /* Check the parameters */ 207 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 208 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 209 | { 210 | SysTick->CTRL |= SysTick_CLKSource_HCLK; 211 | } 212 | else 213 | { 214 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 215 | } 216 | } 217 | 218 | /** 219 | * @} 220 | */ 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | /** 227 | * @} 228 | */ 229 | 230 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 231 | -------------------------------------------------------------------------------- /FWlib/inc/stm32f10x_bkp.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_bkp.h 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file contains all the functions prototypes for the BKP firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_BKP_H 24 | #define __STM32F10x_BKP_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "stm32f10x.h" 28 | 29 | /** @addtogroup StdPeriph_Driver 30 | * @{ 31 | */ 32 | 33 | /** @addtogroup BKP 34 | * @{ 35 | */ 36 | 37 | /** @defgroup BKP_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @} 43 | */ 44 | 45 | /** @defgroup BKP_Exported_Constants 46 | * @{ 47 | */ 48 | 49 | /** @defgroup Tamper_Pin_active_level 50 | * @{ 51 | */ 52 | 53 | #define BKP_TamperPinLevel_High ((uint16_t)0x0000) 54 | #define BKP_TamperPinLevel_Low ((uint16_t)0x0001) 55 | #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \ 56 | ((LEVEL) == BKP_TamperPinLevel_Low)) 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin 62 | * @{ 63 | */ 64 | 65 | #define BKP_RTCOutputSource_None ((uint16_t)0x0000) 66 | #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080) 67 | #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100) 68 | #define BKP_RTCOutputSource_Second ((uint16_t)0x0300) 69 | #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \ 70 | ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \ 71 | ((SOURCE) == BKP_RTCOutputSource_Alarm) || \ 72 | ((SOURCE) == BKP_RTCOutputSource_Second)) 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup Data_Backup_Register 78 | * @{ 79 | */ 80 | 81 | #define BKP_DR1 ((uint16_t)0x0004) 82 | #define BKP_DR2 ((uint16_t)0x0008) 83 | #define BKP_DR3 ((uint16_t)0x000C) 84 | #define BKP_DR4 ((uint16_t)0x0010) 85 | #define BKP_DR5 ((uint16_t)0x0014) 86 | #define BKP_DR6 ((uint16_t)0x0018) 87 | #define BKP_DR7 ((uint16_t)0x001C) 88 | #define BKP_DR8 ((uint16_t)0x0020) 89 | #define BKP_DR9 ((uint16_t)0x0024) 90 | #define BKP_DR10 ((uint16_t)0x0028) 91 | #define BKP_DR11 ((uint16_t)0x0040) 92 | #define BKP_DR12 ((uint16_t)0x0044) 93 | #define BKP_DR13 ((uint16_t)0x0048) 94 | #define BKP_DR14 ((uint16_t)0x004C) 95 | #define BKP_DR15 ((uint16_t)0x0050) 96 | #define BKP_DR16 ((uint16_t)0x0054) 97 | #define BKP_DR17 ((uint16_t)0x0058) 98 | #define BKP_DR18 ((uint16_t)0x005C) 99 | #define BKP_DR19 ((uint16_t)0x0060) 100 | #define BKP_DR20 ((uint16_t)0x0064) 101 | #define BKP_DR21 ((uint16_t)0x0068) 102 | #define BKP_DR22 ((uint16_t)0x006C) 103 | #define BKP_DR23 ((uint16_t)0x0070) 104 | #define BKP_DR24 ((uint16_t)0x0074) 105 | #define BKP_DR25 ((uint16_t)0x0078) 106 | #define BKP_DR26 ((uint16_t)0x007C) 107 | #define BKP_DR27 ((uint16_t)0x0080) 108 | #define BKP_DR28 ((uint16_t)0x0084) 109 | #define BKP_DR29 ((uint16_t)0x0088) 110 | #define BKP_DR30 ((uint16_t)0x008C) 111 | #define BKP_DR31 ((uint16_t)0x0090) 112 | #define BKP_DR32 ((uint16_t)0x0094) 113 | #define BKP_DR33 ((uint16_t)0x0098) 114 | #define BKP_DR34 ((uint16_t)0x009C) 115 | #define BKP_DR35 ((uint16_t)0x00A0) 116 | #define BKP_DR36 ((uint16_t)0x00A4) 117 | #define BKP_DR37 ((uint16_t)0x00A8) 118 | #define BKP_DR38 ((uint16_t)0x00AC) 119 | #define BKP_DR39 ((uint16_t)0x00B0) 120 | #define BKP_DR40 ((uint16_t)0x00B4) 121 | #define BKP_DR41 ((uint16_t)0x00B8) 122 | #define BKP_DR42 ((uint16_t)0x00BC) 123 | 124 | #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \ 125 | ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \ 126 | ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \ 127 | ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \ 128 | ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \ 129 | ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \ 130 | ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \ 131 | ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \ 132 | ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \ 133 | ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \ 134 | ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \ 135 | ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \ 136 | ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \ 137 | ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42)) 138 | 139 | #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F) 140 | /** 141 | * @} 142 | */ 143 | 144 | /** 145 | * @} 146 | */ 147 | 148 | /** @defgroup BKP_Exported_Macros 149 | * @{ 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** @defgroup BKP_Exported_Functions 157 | * @{ 158 | */ 159 | 160 | void BKP_DeInit(void); 161 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel); 162 | void BKP_TamperPinCmd(FunctionalState NewState); 163 | void BKP_ITConfig(FunctionalState NewState); 164 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource); 165 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue); 166 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data); 167 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR); 168 | FlagStatus BKP_GetFlagStatus(void); 169 | void BKP_ClearFlag(void); 170 | ITStatus BKP_GetITStatus(void); 171 | void BKP_ClearITPendingBit(void); 172 | 173 | #endif /* __STM32F10x_BKP_H */ 174 | /** 175 | * @} 176 | */ 177 | 178 | /** 179 | * @} 180 | */ 181 | 182 | /** 183 | * @} 184 | */ 185 | 186 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 187 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_bkp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_bkp.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the BKP firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_bkp.h" 23 | #include "stm32f10x_rcc.h" 24 | 25 | /** @addtogroup StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup BKP 30 | * @brief BKP driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup BKP_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup BKP_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /* ------------ BKP registers bit address in the alias region --------------- */ 47 | #define BKP_OFFSET (BKP_BASE - PERIPH_BASE) 48 | 49 | /* --- CR Register ----*/ 50 | 51 | /* Alias word address of TPAL bit */ 52 | #define CR_OFFSET (BKP_OFFSET + 0x30) 53 | #define TPAL_BitNumber 0x01 54 | #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4)) 55 | 56 | /* Alias word address of TPE bit */ 57 | #define TPE_BitNumber 0x00 58 | #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4)) 59 | 60 | /* --- CSR Register ---*/ 61 | 62 | /* Alias word address of TPIE bit */ 63 | #define CSR_OFFSET (BKP_OFFSET + 0x34) 64 | #define TPIE_BitNumber 0x02 65 | #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4)) 66 | 67 | /* Alias word address of TIF bit */ 68 | #define TIF_BitNumber 0x09 69 | #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4)) 70 | 71 | /* Alias word address of TEF bit */ 72 | #define TEF_BitNumber 0x08 73 | #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4)) 74 | 75 | /* ---------------------- BKP registers bit mask ------------------------ */ 76 | 77 | /* RTCCR register bit mask */ 78 | #define RTCCR_CAL_Mask ((uint16_t)0xFF80) 79 | #define RTCCR_Mask ((uint16_t)0xFC7F) 80 | 81 | /* CSR register bit mask */ 82 | #define CSR_CTE_Set ((uint16_t)0x0001) 83 | #define CSR_CTI_Set ((uint16_t)0x0002) 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | 90 | /** @defgroup BKP_Private_Macros 91 | * @{ 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup BKP_Private_Variables 99 | * @{ 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /** @defgroup BKP_Private_FunctionPrototypes 107 | * @{ 108 | */ 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | /** @defgroup BKP_Private_Functions 115 | * @{ 116 | */ 117 | 118 | /** 119 | * @brief Deinitializes the BKP peripheral registers to their default 120 | * reset values. 121 | * @param None 122 | * @retval : None 123 | */ 124 | void BKP_DeInit(void) 125 | { 126 | RCC_BackupResetCmd(ENABLE); 127 | RCC_BackupResetCmd(DISABLE); 128 | } 129 | 130 | /** 131 | * @brief Configures the Tamper Pin active level. 132 | * @param BKP_TamperPinLevel: specifies the Tamper Pin active level. 133 | * This parameter can be one of the following values: 134 | * @arg BKP_TamperPinLevel_High: Tamper pin active on high level 135 | * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level 136 | * @retval : None 137 | */ 138 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel) 139 | { 140 | /* Check the parameters */ 141 | assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel)); 142 | *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel; 143 | } 144 | 145 | /** 146 | * @brief Enables or disables the Tamper Pin activation. 147 | * @param NewState: new state of the Tamper Pin activation. 148 | * This parameter can be: ENABLE or DISABLE. 149 | * @retval : None 150 | */ 151 | void BKP_TamperPinCmd(FunctionalState NewState) 152 | { 153 | /* Check the parameters */ 154 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 155 | *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState; 156 | } 157 | 158 | /** 159 | * @brief Enables or disables the Tamper Pin Interrupt. 160 | * @param NewState: new state of the Tamper Pin Interrupt. 161 | * This parameter can be: ENABLE or DISABLE. 162 | * @retval : None 163 | */ 164 | void BKP_ITConfig(FunctionalState NewState) 165 | { 166 | /* Check the parameters */ 167 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 168 | *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState; 169 | } 170 | 171 | /** 172 | * @brief Select the RTC output source to output on the Tamper pin. 173 | * @param BKP_RTCOutputSource: specifies the RTC output source. 174 | * This parameter can be one of the following values: 175 | * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin. 176 | * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock 177 | * with frequency divided by 64 on the Tamper pin. 178 | * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse 179 | * signal on the Tamper pin. 180 | * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse 181 | * signal on the Tamper pin. 182 | * @retval : None 183 | */ 184 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource) 185 | { 186 | uint16_t tmpreg = 0; 187 | /* Check the parameters */ 188 | assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource)); 189 | tmpreg = BKP->RTCCR; 190 | /* Clear CCO, ASOE and ASOS bits */ 191 | tmpreg &= RTCCR_Mask; 192 | 193 | /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */ 194 | tmpreg |= BKP_RTCOutputSource; 195 | /* Store the new value */ 196 | BKP->RTCCR = tmpreg; 197 | } 198 | 199 | /** 200 | * @brief Sets RTC Clock Calibration value. 201 | * @param CalibrationValue: specifies the RTC Clock Calibration value. 202 | * This parameter must be a number between 0 and 0x7F. 203 | * @retval : None 204 | */ 205 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue) 206 | { 207 | uint16_t tmpreg = 0; 208 | /* Check the parameters */ 209 | assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue)); 210 | tmpreg = BKP->RTCCR; 211 | /* Clear CAL[6:0] bits */ 212 | tmpreg &= RTCCR_CAL_Mask; 213 | /* Set CAL[6:0] bits according to CalibrationValue value */ 214 | tmpreg |= CalibrationValue; 215 | /* Store the new value */ 216 | BKP->RTCCR = tmpreg; 217 | } 218 | 219 | /** 220 | * @brief Writes user data to the specified Data Backup Register. 221 | * @param BKP_DR: specifies the Data Backup Register. 222 | * This parameter can be BKP_DRx where x:[1, 42] 223 | * @param Data: data to write 224 | * @retval : None 225 | */ 226 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data) 227 | { 228 | /* Check the parameters */ 229 | assert_param(IS_BKP_DR(BKP_DR)); 230 | *(__IO uint16_t *) (BKP_BASE + BKP_DR) = Data; 231 | } 232 | 233 | /** 234 | * @brief Reads data from the specified Data Backup Register. 235 | * @param BKP_DR: specifies the Data Backup Register. 236 | * This parameter can be BKP_DRx where x:[1, 42] 237 | * @retval : The content of the specified Data Backup Register 238 | */ 239 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR) 240 | { 241 | /* Check the parameters */ 242 | assert_param(IS_BKP_DR(BKP_DR)); 243 | return (*(__IO uint16_t *) (BKP_BASE + BKP_DR)); 244 | } 245 | 246 | /** 247 | * @brief Checks whether the Tamper Pin Event flag is set or not. 248 | * @param None 249 | * @retval : The new state of the Tamper Pin Event flag (SET or RESET). 250 | */ 251 | FlagStatus BKP_GetFlagStatus(void) 252 | { 253 | return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB); 254 | } 255 | 256 | /** 257 | * @brief Clears Tamper Pin Event pending flag. 258 | * @param None 259 | * @retval : None 260 | */ 261 | void BKP_ClearFlag(void) 262 | { 263 | /* Set CTE bit to clear Tamper Pin Event flag */ 264 | BKP->CSR |= CSR_CTE_Set; 265 | } 266 | 267 | /** 268 | * @brief Checks whether the Tamper Pin Interrupt has occurred or not. 269 | * @param None 270 | * @retval : The new state of the Tamper Pin Interrupt (SET or RESET). 271 | */ 272 | ITStatus BKP_GetITStatus(void) 273 | { 274 | return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB); 275 | } 276 | 277 | /** 278 | * @brief Clears Tamper Pin Interrupt pending bit. 279 | * @param None 280 | * @retval : None 281 | */ 282 | void BKP_ClearITPendingBit(void) 283 | { 284 | /* Set CTI bit to clear Tamper Pin Interrupt pending bit */ 285 | BKP->CSR |= CSR_CTI_Set; 286 | } 287 | 288 | /** 289 | * @} 290 | */ 291 | 292 | /** 293 | * @} 294 | */ 295 | 296 | /** 297 | * @} 298 | */ 299 | 300 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 301 | -------------------------------------------------------------------------------- /FWlib/src/stm32f10x_pwr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.c 4 | * @author MCD Application Team 5 | * @version V3.0.0 6 | * @date 04/06/2009 7 | * @brief This file provides all the PWR firmware functions. 8 | ****************************************************************************** 9 | * @copy 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2009 STMicroelectronics

19 | */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f10x_pwr.h" 23 | #include "stm32f10x_rcc.h" 24 | 25 | /** @addtogroup StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup PWR 30 | * @brief PWR driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup PWR_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup PWR_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /* --------- PWR registers bit address in the alias region ---------- */ 47 | #define PWR_OFFSET (PWR_BASE - PERIPH_BASE) 48 | 49 | /* --- CR Register ---*/ 50 | 51 | /* Alias word address of DBP bit */ 52 | #define CR_OFFSET (PWR_OFFSET + 0x00) 53 | #define DBP_BitNumber 0x08 54 | #define CR_DBP_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (DBP_BitNumber * 4)) 55 | 56 | /* Alias word address of PVDE bit */ 57 | #define PVDE_BitNumber 0x04 58 | #define CR_PVDE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PVDE_BitNumber * 4)) 59 | 60 | /* --- CSR Register ---*/ 61 | 62 | /* Alias word address of EWUP bit */ 63 | #define CSR_OFFSET (PWR_OFFSET + 0x04) 64 | #define EWUP_BitNumber 0x08 65 | #define CSR_EWUP_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (EWUP_BitNumber * 4)) 66 | 67 | /* ------------------ PWR registers bit mask ------------------------ */ 68 | 69 | /* CR register bit mask */ 70 | #define CR_PDDS_Set ((uint32_t)0x00000002) 71 | #define CR_DS_Mask ((uint32_t)0xFFFFFFFC) 72 | #define CR_CWUF_Set ((uint32_t)0x00000004) 73 | #define CR_PLS_Mask ((uint32_t)0xFFFFFF1F) 74 | 75 | /* --------- Cortex System Control register bit mask ---------------- */ 76 | 77 | /* Cortex System Control register address */ 78 | #define SCB_SysCtrl ((uint32_t)0xE000ED10) 79 | 80 | /* SLEEPDEEP bit mask */ 81 | #define SysCtrl_SLEEPDEEP_Set ((uint32_t)0x00000004) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup PWR_Private_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup PWR_Private_Variables 95 | * @{ 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup PWR_Private_FunctionPrototypes 103 | * @{ 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @defgroup PWR_Private_Functions 111 | * @{ 112 | */ 113 | 114 | /** 115 | * @brief Deinitializes the PWR peripheral registers to their default 116 | * reset values. 117 | * @param None 118 | * @retval : None 119 | */ 120 | void PWR_DeInit(void) 121 | { 122 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, ENABLE); 123 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE); 124 | } 125 | 126 | /** 127 | * @brief Enables or disables access to the RTC and backup registers. 128 | * @param NewState: new state of the access to the RTC and backup 129 | * registers. This parameter can be: ENABLE or DISABLE. 130 | * @retval : None 131 | */ 132 | void PWR_BackupAccessCmd(FunctionalState NewState) 133 | { 134 | /* Check the parameters */ 135 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 136 | *(__IO uint32_t *) CR_DBP_BB = (uint32_t)NewState; 137 | } 138 | 139 | /** 140 | * @brief Enables or disables the Power Voltage Detector(PVD). 141 | * @param NewState: new state of the PVD. 142 | * This parameter can be: ENABLE or DISABLE. 143 | * @retval : None 144 | */ 145 | void PWR_PVDCmd(FunctionalState NewState) 146 | { 147 | /* Check the parameters */ 148 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 149 | *(__IO uint32_t *) CR_PVDE_BB = (uint32_t)NewState; 150 | } 151 | 152 | /** 153 | * @brief Configures the voltage threshold detected by the Power Voltage 154 | * Detector(PVD). 155 | * @param PWR_PVDLevel: specifies the PVD detection level 156 | * This parameter can be one of the following values: 157 | * @arg PWR_PVDLevel_2V2: PVD detection level set to 2.2V 158 | * @arg PWR_PVDLevel_2V3: PVD detection level set to 2.3V 159 | * @arg PWR_PVDLevel_2V4: PVD detection level set to 2.4V 160 | * @arg PWR_PVDLevel_2V5: PVD detection level set to 2.5V 161 | * @arg PWR_PVDLevel_2V6: PVD detection level set to 2.6V 162 | * @arg PWR_PVDLevel_2V7: PVD detection level set to 2.7V 163 | * @arg PWR_PVDLevel_2V8: PVD detection level set to 2.8V 164 | * @arg PWR_PVDLevel_2V9: PVD detection level set to 2.9V 165 | * @retval : None 166 | */ 167 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel) 168 | { 169 | uint32_t tmpreg = 0; 170 | /* Check the parameters */ 171 | assert_param(IS_PWR_PVD_LEVEL(PWR_PVDLevel)); 172 | tmpreg = PWR->CR; 173 | /* Clear PLS[7:5] bits */ 174 | tmpreg &= CR_PLS_Mask; 175 | /* Set PLS[7:5] bits according to PWR_PVDLevel value */ 176 | tmpreg |= PWR_PVDLevel; 177 | /* Store the new value */ 178 | PWR->CR = tmpreg; 179 | } 180 | 181 | /** 182 | * @brief Enables or disables the WakeUp Pin functionality. 183 | * @param NewState: new state of the WakeUp Pin functionality. 184 | * This parameter can be: ENABLE or DISABLE. 185 | * @retval : None 186 | */ 187 | void PWR_WakeUpPinCmd(FunctionalState NewState) 188 | { 189 | /* Check the parameters */ 190 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 191 | *(__IO uint32_t *) CSR_EWUP_BB = (uint32_t)NewState; 192 | } 193 | 194 | /** 195 | * @brief Enters STOP mode. 196 | * @param PWR_Regulator: specifies the regulator state in STOP mode. 197 | * This parameter can be one of the following values: 198 | * @arg PWR_Regulator_ON: STOP mode with regulator ON 199 | * @arg PWR_Regulator_LowPower: STOP mode with 200 | * regulator in low power mode 201 | * @param PWR_STOPEntry: specifies if STOP mode in entered with WFI or 202 | * WFE instruction. 203 | * This parameter can be one of the following values: 204 | * @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction 205 | * @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction 206 | * @retval : None 207 | */ 208 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry) 209 | { 210 | uint32_t tmpreg = 0; 211 | /* Check the parameters */ 212 | assert_param(IS_PWR_REGULATOR(PWR_Regulator)); 213 | assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry)); 214 | 215 | /* Select the regulator state in STOP mode ---------------------------------*/ 216 | tmpreg = PWR->CR; 217 | /* Clear PDDS and LPDS bits */ 218 | tmpreg &= CR_DS_Mask; 219 | /* Set LPDS bit according to PWR_Regulator value */ 220 | tmpreg |= PWR_Regulator; 221 | /* Store the new value */ 222 | PWR->CR = tmpreg; 223 | /* Set SLEEPDEEP bit of Cortex System Control Register */ 224 | *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set; 225 | 226 | /* Select STOP mode entry --------------------------------------------------*/ 227 | if(PWR_STOPEntry == PWR_STOPEntry_WFI) 228 | { 229 | /* Request Wait For Interrupt */ 230 | __WFI(); 231 | } 232 | else 233 | { 234 | /* Request Wait For Event */ 235 | __WFE(); 236 | } 237 | } 238 | 239 | /** 240 | * @brief Enters STANDBY mode. 241 | * @param None 242 | * @retval : None 243 | */ 244 | void PWR_EnterSTANDBYMode(void) 245 | { 246 | /* Clear Wake-up flag */ 247 | PWR->CR |= CR_CWUF_Set; 248 | /* Select STANDBY mode */ 249 | PWR->CR |= CR_PDDS_Set; 250 | /* Set SLEEPDEEP bit of Cortex System Control Register */ 251 | *(__IO uint32_t *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set; 252 | /* This option is used to ensure that store operations are completed */ 253 | #if defined ( __CC_ARM ) 254 | __force_stores(); 255 | #endif 256 | /* Request Wait For Interrupt */ 257 | __WFI(); 258 | } 259 | 260 | /** 261 | * @brief Checks whether the specified PWR flag is set or not. 262 | * @param PWR_FLAG: specifies the flag to check. 263 | * This parameter can be one of the following values: 264 | * @arg PWR_FLAG_WU: Wake Up flag 265 | * @arg PWR_FLAG_SB: StandBy flag 266 | * @arg PWR_FLAG_PVDO: PVD Output 267 | * @retval : The new state of PWR_FLAG (SET or RESET). 268 | */ 269 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG) 270 | { 271 | FlagStatus bitstatus = RESET; 272 | /* Check the parameters */ 273 | assert_param(IS_PWR_GET_FLAG(PWR_FLAG)); 274 | 275 | if ((PWR->CSR & PWR_FLAG) != (uint32_t)RESET) 276 | { 277 | bitstatus = SET; 278 | } 279 | else 280 | { 281 | bitstatus = RESET; 282 | } 283 | /* Return the flag status */ 284 | return bitstatus; 285 | } 286 | 287 | /** 288 | * @brief Clears the PWR's pending flags. 289 | * @param PWR_FLAG: specifies the flag to clear. 290 | * This parameter can be one of the following values: 291 | * @arg PWR_FLAG_WU: Wake Up flag 292 | * @arg PWR_FLAG_SB: StandBy flag 293 | * @retval : None 294 | */ 295 | void PWR_ClearFlag(uint32_t PWR_FLAG) 296 | { 297 | /* Check the parameters */ 298 | assert_param(IS_PWR_CLEAR_FLAG(PWR_FLAG)); 299 | 300 | PWR->CR |= PWR_FLAG << 2; 301 | } 302 | 303 | /** 304 | * @} 305 | */ 306 | 307 | /** 308 | * @} 309 | */ 310 | 311 | /** 312 | * @} 313 | */ 314 | 315 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 316 | --------------------------------------------------------------------------------