diff --git a/bacnet-stack/ports/stm32f10x/bacnet.c b/bacnet-stack/ports/stm32f10x/bacnet.c
index f62871b3..4fb1c0a4 100644
--- a/bacnet-stack/ports/stm32f10x/bacnet.c
+++ b/bacnet-stack/ports/stm32f10x/bacnet.c
@@ -49,12 +49,12 @@ static struct itimer DCC_Timer;
void bacnet_init(
void)
{
- dlmstp_set_mac_address(103);
+ dlmstp_set_mac_address(255);
dlmstp_set_max_master(127);
/* initialize datalink layer */
dlmstp_init(NULL);
/* initialize objects */
- Device_Init();
+ Device_Init(NULL);
/* set up our confirmed service unrecognized service handler - required! */
apdu_set_unrecognized_service_handler_handler
diff --git a/bacnet-stack/ports/stm32f10x/bacnet.ewp b/bacnet-stack/ports/stm32f10x/bacnet.ewp
index 6b695e34..aca99b91 100644
--- a/bacnet-stack/ports/stm32f10x/bacnet.ewp
+++ b/bacnet-stack/ports/stm32f10x/bacnet.ewp
@@ -12,7 +12,7 @@
General
3
- 20
+ 21
1
1
+
+
ICCARM
2
- 26
+ 27
1
1
+
@@ -609,7 +622,7 @@
ILINK
0
- 11
+ 12
1
1
+
@@ -894,7 +911,7 @@
General
3
- 20
+ 21
1
0
+
+
ICCARM
2
- 26
+ 27
1
0
+
@@ -1492,12 +1522,12 @@
ILINK
0
- 11
+ 12
1
0
+
diff --git a/bacnet-stack/ports/stm32f10x/device.c b/bacnet-stack/ports/stm32f10x/device.c
index 13903509..e8d4751d 100644
--- a/bacnet-stack/ports/stm32f10x/device.c
+++ b/bacnet-stack/ports/stm32f10x/device.c
@@ -141,7 +141,6 @@ static int Read_Property_Common(
{
int apdu_len = BACNET_STATUS_ERROR;
BACNET_CHARACTER_STRING char_string;
- char *pString = "";
uint8_t *apdu = NULL;
if ((rpdata->application_data == NULL) ||
@@ -151,29 +150,50 @@ static int Read_Property_Common(
apdu = rpdata->application_data;
switch (rpdata->object_property) {
case PROP_OBJECT_IDENTIFIER:
- /* Device Object exception: requested instance
- may not match our instance if a wildcard */
- if (rpdata->object_type == OBJECT_DEVICE) {
- rpdata->object_instance = Object_Instance_Number;
+ /* only array properties can have array options */
+ if (rpdata->array_index != BACNET_ARRAY_ALL) {
+ rpdata->error_class = ERROR_CLASS_PROPERTY;
+ rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
+ apdu_len = BACNET_STATUS_ERROR;
+ } else {
+ /* Device Object exception: requested instance
+ may not match our instance if a wildcard */
+ if (rpdata->object_type == OBJECT_DEVICE) {
+ rpdata->object_instance = Object_Instance_Number;
+ }
+ apdu_len =
+ encode_application_object_id(&apdu[0], rpdata->object_type,
+ rpdata->object_instance);
}
- apdu_len =
- encode_application_object_id(&apdu[0], rpdata->object_type,
- rpdata->object_instance);
break;
case PROP_OBJECT_NAME:
- if (pObject->Object_Name) {
- (void)pObject->Object_Name(
- rpdata->object_instance,
- &char_string);
+ /* only array properties can have array options */
+ if (rpdata->array_index != BACNET_ARRAY_ALL) {
+ rpdata->error_class = ERROR_CLASS_PROPERTY;
+ rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
+ apdu_len = BACNET_STATUS_ERROR;
} else {
characterstring_init_ansi(&char_string, "");
+ if (pObject->Object_Name) {
+ (void)pObject->Object_Name(
+ rpdata->object_instance,
+ &char_string);
+ }
}
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
case PROP_OBJECT_TYPE:
- apdu_len =
- encode_application_enumerated(&apdu[0], rpdata->object_type);
+ /* only array properties can have array options */
+ if (rpdata->array_index != BACNET_ARRAY_ALL) {
+ rpdata->error_class = ERROR_CLASS_PROPERTY;
+ rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY;
+ apdu_len = BACNET_STATUS_ERROR;
+ } else {
+ apdu_len =
+ encode_application_enumerated(&apdu[0],
+ rpdata->object_type);
+ }
break;
default:
if (pObject->Object_Read_Property) {
@@ -363,10 +383,11 @@ BACNET_REINITIALIZED_STATE Device_Reinitialized_State(
}
void Device_Init(
- void)
+ object_functions_t * object_table)
{
struct my_object_functions *pObject = NULL;
+ (void)object_table;
pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Init) {
@@ -520,7 +541,7 @@ bool Device_Valid_Object_Name(
for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) {
- pObject = Device_Objects_Find_Functions(type);
+ pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) {
@@ -546,7 +567,7 @@ bool Device_Valid_Object_Id(
bool status = false; /* return value */
struct my_object_functions *pObject = NULL;
- pObject = Device_Objects_Find_Functions(object_type);
+ pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)object_type);
if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) {
status = pObject->Object_Valid_Instance(object_instance);
}
@@ -570,7 +591,7 @@ bool Device_Object_Name_Copy(
for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) {
- pObject = Device_Objects_Find_Functions(type);
+ pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
if ((pObject != NULL) && (pObject->Object_Name != NULL)) {
found = pObject->Object_Name(instance, object_name);
break;
diff --git a/bacnet-stack/ports/stm32f10x/led.c b/bacnet-stack/ports/stm32f10x/led.c
index 60bfa31d..03babd4a 100644
--- a/bacnet-stack/ports/stm32f10x/led.c
+++ b/bacnet-stack/ports/stm32f10x/led.c
@@ -30,6 +30,7 @@ static struct itimer Off_Delay_Timer_Rx;
static struct itimer Off_Delay_Timer_Tx;
static bool Rx_State;
static bool Tx_State;
+static bool LD3_State;
/*************************************************************************
* Description: Activate the LED
@@ -104,7 +105,7 @@ bool led_tx_state(void)
}
/*************************************************************************
-* Description: Toggle the state of the setup LED
+* Description: Toggle the state of the LED
* Returns: none
* Notes: none
*************************************************************************/
@@ -118,7 +119,7 @@ void led_tx_toggle(void)
}
/*************************************************************************
-* Description: Toggle the state of the setup LED
+* Description: Toggle the state of the LED
* Returns: none
* Notes: none
*************************************************************************/
@@ -195,6 +196,76 @@ void led_task(
}
}
+/*************************************************************************
+* Description: Activate the LED
+* Returns: nothing
+* Notes: none
+**************************************************************************/
+void led_ld4_on(
+ void)
+{
+ GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
+}
+
+/*************************************************************************
+* Description: Deactivate the LED
+* Returns: nothing
+* Notes: none
+**************************************************************************/
+void led_ld4_off(
+ void)
+{
+ GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
+}
+
+/*************************************************************************
+* Description: Activate the LED
+* Returns: nothing
+* Notes: none
+**************************************************************************/
+void led_ld3_on(
+ void)
+{
+ GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET);
+ LD3_State = true;
+}
+
+/*************************************************************************
+* Description: Deactivate the LED
+* Returns: nothing
+* Notes: none
+**************************************************************************/
+void led_ld3_off(
+ void)
+{
+ GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET);
+ LD3_State = false;
+}
+
+/*************************************************************************
+* Description: Get the state of the LED
+* Returns: true if on, false if off.
+* Notes: none
+*************************************************************************/
+bool led_ld3_state(void)
+{
+ return LD3_State;
+}
+
+/*************************************************************************
+* Description: Toggle the state of the LED
+* Returns: none
+* Notes: none
+*************************************************************************/
+void led_ld3_toggle(void)
+{
+ if (led_ld3_state()) {
+ led_ld3_off();
+ } else {
+ led_ld3_on();
+ }
+}
+
/*************************************************************************
* Description: Initialize the LED hardware
* Returns: none
@@ -206,19 +277,32 @@ void led_init(
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
- /* Configure the Receive LED */
+ /* Configure the Receive LED on MS/TP board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* Configure the Transmit LED */
+ /* Configure the Transmit LED on MS/TP board */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
+ /* Configure the LD4 on Discovery board */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+ /* Configure the LD3 on Discovery board */
+ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(GPIOC, &GPIO_InitStructure);
+ /* Enable the GPIO_LED Clock */
+ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- led_tx_on_interval(500);
- led_rx_on_interval(500);
+ led_tx_on();
+ led_rx_on();
+ led_ld3_on();
+ led_ld4_on();
}
diff --git a/bacnet-stack/ports/stm32f10x/led.h b/bacnet-stack/ports/stm32f10x/led.h
index fe4d931f..51e4fb22 100644
--- a/bacnet-stack/ports/stm32f10x/led.h
+++ b/bacnet-stack/ports/stm32f10x/led.h
@@ -31,6 +31,17 @@
extern "C" {
#endif /* __cplusplus */
+ void led_ld3_on(
+ void);
+ void led_ld4_on(
+ void);
+ void led_ld3_off(
+ void);
+ void led_ld4_off(
+ void);
+ bool led_ld3_state(void);
+ void led_ld3_toggle(void);
+
void led_tx_on(void);
void led_rx_on(void);
diff --git a/bacnet-stack/ports/stm32f10x/main.c b/bacnet-stack/ports/stm32f10x/main.c
index 8d650be0..e0b3d5c9 100644
--- a/bacnet-stack/ports/stm32f10x/main.c
+++ b/bacnet-stack/ports/stm32f10x/main.c
@@ -56,20 +56,86 @@ void assert_failed(uint8_t* file, uint32_t line)
}
#endif
+/* Private define ------------------------------------------------------------*/
+#define LSE_FAIL_FLAG 0x80
+#define LSE_PASS_FLAG 0x100
+
+void lse_init(void)
+{
+ uint32_t LSE_Delay = 0;
+ struct etimer Delay_Timer;
+
+ /* Enable access to the backup register => LSE can be enabled */
+ PWR_BackupAccessCmd(ENABLE);
+ /* Enable LSE (Low Speed External Oscillation) */
+ RCC_LSEConfig(RCC_LSE_ON);
+
+ /* Check the LSE Status */
+ while(1)
+ {
+ if(LSE_Delay < LSE_FAIL_FLAG)
+ {
+ timer_elapsed_start(&Delay_Timer);
+ while (!timer_elapsed_milliseconds(&Delay_Timer,500)) {
+ /* do nothing */
+ }
+ /* check whether LSE is ready, with 4 seconds timeout */
+ LSE_Delay += 0x10;
+ if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET)
+ {
+ /* Set flag: LSE PASS */
+ LSE_Delay |= LSE_PASS_FLAG;
+ led_ld4_off();
+ /* Disable LSE */
+ RCC_LSEConfig(RCC_LSE_OFF);
+ break;
+ }
+ }
+
+ /* LSE_FAIL_FLAG = 0x80 */
+ else if(LSE_Delay >= LSE_FAIL_FLAG)
+ {
+ if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
+ {
+ /* Set flag: LSE FAIL */
+ LSE_Delay |= LSE_FAIL_FLAG;
+ led_ld4_on();
+ }
+ /* Disable LSE */
+ RCC_LSEConfig(RCC_LSE_OFF);
+ break;
+ }
+ }
+}
+
int main(
void)
{
+ struct itimer Blink_Timer;
+
/*At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file */
+ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
+ led_init();
+ RCC_APB2PeriphClockCmd(
+ RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
+ RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
+ RCC_APB2Periph_GPIOE, ENABLE);
timer_init();
+ lse_init();
led_init();
rs485_init();
bacnet_init();
+ timer_interval_start(&Blink_Timer, 125);
for (;;) {
+ if (timer_interval_expired(&Blink_Timer)) {
+ timer_interval_reset(&Blink_Timer);
+ led_ld3_toggle();
+ }
led_task();
bacnet_task();
}
diff --git a/bacnet-stack/ports/stm32f10x/stm32f10x_flash.icf b/bacnet-stack/ports/stm32f10x/stm32f10x_flash.icf
index e14b28a7..681dd043 100644
--- a/bacnet-stack/ports/stm32f10x/stm32f10x_flash.icf
+++ b/bacnet-stack/ports/stm32f10x/stm32f10x_flash.icf
@@ -5,9 +5,9 @@
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ;
-define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF;
+define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
-define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF;
+define symbol __ICFEDIT_region_RAM_end__ = 0x20017FFF;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__ = 0x200;