Tải Thư viện tại đây:
Đăng nhập để Tải
Hướng Dẫn:
bạn tải demo ethernet trong topic sau, rồi add thư viện vào :
Đăng nhập
port.h :
#include "stm32f4xx_conf.h"
#define ENTER_CRITICAL_SECTION( ) ( __disable_irq() )
#define EXIT_CRITICAL_SECTION( ) ( __enable_irq() )
**********************************************************
porttcp.c bỏ hàm này:
vMBPortEventClose( );
******************************************************
Main.c:
/**
******************************************************************************
* @file main.c
* @author MCD Application Team
* @version V1.1.0
* @date 31-July-2013
* @brief Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4x7_eth.h"
#include "stm32f4_discovery.h"
#include "netconf.h"
#include "main.h"
#include "httpd.h"
#include "misc.h"
/* ----------------------- Modbus includes ----------------------------------*/
#include "mb.h"
#include "mbtcp.h"
/* ----------------------- Defines ------------------------------------------*/
#define REG_INPUT_START 1000
#define REG_INPUT_NREGS 4
#define REG_HOLDING_START 2000
#define REG_HOLDING_NREGS 130
/* ----------------------- Static variables ---------------------------------*/
static USHORT usRegInputStart = REG_INPUT_START;
static USHORT usRegInputBuf[REG_INPUT_NREGS];
static USHORT usRegHoldingStart = REG_HOLDING_START;
static USHORT usRegHoldingBuf[REG_HOLDING_NREGS];
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define SYSTEMTICK_PERIOD_MS 10
static UCHAR Vendor[14] = "WVC 0.2 - dB14";
/*--------------- LCD Messages ---------------*/
#if defined (STM32F40XX)
#define MESSAGE1 " STM32F40/41x "
#elif defined (STM32F427X)
#define MESSAGE1 " STM32F427x "
#endif
#define MESSAGE2 " STM32F-4 Series "
#define MESSAGE3 " Webserver Demo "
#define MESSAGE4 " "
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;
/* Private function prototypes -----------------------------------------------*/
void LCD_LED_Init(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured to
168 MHz, this is done through SystemInit() function which is called from
startup file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
#ifdef SERIAL_DEBUG
DebugComPort_Init();
#endif
/*Initialize LCD and Leds */
LCD_LED_Init();
/* configure ethernet (GPIOs, clocks, MAC, DMA) */
ETH_BSP_Config();
/* Initilaize the LwIP stack */
LwIP_Init();
/* Http webserver Init */
httpd_init();
/* inicialización del Stack de Modbus */
eMBTCPInit(0);
/* Habilita el Stack de Modbus */
eMBEnable();
/*Establesco el Slave ID*/
eMBSetSlaveID( MB_TCP_PSEUDO_ADDRESS, TRUE, Vendor, sizeof(Vendor) );
/* Infinite loop */
while (1)
{
/* llamado periódico para ejecutar el stack modbus */
eMBPoll();
/* check if any packet received */
if (ETH_CheckFrameReceived())
{
/* process received ethernet packet */
LwIP_Pkt_Handle();
}
/* handle periodic timers for LwIP */
LwIP_Periodic_Handle(LocalTime);
}
}
/**
* @brief Inserts a delay time.
* @param nCount: number of 10ms periods to wait for.
* @retval None
*/
void Delay(uint32_t nCount)
{
/* Capture the current local time */
timingdelay = LocalTime + nCount;
/* wait until the desired delay finish */
while(timingdelay > LocalTime)
{
}
}
/**
* @brief Updates the system local time
* @param None
* @retval None
*/
void Time_Update(void)
{
LocalTime += SYSTEMTICK_PERIOD_MS;
}
/**
* @brief Initializes the STM324xG-EVAL's LCD and LEDs resources
* @param None
* @retval None
*/
void LCD_LED_Init(void)
{
#ifdef USE_LCD
/* Initialize the STM324xG-EVAL's LCD */
STM324xG_LCD_Init();
#endif
/* Initialize STM324xG-EVAL's LEDs */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
#ifdef USE_LCD
/* Clear the LCD */
LCD_Clear(Black);
/* Set the LCD Back Color */
LCD_SetBackColor(Black);
/* Set the LCD Text Color */
LCD_SetTextColor(White);
/* Display message on the LCD*/
LCD_DisplayStringLine(Line0, (uint8_t*)MESSAGE1);
LCD_DisplayStringLine(Line1, (uint8_t*)MESSAGE2);
LCD_DisplayStringLine(Line2, (uint8_t*)MESSAGE3);
LCD_DisplayStringLine(Line3, (uint8_t*)MESSAGE4);
#endif
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
eMBErrorCode
eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
usRegInputBuf[0] = (GPIOD->ODR & 0xF000);
usRegInputBuf[0] = usRegInputBuf[0] >> 12;
usRegInputBuf[1] = usRegInputBuf[0];
if( ( usAddress >= REG_INPUT_START )
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
{
iRegIndex = ( int )( usAddress - usRegInputStart );
while( usNRegs > 0 )
{
*pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
*pucRegBuffer++ = ( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegisterMode eMode )
{
eMBErrorCode eStatus = MB_ENOERR;
int iRegIndex;
if( ( usAddress >= REG_HOLDING_START ) &&
( usAddress + usNRegs <= REG_HOLDING_START + REG_HOLDING_NREGS ) )
{
iRegIndex = ( int )( usAddress - usRegHoldingStart );
switch ( eMode )
{
/* Pass current register values to the protocol stack. */
case MB_REG_READ:
while( usNRegs > 0 )
{
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] >> 8 );
*pucRegBuffer++ = ( UCHAR ) ( usRegHoldingBuf[iRegIndex] & 0xFF );
iRegIndex++;
usNRegs--;
}
break;
/* Update current register values with new values from the
* protocol stack. */
case MB_REG_WRITE:
while( usNRegs > 0 )
{
usRegHoldingBuf[iRegIndex] = *pucRegBuffer++ << 8;
usRegHoldingBuf[iRegIndex] |= *pucRegBuffer++;
iRegIndex++;
usNRegs--;
}
}
}
else
{
eStatus = MB_ENOREG;
}
return eStatus;
}
eMBErrorCode
eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils, eMBRegisterMode eMode )
{
return MB_ENOREG;
}
eMBErrorCode
eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
{
return MB_ENOREG;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Lưu ý bạn StormV5 bị lỗi khi add xong thư viện nhưng không chạy (build ko có lỗi nhé), cụ thể lỗi hàm này: vprintf( szFmt, args );
ai bị thì bỏ hàm này đi. Riêng tui không bị phát sinh 1 lỗi nào khi add, cảm ơn bạn StormV5 đã chia sẽ, ai bị lỗi nào khi add thư viện thì tiếp tục post lên để mọi người giải quyết khi gặp và mọi người giúp đỡ.
Được sửa bởi Admin ngày 21/02/17, 02:11 pm; sửa lần 4.
26/03/24, 10:39 am by UgreenVietNam_official
» Báo giá buồng khử khuẩn
07/09/21, 09:07 am by kieumy902
» Giá lắp đặt giếng trời thông minh
22/03/21, 04:11 pm by kieumy902
» Thanh nhôm barie giá chỉ 500.000 đồng
09/03/21, 10:30 am by kieumy902
» Cửa hàng sửa máy tính ở tân cảnh
06/02/21, 08:53 pm by congtythienlong
» Giá barie chắn đường tại Bà Rịa - Vũng Tàu
25/01/21, 09:59 pm by kieumy902
» Lắp đặt barie tự động hcm
19/01/21, 03:52 pm by kieumy902
» Lắp đặt barie tự động khu công nghiệp - barrier tự động
14/01/21, 03:00 pm by kieumy902
» Giá bán tay cần barie 2m, 3m, 4m, 6m
12/01/21, 04:58 pm by kieumy902