Home

EMRF-BCM20737S User Manual

image

Contents

1. 1 ERRA TA c 3 SECTION 1 PROGRAM THE 20 73 75 rrenan N 3 SECTION 2 DEBUG OUTPUT WITH THE 2073 75 5 SECTION 3 HELLO SENSOR WALK 10 _ _ 11 B SENSOR CONFIGURATION 14 SECTION 4 HELLO SENSOR CODE ANALYSIS scsscssisssscssssssstssissssvsccsssscsassssassssscsatsssussssssssesausssscsassssacsssnteassssscsasssssssissssscenssssatsies 15 1 GATT DATABASE CONFIGURATION a E 15 2 BLE PROFILE STACK CONFIGURATION sccesceeseeeeeeeeeeeeceseeeecuaecnaecaaecaeecaeesaeeeesseeesecaeceaeceaeceaeceaecaaesaeecaeeeaeseeeseneseeseeseeseaeenaeenaes 19 3 PUARTAND GPIO
2. New Edit F2 Go Home Go Back Go Into Ctrl C Paste Ctrl V Delete Delete amp Build Target Rebuild Last Target F9 EMRF 20737S BOB V1 0 1 Page 41 Embedded Masters Now go to the top of the Make Target list and right click and past what we have copied back into the list Make Target 22 AS 4 WICED Smart SDK 4 4 power receiver BCM920737TAG 032 download a4wp power transmitter BCM920737TAG 032 download automation io BCM920737TAG Q32 download LI fia amr 7 7n Arnarr anr 3 New Edit F2 Go Go Back gt Golnto Copy Ctrl C Paste Ctrl V X Delete Delete Build Target Rebuild Last Target You will now see the dialog indicating that it is a Copy of hello_sensor make target Just rename it to MyProject Target name of hello_sensor BCM920737TAG_C Make Target Same as the target name Make target Copy of hello sensor BCM920737TAG Build Command So it now looks like this Target name MyProject BCM920737TAG 032 downlo Make Target Same as the target name Make target MyProject BCM920737TAG 032 downle NOTE You can leave everything else the way it is EMRF 20737S BOB V1 0 1 Page 42 7 8 Embedded Masters This Make Target finds the files from the folder structure Apps MyProject It then calls a make exe file which is loca
3. 207375 with the hello sensor app we will do the following steps to run the hello sensor app 1 Ensure you have disconnected the HCI RX line from the FTDI TX line so you can see the Debug output on a terminal window as shown in the prior section 2 Now go to the bottom right of your toolbar and find the Bluetooth symbol and select Add Device ms Add a Device Allow a Device to Connect Show Bluetooth Devices Join a Personal Area Network Open Settings Turn Adapter Off Customize 3 Ifyour Plugable dongle and WIDCOM Bluetooth drivers have installed correctly OR you are using WING you should see the hello sensor app show up after selecting Add a Device Select a device to add to this computer Windows will continue to look for new devices and display them here Hello b Bluetooth Other EMRF 20737S BOB V1 0 1 Page 10 Embedded Masters 4 After click on the Hello symbol your system will attempt to go find drivers for Hello There are no drivers for it so you could skip the driver installation search if you want 5 Now go back to SDK2 x x and find in the hello sensor folder the Windows gt Release folder Choose the appropriate folder x64 64bit OS or x86 32bit OS and click on the HelloClient exe 2 hello sensor 4 HelloClient amp Windows Release 2 x64 HelloClient exe amp x86 Z HelloClient exe bluetooth ico 6 You will now
4. 19 22 permission check retCode 00 hello_sensor_send_message wow NNN NNN t f hello sensor indication sent 0000 m o N N 48656c6c6f2031 SENSOR VALUE NOTIFY db pdu len 9007 o N N 9 22 12 eo oo e oo oo oo oo oo os oo oo o wW N N 19 22 40200e000a0004001b2a0048656c6c6f 19 22 2031 19 22 19 22 19 22 hello sensor send message InterruptHandler 19 22 INT But1 0 But2 But3 1 48656c6c6f2031 e wow NNN NNN b 10 709 permission check retCode 00 hello_sensor_send_message 9 22 hello sensor indication sent 0000 es oo m o N N 9 22 48656c6c6f2032 9 22 SENSOR VALUE NOTIFY db pdu len 0007 m o N N 19 22 12 Tx 19 22 40200e000a0004001b2a0048656c6c6f 19 22 2032 1 1 co oo oo oo oo m o N N 9 22 hello_sensor_send_message gt InterruptHandler 9 22 blecm evt handler 22 13050140000100 ee 9 22 blecm evt handler 19 22 13050140000100 89 19 23 hello sensor timeout 265 MUT EMRF 20737S BOB V1 0 1 Page 13 Embedded Masters B UUID HELLO SENSOR CONFIGURATION 1 Click the Read button under the title Hello Configuration Initially you will see 0 Characteristic Hello Input 8AC32D3F 5CB9 4D44 BEC2 EE689 169F626 ii Now type in a value such as 5 and click Write
5. number of alert for each interval mild alert num e number of alert for each interval status led enable 1 if 1 status LED is enable status led interval 1 second status led con blink 2 blink num of connection status led dir adv blink 0 blink num of dir adv status led un adv blink 2 blink num of undir adv EMRF 20737S BOB V1 0 1 Page 20 Embedded Masters Here we can define the time ON OFF of a LED that we can define later on led on ms 400 led blink on duration in ms led off ms 400 led blink off duration in ms Here we can define a buzzer duration if the system has one The EMRF 20737S BOB does not have a Buzzer so we can just leave this as 0 or you could set it to a value and view the PWM output on P28 pin39 buz on ms 0 buzzer on duration in ms button power timeout 0 seconds button client timeout 0 seconds button discover timeout 0 seconds button filter timeout 0 seconds ifdef BLE UART LOOPBACK TRACE button uart timeout 15 seconds endif 3 PUART and GPIO Configuration This next section we can define whether we want to enable the Peripheral UART PUART and or various GPIO settings that are defined in the Broadcom BTLE Stack The default values for these pins are defined in platform h which is in the include Platforms BCM920736TAG_Q32 folder as shown below The EMRF
6. You will see D1 blink 5 times iii Now if you hit PO again you will not only see the last digit increment in Hello X but you will also see the LED flash the same number of times that you wrote into the Characteristic Hello Configuration Select Allow Notifications in the drop down box then press the white button on the tag to receive a Hello message Characteristic Hello Input 8AC32D3F 5CB9 4D44 BEC2 EE689 169F626 vive Heel mes Characteristic Hello Configuration SE9BF 2A8 F93F 448 1 A6 7E 3B 2F4A0789 1A We are now done with hello_sensor App walk through Next we will code analysis for hello_sensor app EMRF 20737S BOB V1 0 1 Page 14 Embedded Masters Section 4 hello_sensor code analysis This firmware example is ALL Copyright 2013 Broadcom Corporation Now that we have seen what the hello sensor app does let s inspect the code to see how it all goes together 1 GATT Database Configuration The GATT Generic Attribute Profile database configures all the services and characteristics fora given BTLE application You can think of services as functions that handle particular data types and provide various functionality Many services are part of the BTv4 0 v4 1 spec and help comprise BTLE profiles Characteristics can be thought of as a description of the data variable value that is used in the service The GATT database is read by a client master during the connection
7. dasescdaeayedasbecsaiedoaneetish Eia ea aia aaa 21 A 22 5 25 23 6 HELLO SENSOR CONNECTION ertt Hei Ree He ER HB UR Rete oain EA OEE EEEa Si 25 7 SENSOR CONNECTION DOWN eren eene enne nnne nnne rnnt ea setas sese 27 8 SENSOR ADVERTISEMENT STOPPED KE KERN AERE 28 9 HELLO SENSOR TIMEOUT FINE TIMEOUT recientes tete E tee ie eee rein E 28 10 HELLO SENSOR SMP BOND tte reet 29 11 HELLO SENSOR ENCRYPTION CHANGED ra P REM 30 12 HELLO SENSOR SEND MESSAGE aids 32 13 SENSOR WRITE HANDEER 2 tie e eive eren 33 14 HELLO SENSOR INTERRUPT HANDLER 2 6 5 eren Rete a Ree
8. Embedded Masters 207375 1 3 x1 3 Breakout Board Description The 207375 is one of the world s smallest complete BTLE Modules at a mere 6 5x6 5mm It comes in a 48pin LGA package that can go through a typical solder reflow process It includes a complete BTLE Stack and a Cortex M3 running the show User is able to make use of a FREE SDK Software Development Kit that is based on Eclipse and a GCC compiler The SDK provides a simple Single Click Installer The SDK that supports the BCM20737S is SDK2 0 1 and beyond The most current SDK is 2 1 0 This BOB is compatible with the examples provided in the SDK and makes use of the same pin allocations as used in the examples The 207375 provides an ultra small Breakout Board that can either be used in your application or it can be used in place of the BCM92073x_LE_KIT commonly sold to support the 20736 207375 It comes with a TPS62740 ultra low Iq DC DC converter with up to 90 efficiency even with light loads down to 10uA The user has complete control over the output voltage of the DC DC via Resistor Jumpers on the bottom of the board ranging from 1 8 to 3 3V in increments of 100mV Default voltage is 3 0V The TPS62740 also has a second voltage output LOAD for sensors and other miscellaneous devices This is controlled via a CMOS GPIO pin CTRL which can be toggled HIGH LOW to turn ON OFF the secondary LOAD output Every useable GPIO is routed out to 2 54mm headers
9. end hello_sensor_send_message 13 hello sensor write handler This function processes all write commands from the client master to the peripheral slave Process write request or command from peer device NOTE LEGATTDB ENTRY HDR is defined in legattdb h int hello sensor write handler LEGATTDB ENTRY HDR p UINT8 writtenbyte The legattdb xxxx functions are defined in legattdb h UINT16 handle legattdb getHandle p int len legattdb_getAttrValueLen p UINT8 attrPtr legattdb getAttrValue p Again the EMRF 20737 does not have a Buzzer on it so you can either comment this line out or leave it in place and if you would like view the PWM output that is intended to drive the buzzer on P28 pin 39 do some noise bleprofile BUZBeep bleprofile p cfg buz on ms Here we are reading the client master BD Address to ensure it is the device we are actually paired to that is attempting to write to the peripheral slave make sure that it is the paired device which is trying to write read BDADDR of the paired device from the NVRAM and compare with connected bleprofile ReadNVRAM VS BLE HOST LIST sizeof hello sensor hostinfo UINT8 amp hello sensor hostinfo EMRF 20737S BOB V1 0 1 Page 33 Embedded Masters This is where we compare what is stored in the VS_BLE_HOST_LIST to what we have stored in the hello_sensor_remote_addr Since the BD Address is 6bytes 48bits we compare all 6bytes If the compare doesn
10. eng bei td sees 47 SECTION S CONEIGURE usto heec tos ps cuc sacas ute pa sess sa sese cha 49 i1HOW GPIO PORTS AREAGCCESSED Wiss 49 BEVISION HISTORY 5 tenet ieu ce aaa a MEI ce eee 50 207375 SCHEMATIC 51 207375 V1 0 1 Page 2 Embedded Masters Section 1 Program the BCM20737S To program the 207375 on the Breakout Board you will need an external USB UART FTDI device to connect to the SDK provided by Broadcom The 207375 accepts HCI3 0 commands from the SDK to program the EEPROM that is internal to the module The 207375 only needs a simple 2 Wire UART to be programmed and the lines being HCI RX and HCI TX Of course Power and GND are required also The steps to program are outlined below 1 Find your favorite USB UART device This is most likely going to be a FTDI 3 3V Cable FT232 234 Breakout board or you can actually even use an existing Broadcom BTLE TAG board if you happen to have one Some common FTDI devices that can be used are outlined in the Appendix A NOTE Check back soon Embedded Masters will be making their own FT234 based Breakout similar to that shown in the picture below 2 Connect the following lines of the FTDI device
11. Converting CGS to HEX Conversion complete Creating OTA images Conversion complete OTA image footprint in NV is 5035 bytes Downloading application Download complete Application running 18 38 49 Build Finished took 95 502 5 EMRF 20737S BOB V1 0 1 Page 4 Embedded Masters Section 2 Debug Output with 207375 In order to see the Debug Traces you need to simply disconnect the HCI_RX line from the FTDI TX line So simply disconnect the wire you have used to connect these two ports together The HCI_RX line is important to the BCM2073x family as it is Sampled upon every POR and RESET event by the BCM2073x and then determines whether the device should be in Programming Mode or in Application Mode The Modes are indicated below After a POR or RESET event HCI RX HIGH gt Device enters Programming Mode It may appear dead if you have programmed it once and then hit RST on the BOB as itis waiting for HCI 3 0 programming commands HCI_RX LOW gt Device enters Application Mode and begins executing program NOTE After each time the device has been programmed it will begin executing afterwards but if you hit the RST button or Re Apply Power it will go into either Programming Mode or Application Mode depending on whether HCI RX is HIGH or LOW Now with HCI RX explained we can get back to how to see the Debug Traces With the HCI RX line disconnected from FTDI Tx line and you have hit RST
12. has been defined as a readable value and the value can be up to 16bytes long If you wanted you could give your device a custom name by replacing the Hello with your own name that can be up to 16bytes long NOTE If you want to look at how the CHARACTERISTIC UUID16 function prototype looks you find the function definition in bleprofile h CHARACTERISTIC UUID16 0x0015 0x0016 UUID CHARACTERISTIC DEVICE NAME LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 16 H e 1 1 0 0x00 0x00 0x00 0x00 0x00 0x00 x00 Ox0O xO Ox0O OxOO This characteristic tells the device it is connecting to what kind of device itis A PC for example may show different symbols based on what the APPEARANCE is defined as There is a list of values for APPEARANCES in ble uuid h NOTE We have 2 handles defined here One for the UUID CHARACTERISTIC APPEARANCE and one for the Value of the APPEARANCE being APPEARANCE GENERIC TAG Handle 0x17 characteristic Appearance handle 0x18 characteristic value List of approved appearances is available at bluetooth org Current value is set to 0x200 Generic Tag CHARACTERISTIC UUID16 0x0017 0x0018 UUID CHARACTERISTIC APPEARANCE LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 2 BIT16 TO 8 APPEARANCE GENERIC TAG EMRF 20737S BOB V1 0 1 Page 16 Embedded Masters Now we define the actual custom service which is specified by a UUID128 since it is NOT a BT Sig defined service The
13. hello sensor connection up This is the callback function for when a connection gets established void hello sensor connection up void UINT8 writtenbyte UINT8 bda This function gets the handle value ofthe Client we have connected to hello sensor connection handle UINT16 emconinfo getConnHandle As the inline comment indicates we are retrieving the BD Address of the Client and make a copy save address of the connected device and print it out memcpy hello sensor remote UINT8 emconninfo getPeerAddr sizeof hello sensor remote Here we are just printing out the BD Address of the Client to the terminal window ble trace3 hello sensor connection up 408x404x d n hello sensor remote addr 5 lt lt 24 hello sensor remote 4 lt lt 16 hello sensor remote addr 3 lt lt 8 hello sensor remote addr 2 hello sensor remote addr 1 lt lt 8 hello sensor remote addr 0 hello sensor connection handle Since we have established a connection we can stop advertising so we stop adverstising Stop advertising bleprofile Discoverable NO DISCOVERABLE NULL We can also now stop the Connection Idle Timer Since we have it disabled in the BLE PROFILE CFG this really has no effect but in a real application you would want to have a Connection Idle timer enabled bleprofile StopConnIdleTimer EMRF 20737S BOB V1 0 1 Page 25 Embedded Masters As the inline comment i
14. t equal 0 we return and put out a Debug message indicating that it is the wrong host handle If not we print out the handle of the client master if memcmp hello sensor remote addr hello sensor hostinfo bdaddr 6 ble_trace1 hello_sensor_write_handler wrong host handle 4x n handle return 0 ble tracei hello sensor write handler handle 4x n handle Here we determine if what is being wrote to the peripheral slave is the HELLO SENSOR CLIENT CONFIGURATION DESCRIPTOR which is 2bytes If so the client master is writing to indicate it wants to receive Notifications 0x01 or Indications 0x02 len is defined above by int len legattdb getAttrvaluelen p By writing into Characteristic Client Configuration descriptor peer can enable or disable notification or indication if len 2 88 handle HANDLE_HELLO_SENSOR_CLIENT_CONFIGURATION_DESCRIPTOR hello sensor hostinfo characteristic client configuration attrPtr 0 attrPtr 1 8 ble tracei hello sensor write handler client configuration 04 hello sensor hostinfo characteristic client configuration If what is being wrote to peripheral slave from client master is not whether it wants to accept Notification Indications it will be to update the number of blinks which is the HELLO_SENSOR_CONFIGURATION NOTE This and the HELLO_SENSOR_CLIENT_CONFIGURATION_DESCRIPTOR are both defined in the GATT database at the begi
15. 20737S BOB makes use of the same Pushbutton and LED GPIO pins as are defined in the platform h There is an additional Pushbutton connected to P4 and an additional LED connected to P27 gt E Drivers amp include b amp Drivers Platforms 4 amp BCM920736TAG_Q32 8 platform h Here we can either enable or disable the PUART via the BTLE stack My recommendation is to Configure this manually if you want to use it as you have more control over how it is configured The PUART can also be used to output Debug messages Using the PUART and outputting Debug Messages will be discussed in a follow on document and a code example provided Following structure defines UART configuration const BLE_PROFILE_PUART_CFG hello_sensor_puart_cfg baudrate 115200 txpin PUARTDISABLE GPIO PIN UART TX rxpin PUARTDISABLE GPIO PIN UART RX EMRF 20737S BOB V1 0 1 Page 21 Embedded Masters Here we can define the WP pin for the EEPROM internal to the Module The WP pin definition should NOT be modified in the platform h file as it is internally connected to P1 There is no way to change this unless you are doing a discrete SOC design We also can define the default Pushbutton that will trigger an interrupt This is defined as PO in platform h Also defined here is the default LED which is defined as P14 You could modify the Button and LED definitions in platform h to make use of P4 for the button and P27
16. 34 12 Rx 4020090005000400122b000100 Checking readable attribute 002b permission check retCode 00 hello sensor write handler handle 002b hello sensor write handler client configuration 0001 hello sensor write handler NVRAM write 0009 l2cap Tx 402005000100040013 WriteCb handle 602b BUZBeep NNNNNNNNNNNNNNNNNNYN blecm evt handler 13050140000100 00 17 35 hello sensor timeout 154 ii Now click Read button on the GUI You will see Hello 0 being displayed iii To send updates to the PC app click on the PO Pushbutton You will see the last digit byte is being updated on every PO button press It will rollover after 9 back to 0 Service Hello Service Select Allow Notifications in the tag to receive a Hello message Characteristic 32D3F 5CB9 4D44 BEC2 FE689 169F626 Ve nes Characteristic Hello Configuration SE9BF 2A8 F93F 448 1 A67E 382F4A07891A _ then press the white button on the EMRF 20737S BOB V1 0 1 Page 12 Embedded Masters On every button press you will see something similar to below in the trace terminal window indicating that an Interrupt has occurred voLi 89 19 22 hello sensor timeout 264 00 19 22 00 19 22 INT But1 1 But2 0 But3 m o N N 48656c6c6f2030 oo NN NN
17. A few ofthe pins are connected to Pushbuttons or LEDs The user has the capability of making use of every usable GPIO since they are routed out to the edge connectors If the Pins that are connected to one of the Pushbuttons or LED s is desired to be used the user can depopulate these components and make use ofthe GPIO pins with basic soldering skills The only pin that is consumed is pin25 P1 which is internally connected to the EEPROM WP line and is connected to a pull up resistor to allow for an always known state during RESET or POR events Gerber files and PCB Footprints are available upon request For more information on the 207375 interested users need to register the Broadcom Community site at the following link to access the 207375 Technical Reference Manual Appnotes and associated information along with being able to download the SDK2 1 0 or Higher http community broadcom com welcome Features e VDD Supply voltage range of 1 62V 3 63V e 1 3 1 3 Breakout board that can be directly soldered into your application or be used for an ultra small evaluation system e 90 Efficient at 10uA up to 300mA Output Current DC DC Converter with Controllable Second LOAD output TPS62740 16 Selectable Output Voltage in 100mV steps from 1 8V to 3 3V e All Pins Broken Out to Standard 0 1 2 54mm Spaced Headers EMRF 20737S BOB V1 0 1 Page 1 Embedded Masters DESCRIPTION cc ea a E M E 1 FEAT URES
18. capabilities coming down the road in future SDK s Segger J LINK WICED Smart Forum Post How to use a Segger J LINK http community broadcom com community wiced smart wiced smart forums blog 2014 08 08 wiced smart jlink debugger So to debug we will make us of the ble_trace commands that have already been created for us We can search our project for ble_trace by doing CRTL F and typing ble_trace in the Find Replace window It is useful to take a look at the common ones that are used Some of the common ones are shown below To simply print out a Text String we use ble trace0 ble traceO0 hello sensor create To print out a single variable we use ble trace1 ble trace1 NVRAM write 4x n writtenbyte To print out 2 variables we use ble_trace2 ble trace2 hello sensor write handler bad write len d handle x x n len handle To print out 3 variables we use ble trace3 ble trace3 INT Buti 4d But2 d But3 d n value amp x 1 value amp 0x02 gt gt 1 value amp 0x04 2 To print out 4 variables we would use ble trace4 ble trace4 EncOn 08 04 client configuration 04x blinks d n hello sensor hostinfo bdaddr 5 lt lt 24 hello sensor hostinfo bdaddr 4 lt lt 16 hello sensor hostinfo bdaddr 3 lt lt 8 hello sensor hostinfo bdaddr 2 hello sensor hostinfo bdaddr 1 lt lt 8 hello sensor hostinfo bdaddr 0 hello sensor hostinfo characteristic client configuration hello
19. client wanted us to use indication instead of notifications we have to wait for confirmation after every message sent For example if user pushed button twice very fast we will send first message wait for confirmation send second message wait for confirmation and if configured start idle timer only after that void hello sensor indication cfm void If hello sensor indication sentis 0 it is not the correct ACK from client master as hello sensor indication sent would have been set to 1 TRUE in hello sensor send if hello sensor indication sent ble_trace Hello Wrong Confirmation return We now clear the hello_sensor_indication_sent variable as we have received the ACK back from the client host indicating that it has received the indication hello sensor indication sent 0 If there are still more indications to send go ahead and send them We might need to send more indications if hello sensor num to write 1 hello_sensor_num_to_write hello sensor send message Similar to before if hello_sensor_stay_connected is set to 0 and we have sent all the indicatations we will start the Connection Idle timer and disconnect after the specified time that the connection has been idle if we sent all messages start connection idle timer to disconnect if hello_sensor_stay_connected amp amp hello_sensor_indication_sent bleprofile_StartConnIdleTimer bleprofile_p_cfg gt
20. connection disc required e if 1 disconnection after confirmation test enable 1 TEST MODE is enabled when 1 Here is where we specify the output PA level It can be as high as 4dBm tx_power_level exeo dbm Here is where you could specify a time in seconds that if the connection is IDLE that the connection times out and disconnects For development purposes it is easier to just set this to 0 so it never times out con idle timeout e second 0 no timeout Here is where you can specify that if the system is IDLE for a time period in seconds that the device goes into a low power mode Personally I have found it is better to do this manually in the firmware We will cover how to do this in Section 7 and you will see firmware that allows this later in this section powersave timeout e second 0 gt no timeout hdi 0x00 0x0063 0x00 0x00 Ox00 HANDLE NUM MAX serv 0x00 UUID SERVICE BATTERY 0x00 0x00 0x00 cha 0x00 UUID CHARACTERISTIC BATTERY LEVEL 0x00 Ox00 findme locator enable 0 if 1 Find me locator is enable findme alert level 0 alert level of find me client grouptype enable 0 if 1 grouptype read be used linkloss button enable 0 if 1 linkloss button is enable pathloss check interval 0 second alert interval e interval of alert high alert num
21. eed re Meere pereas 35 15 HELLO SENSOR INDICATION GENI sosta cn tu ena Ax Eee sa Rute even quee Rand eioan 37 16 BLEPROFILE STARTCONNIDEETIMER 53 55 35551 eaae paa Pin EYE NE FL a BEATAE Fa RR NER ERR RR CERE FERRY ETE eak 38 17 BLEPROFILE STOPCONNIDLETIMER s sees seen ener ener nennen rns nenas earns teens earns itas sten aser reset asia 38 18 BLEPROFILE_SENDCONNPARAMUPDATEREQ eese eene enne nnne nnne nnn nenne erre nensi nn intense rase seen senes earn senes ena 38 SECTION 5 CREATE MY OWN PROJECT 6 1 itis ocn ks IF Robb S Fas Ca roses 39 SECTION 6 DEBUGGING niesie aiaa eaea sane cho ai Ted 46 SECTION 7 HOW TO SLEEP 47 CE Ee 47 B DEEP SLEEP iiec Ge OO ER EPOR HR BORED EE PARES ERIS RR GU or e ER
22. for the LED on the EMRF 20737S BOB The Flag definitions further down are simply flags that get checked in the inner workings of the BTLE stack NOTE have commented out the Battery and Buzzer definitions You could connect a battery to the system and feed the battery voltage into P15 if you so desire Following structure defines GPIO configuration used by the application const BLE_PROFILE_GPIO_CFG hello_sensor_gpio_cfg gpio_pin 1 GPIO PIN WP This need to be used to enable disable NVRAM write protect GPIO PIN BUTTON Button GPIO is configured to trigger either direction of interrupt GPIO PIN LED LED GPIO optional to provide visual effects 1 GPIO PIN BATTERY Battery monitoring GPIO When it is lower than particular level it will give notification to the application 1 GPIO PIN BUZZER Buzzer GPIO optional to provide audio effects 1 1 1 1 1 1 1 1 1 1 1 other GPIOs are not used gpio flag GPIO_SETTINGS_WP GPIO_SETTINGS_BUTTON GPIO_SETTINGS_LED 0 GPIO SETTINGS BATTERY 0 GPIO SETTINGS BUZZER 4 Application Init Just as it sounds we will initialize the system Note that here we are passing in a pointer to the Gatt Database we defined earlier i We define the size of the GATT Database ii We pass in a pointer to the BLE PROFILE CONFIG defined earlier iii We pass in a pointer to the Puart amp
23. incremented if you push the pushbutton Read value of the characteristic to send from the GATT DB bleprofile ReadHandle HANDLE HELLO SENSOR VALUE NOTIFY amp db pdu ble tracen char db pdu pdu db 1 Here we Logical AND the characteristic client configuration to determine if it is a Notification or if it is not it should be an Indication which is handled in the else part of the statement Note that the CCC NOTIFICATION is defined in bleprofile h and is defined as 0x01 whereas an Indication is defined as CCC INDICATION and is defined as 0x02 The bleprofile sendNotification and bleprofile sendIndication functions are defined also in bleprofile h if hello sensor hostinfo characteristic client configuration amp NOTIFICATION bleprofile sendNotification HANDLE HELLO SENSOR VALUE NOTIFY UINT8 db pdu pdu db 1 ble traceeO CCC Notification Sent n 207375 V1 0 1 Page 32 Embedded Masters else if hello_sensor_indication_sent hello_sensor_indication_sent TRUE ble_trace Hello_sens_indication_cfm sent n NOTE If it is an Indication there is a Callback function for the ACK Confirmation from the client master This function is detailed later in this document bleprofile sendIndication is defined in bleprofile h bleprofile sendIndication HANDLE HELLO SENSOR VALUE NOTIFY UINT8 db pdu pdu db pdu len hello sensor indication cfm
24. see the following GU Service Hello Service Select Allow Notifications in the drop down box then press the white button on the tag to receive a Hello message Characteristic Hello Input 8AC32D3F 5CB9 4D44 BEC2 EE689 169F626 vate Characteristic Hello Configuration SESBF 2A8 F93F 448 1 A67E 3B2F4A0789 14 Value Service Device Information Manufacturer Name Broadcom Model number 1234 System ID 93 b8 63 80 5f 9f 9171 Service Battery Battery Level 100 Connected 7 The GUI allows communication from the BTLE dongle to the EMRF board To make use of the GUI you can do the following A Indications Notifications CLIENT CONFIGURATION DESCRIPTOR i Select Allow Notifications or Allow Indications from the drop down menu Notifications Indications are messages that are sent from EMRF 20737S Slave to the PC Master In a real application these could be updates from a sensor or some other data that needs to be updated on say an iPhone or Android app HeloClent Service Hello Service Select Allow Notifications in the drop down box then button on the tag to receive a Hello message Characteristic Hello Input 8AC32D3F x 2 EE689169F626 vie Annette Characteristic Hello Configuration SE9BF2A8 F93F 448 1 A6 7E 3B2F4A0789 1A whee EMRF 20737S BOB V1 0 1 Page 11 In Embedded Masters the trace terminal window you will see the following indicating this has occurred 1 17
25. sensor hostinfo number of blinks Hopefully you are starting to see the pattern as to how many variables you want to print out and the ble traceX option you would use The ble traceX functions are defined in bleapp h We now move on to Section 7 How to SLEEP EMRF 20737S BOB V1 0 1 Page 46 Embedded Masters Section 7 How to SLEEP The BCM2073xS devices have 2 SLEEP Modes These modes are outlined below A SLEEP I typically refer to this mode as IDLE This mode is typically handled automatically by the underlying RTOS in which if there are no Tasks that are active it will automatically place the device into this mode to conserve power Clocks still active RAM is retained Fast Wake Up Handled automatically by RTOS B DEEP SLEEP This mode is similar to MCU s DEEP SLEEP modes in which they lose the RAM contents and go through a POR Re initialization of the system upon waking up This mode can be used if there will be relatively long interval between sending data or if the device is not in use 128KHz external 32KHz clocks can be active e RAM is not retained Wake up require going through POR Re Initialization e Can be woke up from either a GPIO Interrupt OR a Time Wake from either the 128KHz clock or the 32kHz clock Lowest Power Mode 1uA For this section we will only concern ourselves with DEEP SLEEP and only with using a GPIO Interrupt to wake the device We will cover the Timed Wake in either a
26. that has been configured as an interrupt such as the PO button Keep in mind PO is configured as an interrupt in platform h we are configured to stay connected disconnection was caused by the peer start low advertisements so that peer can connect when it wakes up if hello sensor stay connected bleprofile_Discoverable LOW_UNDIRECTED_DISCOVERABLE hello_sensor_hostinfo bdaddr ble trace2 ADV start 08 04 hello_sensor_hostinfo bdaddr 5 lt lt 24 hello_sensor_hostinfo bdaddr 4 lt lt 16 hello_sensor_hostinfo bdaddr 3 lt lt 8 hello_sensor_hostinfo bdaddr 2 hello_sensor_hostinfo bdaddr 1 lt lt 8 hello sensor hostinfo bdaddr 0 else ble traceO Entering DeepSleep Connection Lost in bleapputils delayUs 500 bleprofile PrepareHidOff end hello sensor connnection down EMRF 20737S BOB V1 0 1 Page 27 Embedded Masters 8 hello sensor advertisement stopped This is the callback function that gets called if there has not been a connection established after both the High and the Low Advertising Intervals have expired Keep in mind it is ONLY after BOTH the High and Low Advertising Intervals have expired that this callback will be called unless of course you only have one of them specified I have again added the capability to go into Deep Sleep if the hell sensor stay connected variable is set to 0 Otherwise we will start the Advertisements again voi
27. to the EMRF 20737S BOB NOTE The 207375 IS NOT 5V tolerant FTDI EMRF 20737S BOB 3 3 Power Vin input into DC DC regulator GND GND Tx HCI_RX Rx HCI TX 6 3 After you have done this you may want to very thorough and simply press the RST button 4 Now from the SDK simply click on your favorite Application Example Make Target button as shown below Let s try the hello_sensor App To compile and download this App simply double click on the Green Bullseye hello_client BCM920736TAG_Q32 download hello_sensor BCM920736TAG_Q32 download hello sensor BCM920736TAG Q32 recover hello sensor BCM920737TAG 032 download dp help GR ITRELIARLIIIIlIA lQ a BBC CERETAF VV BR EMRF 20737S BOB V1 0 1 Page 3 Embedded Masters 5 Now you should see in the Console Window that the App compiled the Device was found and the Download is Complete as shown below Sometimes the Detecting Device process can take a while You can speed this up by adding the COM port to the Make Target as shown below Um rdi TTIUTHLUITD CIVI2ZUZ DU FAM Nz UUWIIVGU hello client BCM920736TAG 032 download hello sensor BCM920736TAG 032 download hello sensor BCM920736TAG Q32 recover hello sensor BCM920737TAG 032 download UART COM6 help El Console 22 u Problems Search Debug CDT Build Console WICED Smart SDK Total RAM footprint 4609 bytes 4 5kiB
28. 0 40 26 Trace Decoding Error Could not find line number 314 00 40 26 UUID 2800 00 40 26 Attribute bytes 00 40 26 Handle 0062 00 40 26 Perm 0002 Len Max Len 0005 0005 UUID 2803 Attribute bytes Handle 0063 Perm 0002 Len Max Len 0001 0001 UUID 2A19 Attribute bytes Gatt DB Dump complete bd addr 5 2 20 73 18 bd addr 1 0 9877 ee GPIO 1 11 GPIO 0000 104 GPIO 0014 1003 00 40 26 GPIO 0015 20 00 40 26 GPIO 0028 2001 00 40 26 Interrupt mask 0 1 0001 0000 00 40 26 Interrupt mask 2 0000 00 40 26 GPIO_WP OFF 00 00 40 26 GPIOBTN1 0FF 1 INT 0 00 40 26 LED OFF 1 00 40 26 00 40 26 BUZ OFF O 00 40 26 Battery level 0 100 00 40 26 Fine Timer ms sec 00 40 26 Fine TImer tick 80 s ss ss oe ss os s ss ss ss I NNNNNNNNNNNNN DAAAAAAAAAAAAAAH SSSSSSSSSSSSSS 55555555555565 00 40 26 Normal Timer 1 s 80 tick 00 40 26 high un adv timer 0 00 40 26 hello sensor timeout 00 40 27 EMRF 20737S BOB V1 0 1 Page 6 Embedded Masters You could choose to not use the Trace inside of the SDK2 x x and use your own favorite terminal window but some of the data that will show on the terminal window will not have as much detail for the items that are printed from ROM Regardless to do so you would follow the instruction below Any terminal window Putty RealTerm TeraTerm will work and will have similar setup as
29. 100 500 msec with link supervision timeout 7 seconds bleprofile SendConnParamUpdateReq 80 400 0 700 end hello sensor encryption changed 12 hello sensor send message This function is called from hello sensor encryption changed hello sensor indication cfm and hello sensor interrupt handler This function sends out a message if the client has indicated it wants to receive Indications or Notifications In the case ofthe hello sensor app this would entail a button press but in a real world application this would involve some sort of data that needs to be updated to the client master if it has changed Check if client has registered for notification and indication and send message if appropriate void hello sensor send message void BLEPROFILE DB PDU db pdu Ifthe value for the characteristic client configuration is 0 it means that the client master has not registered told the peripheral slave that it wants to receive Notifications 1 or Indications 2 So we will simply return even if this function is called client has not registered for indication notification do not need to do anything if hello sensor hostinfo characteristic client configuration 0 return Here we are reading the value that has been stored into the HELLO CHARACTERISTIC NOTIFY and is what you would see being incremented from the Pushbutton which is the 7 byte of Hello X where X is 7 byte that gets
30. 4 Now we need to modify the makefile inc file so that it knows what files it needs to compile If you open the makefile inc now simply replace the hello_sensor c file with MyProject c or whatever you have renamed the files to as shown below makefile mk 23 Copyright 2014 Broadcom Corporation All Rights Reserved the contents of this file may not be disclosed to third parties copied or duplicated in any form in whole or in part without the prior This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation written permission of Broadcom Corporation Add Application sources here APP_SRC MyProject c dHHHHHHHHHHHHHHEHE DO NOT MODIFY FILE BELOW THIS LINE 5 One other thing we need to do is modify in MyProject c the header file name hello sensor h to MyProject h as shown below NOTE Make sure to Manually SAVE the file include bleprofile h include bleapp h include gpiodriver h include string h include stdio h include platform h include MyProject h include spar utils h 6 Now the last step is to create a Make Target bullseye for this project To do this we simply go over to the Make Target tab and copy one of the existing Make Targets and rename it to our own as shown below We can use the same hello sensor make target for this Update to SDK2 x x USC ITICLCT D CLIVI22U 7 2Z 1 AU 4 52 GOWN
31. 7 bit ASCII Wrap lines that exceed terminal width 4 Now click OK OK to get out of the ASII Setup and Properties Dialogue and connect to COM port You will start seeing Debug Messages being printed out to the Terminal window as such You may want to press RST on the EMRF board to start from the beginning Note you will see the printout from ROM a bunch of numbers without any indication as to what it is Regardless any Debug messages you put in your firmware will print out correctly You will see the following File Edit View Call Transfer Help De DB ES blecm evt handler 0e04010a2000 a HOA4FFFGF70092011E0300C1E804640000008003BR818002800008003BE10000000008003RE1R62 0000008003B210020000008003B618050005008003B8180032800008003BE10000000008003RE1863 0000008003B210020000008003B618010001008003BR181928000008003BE10000000008003DR1800 000000000 740051868 7320000 74E05 7 7980000000 7820611000100000 7820604010000000 7820603 100E000007820620000F 00000 7820601201C00000 7920 700000100000 7060 700000000000 7D20 700 000000000 7100801000000000 78800801000000000 7EE0 700000000000 712080000000000E54 90B00 000000000 736200100E8038 104FF1EF 70092010300000 73A828050000000000 75228500001000007 021F01000000hello sensor timeout 0 EMRF 20737S BOB V1 0 1 Page 8 Embedded Masters You have now successfully programme
32. 737S BOB V1 0 1 Page 39 Embedded Masters 3 You will now see the following dialog appear Enter a new name for hello sensor Copy of hello sensor We just need to rename the project to our own name such as MyProject It will place a copy of the hell sensor folder into a folder MyProject as shown below 4 amp MyProject gt E HelloClient 8 hello sensor c hello sensor h makefile inc At this point I would recommend renaming the files so that you don t get confused which ones you are actually working on as you make changes You could do this in Windows Explorer by going to the SDK2 x x install directory and finding the folder in the Apps directory or simply open the files and go to the main Menu bar and choosing File gt Save As and rename them to whatever you would like have renamed them MyProject c and MyProject h as shown below 4 MyProject gt gt HelloClient makefile inc 8 MyProject c 8 MyProject h NOTE If you modify the names in Windows Explorer and come back to Eclipse you may need to do a Refresh of the directory to have the files show up You can do this by either hitting F5 or by right clicking on the MyProject folder and selecting Refresh New Go Into Copy Ctrl C Paste Ctrl V Delete Delete 5 Remove from Context Ctrl Alt Shift Down Move Rename F2 gg Import pA Export Refresh N F5 EMRF 20737S BOB V1 0 1 Page 40 Embedded Masters
33. DEVICE INFORMATION Here we are simply defining the Characteristic of the Device Information in which we providing a manufacturer name being Broadcom NOTE This is where you would define your own company name Ensure you define it with enough bytes to completely store the name you want Handle 4 characteristic Manufacturer Name handle x4f characteristic value CHARACTERISTIC UUID16 0x004e 0x004f UUID CHARACTERISTIC MANUFACTURER NAME STRING LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 8 we are simply using another defined value which is the Model number For your own product you would provide a rev product ID or something that indicates what the product model is Handle 0x50 characteristic Model Number handle 0x51 characteristic value CHARACTERISTIC UUID16 0x0050 0x0051 UUID CHARACTERISTIC MODEL NUMBER STRING LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 8 1 2 3 4 0x00 0x00 0x00 0x00 Here we are defining the SYSTEM ID The SYSTEM ID is a BT Sig defined value which is a 64bit value The 64bit value is broken into a 40bit manufacturer defined identifier concatenated with a 24bit unique Organizationally Unique Identifier OUI The OUI is issued by the IEEE Registration Authority and is required to be used in accordance with IEEE Standard 802 2001 6 while the last 40bits Are manufacturer defined http standards ieee org regauth index html Handle 0x52 char
34. GPIO config structures we just defined iv Last thing we do is we call hello sensor create function Application initialization APPLICATION INIT bleapp set cfg UINT8 hello sensor gatt database sizeof hello sensor gatt database void amp hello sensor cfg void amp hello sensor puart cfg void amp hello sensor gpio cfg hello sensor create EMRF 20737S BOB V1 0 1 Page 22 Embedded Masters 5 hello sensor create This is where were we continue the system initialization and setup our callback functions we want to make use of void hello_sensor_create void Here we instantiate a BLE Profile Database PDU Protocol Data Unit for use later BLEPROFILE DB PDU db pdu extern UINT32 blecm configFlag blecm configFlag BLECM DBGUART LOG ble traceO hello sensor create ble traceO bleprofile p cfg ver Here we output the entire GATT Database This is what you see when you RESET the device and see all the values initially being printed out to the terminal window In SDK2 0 1 there are better descriptions of what these values are related to compared to SDK1 1 which supports the BCM20732 BCM207328 dump the database to debug uart legattdb dumpDb We now initialize the BLE PROFILE structure that we define earlier and below that we initialize the GPIO settings we defined earlier These functions are defined in bleprofile h bleprofile Init bleprofile p cfg bleprofile GPIOInit blepr
35. Handle and Service are defined in hello_sensor h You may be asking how does one define this 128bit UUID Well there is not really a defined way to do this There are some pretty slick online applications that can do this for you such as the one from the link below http www guidgenerator com Handle x28 Hello Service This is the main proprietary service of Hello Sensor It has 2 characteristics One will be used to send notification s to the paired client when button is pushed another is a configuration of the device The only thing which can be configured is number of times to send notification Note that UUID of the vendor specific service is 16 bytes unlike standard Bluetooth UUIDs which are 2 bytes UUID128 version of the macro should be used PRIMARY SERVICE UUID128 HANDLE HELLO SENSOR SERVICE UUID UUID HELLO SERVICE Now we are going to define a UUID128 characteristic that will be passed during a Notification or an Indication Note that the Characteristic is Readable and is a 7byte value We will see later how this value gets updated in the application the button press The difference between a Notification and an Indication is that an Indication requires a response from the client master as confirmation that it has received the message In this App the user selects whether it is a Notification or Indication via the PC GUI drop down menu Indications Notifications are quite useful as they allow the s
36. HyperTerminal which is shown below 1 Configure the COM port to ae 8 N 1 shown below EMRF 20732S BOB Properties Port Settings Bits per second 115200 Z Data bits 8 X Parity None X Stop bits 1 Flow control None 2 In Hyperterminal go to the Settings Tab and press the ASII Setup button i Function arrow and ctr keys act as Teminal keys Windows keys Backspace key sends Del Cri H Space Emulation Terminal Setup Telnet terminal ID ANSI Backscroll buffer ines 500 ES Play sound when connecting or disconnecting EMRF 20737S BOB V1 0 1 Page 7 Embedded Masters 3 Then check the box next to Append line feeds to incoming line ends as shown below This will ensure that you see all the lines that are being printed out of the device If this is not checked some of the ble_trace debug statements in ROM do not have a line feed at the end of the print statement so they will get written on top of each other Other terminal windows have a similar function to enable this EMRF 20732S BOB Properties 101 25 ASCII Sending Send line ends with line feeds i Echo typed characters locally Line delay 0 milliseconds Character delay 0 milliseconds ing Append line feeds to incoming line ends Force incoming data to
37. VRAM is defined in bleprofile h The ReadNVRAM function has the following input parameters UINTS8 ID number of NVRAM 0 0x6F VS BLE HOST LIST 0x70 UINTS8 itemLength sizeof hello_sensor_hostinfo UINTS8 payload amp hello_sensor_hostinfo Connection has been encrypted meaning that we have correct paired device restore values in the database bleprofile ReadNVRAM VS BLE HOST LIST sizeof hello_sensor_hostinfo UINT8 amp hello sensor hostinfo Here we are loading the client configuration into a PDU packet and then later writing it into the descriptor value This value determines whether or not Notifications or Indications have been enabled by the Client Master Need to setup value of Client Configuration descriptor in our database because peer might decide to read and stack sends answer without asking application db pdu len 2 db pdu pdu 0 hello sensor hostinfo characteristic client configuration amp Oxff db pdu pdu 1 hello sensor hostinfo characteristic client configuration gt gt 8 amp Oxff Here we are updating the GATT database for the handle specified as HANDLE HELLO SENSOR CLIENT CONFIGURATION DESCRIPTOR The bleprofile WriteHandle function is defined in bleprofile h This function provides a means for the application to write to the GATT database bleprofile WriteHandle HANDLE HELLO SENSOR CLIENT CONFIGURATION DESCRIPTOR amp db pdu EMRF 20737S BOB V1 0 1 Page 30 Embedded Maste
38. _sensor_connection_handle is therefore not 0 We can now send the Notifications or Indications to the client master Keep in mind indications require an ACK from the client master The hello_sensor_indication_sent variable is set in the hello_sensor_send_message function and is cleared in the hello sensor indication cfm function Connection is up Send message if client is registered to receive indication or notification After we sent an indication we need to wait for the ack before we can send anything else while hello sensor num to write 0 amp amp hello sensor indication sent hello sensor num to write hello sensor send message EMRF 20737S BOB V1 0 1 Page 36 Embedded Masters If hello_sensor_stay_connected is set to 0 and we have sent all the messages we will start the Connection Idle Timer to disconnect after the specified time if we sent all messages start connection idle timer to disconnect if hello_sensor_stay_connected amp amp hello_sensor_indication_sent bleprofile StartConnIdleTimer bleprofile p cfg con idle timeout bleprofile appTimerCb end hello sensor interrupt handler 15 hello sensor indication cfm This is the callback function indicated from the function bleprofile sendIndication which is in hello sensor send message This is the callback for ACK from the client master when an indication is sent out process indication confirmation If
39. acteristic System ID handle 0x53 characteristic value CHARACTERISTIC UUID16 0x0052 0x0053 UUID CHARACTERISTIC SYSTEM ID LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 8 0x93 0xb8 0x63 0x80 0x5f 0x9f 0x91 0x71 EMRF 20737S BOB V1 0 1 Page 18 Embedded Masters Here we are defining a BTLE Standard service which is to monitor the battery level Handle 0x61 Battery service This is an optional service which allows peer to read current battery level PRIMARY SERVICE UUID16 0x0061 UUID SERVICE BATTERY Here we are simply defining the Characteristics of the Battery Service itself NOTE It is 1 byte Handle 0x62 characteristic Battery Level handle 0x63 characteristic value CHARACTERISTIC UUID16 0x0062 0x0063 UUID CHARACTERISTIC BATTERY LEVEL LEGATTDB CHAR PROP READ LEGATTDB PERM READABLE 1 0x64 HN 2 BLE PROFILE CFG Stack Configuration This structure defines how the Broadcom BTLE Stack gets initialized We will go through the most important items here const BLE PROFILE CFG hello sensor cfg Here we define the fine_timer_interval Think of this as your fast application system tick fine_timer_interval 250 ms Here we are simply defining that the Advertising be UNDIRECTED_DISCOVERABLE This simply means that any BTLE device can see the advertisements and Discover or connect to it There are several types of Advertisements that one can use For example if you know the Device
40. at you can have multiple 2073755 plugged into the PC or to speed up the download process so SDK does not have to search through the COM Ports This will dictate which one gets programmed You have already seen examples of directly specifying the COM port in prior sections That wraps it up for a quick overview of How to Create Your Own Project We will move on to Section 6 Debugging Techniques EMRF 20737S BOB V1 0 1 Page 45 Embedded Masters Section 6 Debugging Techniques Currently the only means to debug the BCM2073x BCM2073XxS devices is to place printf like commands in firmware The device does have SWD capability but it is currently only supported with a Keil RealView which costs 5000 Luckily the BTLE Stack and Peripheral API functions are already done for us so we can still do some pretty cool things without needing a sophisticated debugger You can use a Segger J LINK SWD A link from the forums has been provided below Keep in mind on these devices you have 30KB of RAM code space available for your application This may seem small but you need to keep in mind that the entire BTLE Stack and Peripheral API s are already programmed in ROM The of RAM can truly be set aside for Dynamic Data or your own custom functions as we don t need to spend any of this available space for Peripheral Initialization functions Peripheral handlers or BTLE Function calls It has been indicated that there are some better Debug
41. ce the secure connection has started hello sensor encryption changed NULL end hello sensor connection up EMRF 20737S BOB V1 0 1 Page 26 Embedded Masters 7 hello sensor connection down This is the callback function for when the connection is closed or lost The user is to decide whether to attempt to start advertising again to reconnect or to do something else such as possibly go into a Low Power Mode I have added some code to go into Deep Sleep if the variable hello_sensor_stay_connected is not set void hello_sensor_connection_down void Here we are just printing out to the terminal window the address and handle of the client that we lost the connection to ble_trace3 hello_sensor_connection_down 08x 04x handle d n hello_sensor_remote_addr 5 lt lt 24 hello_sensor_remote_addr 4 lt lt 16 hello_sensor_remote_addr 3 lt lt 8 hello_sensor_remote_addr 2 hello sensor remote addr 1 lt lt 8 hello sensor remote addr 0 hello sensor connection handle Here we are clearing the BD Address ofthe client and clearing the handle value since the connection was lost memset hello sensor remote 6 hello sensor connection handle 0 This section will either restart the Advertising to try and re connect OR if the hello sensor stay connected variable is set to 0 we go into Deep Sleep at just over 1uA at 1 8V and a bit higher at higher voltages The device can be woken up by any GPIO
42. con_idle_timeout bleprofile appTimerCb end hello_sensor_indication_cfm EMRF 20737S BOB V1 0 1 Page 37 Embedded Masters 16 bleprofile StartConnIdleTimer This function stops the Connection Idle timer This function would be called if we have set the hello_sensor_stay_connected variable to 0 Start connection idle timer if it is not running void bleprofile StartConnIdleTimer UINT8 timeout BLEAPP TIMER CB cb if emconinfo getAppTimerId 0 emconinfo_setIdleConnTimeout timeout blecm_startConnIdleTimer ble_trace1 profile idletimer d timeout end bleprofile StartConnIdleTimer 17 bleprofile StopConnIdleTimer 18 This function stops the Connection Idle timer This function would be called if we have set the hello sensor stay connected variable to 0 This function is called in hello sensor connection up Stop connection idle timer if it is running void bleprofile StopConnIdleTimer void if emconinfo getAppTimerId 0 blecm stopConnIdleTimer emconinfo setAppTimerId 1 ble tracee profile idletimer stopped end bleprofile StopConnIdleTimer bleprofile SendConnParamUpdateReq This function sends updated Connection parameters to the client master Send request to client to update connection parameters void bleprofile SendConnParamUpdateReq UINT16 minInterval UINT16 maxInterval UINT16 slaveLatency UINT16 timeout if minInt
43. ctively Not _WRITABLE in the macro This means that attribute can be written by the peer CHAR DESCRIPTOR UUID16 WRITABLE HANDLE HELLO SENSOR CLIENT CONFIGURATION DESCRIPTOR UUID DESCRIPTOR CLIENT CHARACTERISTIC CONFIGURATION LEGATTDB PERM READABLE LEGATTDB PERM WRITE REQ 2 0x00 0x00 EMRF 20737S BOB V1 0 1 Page 17 Embedded Masters Here we are simply defining a Characteristic that stores the value for how many Notifications or Indications will be sent after a button press NOTE it is a single byte Handle x2c characteristic Hello Configuration handle x2d characteristic value The configuration consists of 1 bytes which indicates how many notifications or indications to send when user pushes the button CHARACTERISTIC UUID128 WRITABLE 0x002c HANDLE HELLO SENSOR CONFIGURATION UUID HELLO CHARACTERISTIC CONFIG LEGATTDB CHAR PROP READ LEGATTDB CHAR PROP WRITE LEGATTDB PERM READABLE LEGATTDB PERM WRITE CMD LEGATTDB PERM WRITE REQ 1 0x00 Here we are defining a standard BT defined service which provides the Device Information Handle x4d Device Info service Device Information service helps peer to identify manufacture or vendor of the device It is required for some types of the devices for example HID and medical and optional for others There are a bunch of characteristics available out of which Hello Sensor implements 3 PRIMARY SERVICE UUID16 0x004d UUID SERVICE
44. d MyProject BCM920736TAG Q32 rom ram Wiced release A 20736A1 MyProj ect rom ram spar cgs MDS sum is c348f20b382c2c3b3c7146f0028deef7 build MyProject BCM920736TAG Q32 rom ram Wiced release A 20736A1 MyProject rom ram spar cgs Patches start at 204568 RAM address Patches end at 2 528 RAM address Application starts at 9 00204 9 RAM address Application ends at 2 5050 RAM address Patch size including reused RAM 3352 bytes Patch size 2612 bytes Application size 3521 bytes Total RAM footprint 6133 bytes 6 0kiB Converting CGS to HEX Conversion complete Creating OTA images Conversion complete OTA image footprint in NV is 6565 bytes Downloading application Download complete Move DIP switch 2 of SW4 to off position and push Reset button to start application 22 43 32 Build Finished took 10s 403ms Note that it indicates the application is Running which is true BUT remember if we want to see Debug Messages on a Terminal Window we need to disconnect the HCI RX line from the FTDI USB TX line so that the HCI RX line drops low and we press RST on the 207375 to put the 207375 in Application mode We can now see output on the Terminal Window and we can RESET the device as much as we would like and it will stay in Application Mode If you want to Re Program the device just Reconnect the HCI RX line to the FTDI USB UART TX line and Hit RST on the 207375 and th
45. d hello_sensor_advertisement_stopped void ble_trace ADV stop n If we are configured to stay connected disconnection was caused by the peer start low advertisements so that peer can connect when it wakes up if hello_sensor_stay_connected bleprofile_Discoverable LOW_UNDIRECTED_DISCOVERABLE hello_sensor_hostinfo bdaddr ble trace2 ADV start 08 04 hello_sensor_hostinfo bdaddr 5 lt lt 24 hello_sensor_hostinfo bdaddr 4 lt lt 16 hello_sensor_hostinfo bdaddr 3 lt lt 8 hello sensor hostinfo bdaddr 2 hello_sensor_hostinfo bdaddr 1 lt lt 8 hello sensor hostinfo bdaddr 0 else ble traceO Entering DeepSleep AdvStopped n bleapputils delayUs 5 bleprofile Discoverable NO DISCOVERABLE NULL bleprofile PrepareHidOff Puts device into DeepSleep 1 33uA 9 hello sensor timeout fine timeout These are the callback functions for the fine timer and the 1 second tick timer Keep in mind the fine_timer timeout value is set in the BLE_PROFILE_CFG structure The fine timer can be configured for 12ms to 1sec timeout Anything greater than 1000 will result in effectively in a 1 second timeout void hello_sensor_timeout UINT32 arg ble_trace1 hello_sensor_timeout d n hello_sensor_timer_count switch arg case BLEPROFILE_GENERIC_APP_TIMER hello_sensor_timer_count break EMRF 20737S BOB V1 0 1 Page 28 10 Embed
46. d the 207375 and enabled the Debug output Now let s touch on a few more details as outlined below Section 3 hello_sensor Walk Through Section 4 hello_sensor Code Analysis Section 5 How create my own project Section 6 Debugging Techniques Section 7 How To Sleep Section 8 How configure GPIO These topics will be covered in the next sections Embedded Masters will be creating additional documents that will explain even further details of the BCM20732S BCM20736S and BCM20737S modules One of the really cool things about these modules is they are all 100 pin compatible EMRF 20737S BOB V1 0 1 Page 9 Embedded Masters Section 3 hello_sensor Walk Through What does this App Do First to fully utilize the hello_sensor app you will want a PC that you can connect to a BTLE device WIN8 already has this built in If you have WIN7 or XP don t worry you can get a 13 USB dongle from Plugable and this will update your WIN7 or XP machine to have BTLE capability The link to purchase this dongle and download the drivers for it is provided below Plugable USB Bluetooth 4 0 Low Energy Micro Adapter Windows 8 7 XP Linux Compatible Classic Blue tooth and Stere Buy Now 12 95 http plugable com products usb bt4le Once you have one of these and you have installed the drivers you will be ready to follow along Assuming you have followed the steps in the Intro section and have programmed the
47. ded Masters NOTE We are using the fine_timer to check the Pushbutton defined in the BLE_PROFILE_CFG and platform h void hello sensor fine timeout UINT32 arg hello_sensor_fine_timer_count If you want to see the output of this timer you can put this line of code in your hello_sensor example ble_trace1 hello_sensor_fine_timeout d hello sensor fine timer count button control bleprofile ReadButton hello sensor smp bond result This callback function is setup in the hello_sensor_create function and is called during the bonding process If the bonding pairing is successful we store Client Master s BD Address in EEPROM and we initialize the hello_sensor_hostinfo structure mentioned earlier void hello sensor smp bond result LESMP PARING RESULT result ble_trace1 hello_sample bond result 2x n result On the EMRF 20737S BOB you could comment this line out as we don t have a buzzer or if you want to look at the signal you can ensure the Buzzer is defined in platform h and ensure it gets defined in the BLE_PROFILE_GPIO_CFG structure The default Port if P28 pin39 as defined in platform h You could choose a different PWM pin also if you like If you have a scope you will see a PWM waveform on P28 pin39 do some noise bleprofile BUZBeep bleprofile p cfg buz on ms LESMP PAIRING RESULT BONDEDis typedef enum and is defined in lesmp h if result LESMP PAIRING RESULT BONDED sa
48. e device will be back in Programming Mode EMRF 20737S BOB V1 0 1 Page 43 Embedded Masters 9 There are times when you may want to have additional output or commands sent to the make exe executable There are additional command line options that can be placed in your Make Target that are defined in Makefile located in the same directory as the make exe This file is shown below Contents of Makefile The entire file is not shown but you can view open it yourself This file is found in the Main WICED Smart SDK Project Directory as shown below wo gt amp Wiced Smart cproject Xj project CHANGELOG tt com port bxt LICENSE b make make exe L Makefile 11 12MAKEFILE TARGETS help download debug recover clean 13 14 include SOURCE ROOT wiced toolchain common mk 15 16 17 PHONY MAKEFILE TARGETS 18 19 BASE LOCATIONS 20 LOCATIONS BASErom BASEram BASEflash SPARrom SPARram SPARflash 21 TOOLCHAINS RealView Wiced CodeSourcery 22 BUILD_TYPE_LIST debug release 23 24 define USAGE TEXT 25 26 Usage make target download debug recover UART yyyy JOBS x PLATFORM NV EEPROM SFLASH 27 make run 28 29 target 3e One each of the following mandatory and optional components separated by 31 Application Apps in sub directories are referenced by subdir appname 32 Hardware Platform filter out common include README txt notdir wi
49. e fine timer fast timer and 1sec default timer We then start the timers After the ble profileStartTimer is called you will start seeing the Timer printouts on the terminal window bleprofile regTimerCb hello sensor fine timeout hello sensor timeout bleprofile StartTimer The next section starts the advertisements This will be covered in more detail in a future Appnote using the Beacon example that is in SDK2 0 1 and beyond which supports the 207365 and 207375 Read value of the service from GATT bleprofile ReadHandle HANDLE HELLO SENSOR SERVICE UUID amp db pdu ble tracen char db pdu pdu db 1 if db pdu len 16 ble_trace1 hello_sensor bad service UUID len d n db 1 else BLE_ADV_FIELD adv 3 flags adv len 1 1 adv 0 val ADV FLAGS EMRF 20737S BOB V1 0 1 Page 24 Embedded Masters adv data LE LIMITED DISCOVERABLE BR NOT SUPPORTED adv 1 len 16 1 adv 1 val ADV_SERVICE_UUID128_COMP memcpy adv 1 data db_pdu pdu 16 name adv 2 len strlen bleprofile_p_cfg gt local_name 1 adv 2 val ADV_LOCAL_NAME_COMP memcpy adv 2 data bleprofile_p_cfg gt local_name adv 2 len 1 bleprofile_GenerateADVData adv 3 blecm_setTxPowerInADV bleprofile_Discoverable HIGH_UNDIRECTED_DISCOVERABLE hello_sensor_remote_addr ble_trace end AppInit Xn end hello sensor create 6
50. ed as a callback in the hello sensor create function Three Interrupt inputs Buttons can be handled here the following value 1 Button is pressed Different than initial value the following value 0 Button is depressed Same as initial value Button1 value amp xe1 Button2 value amp 0x02 1 Button3 value amp 0x04 2 void hello sensor interrupt handler UINT8 value BLEPROFILE_DB_PDU db_pdu Determine which button that was configured was pressed ble_trace3 INT But1 d But2 d But3 d n value amp x 1 value amp 0x02 gt gt 1 value amp 0x04 gt gt 2 Blink the stored number of blinks Blink as configured bleprofile LEDBlink 250 250 hello sensor hostinfo number of blinks ble traceO LED Blink interrupt handlerin EMRF 20737S BOB V1 0 1 Page 35 Embedded Masters Here we store the amount of button presses in the last byte of Hello X You can see that we are incrementing 79 byte of the array H T 1 0 If the last byte is greater than 9 we reset to 0 So in the hello_sensor GUI you see Hello X increment from 0 9 and then rollover to 0 again After the last byte is incremented it is Stored back into the HELLO SENSOR VALUE NOTIFY via the bleprofile WriteHandle function keep number of the button pushes in the last byte of the Hello d message That will guarantee that if client reads it it wi
51. elds the Following definitions that can be defined There will be a GPIO Test c file that will be available on www embeddedmasters com that you can make use of define GPIO define GPIO P1 define GPIO P2 0 Port 0 1 2 define GPIO P3 3 4 8 EEPROM WP Pin Be Careful define GPIO P4 define GPIO P8 define GPIO P11 11 define GPIO P12 12 define GPIO P13 13 Dual Bonded with P28 define GPIO P14 14 Dual Bonded with P38 define GPIO P15 15 Port 0 EMRF 20737S BOB V1 0 1 Page 49 Embedded Masters define GPIO P24 8 1 define GPIO P25 9 Port 1 define GPIO P26 10 Port 1 define GPIO P27 11 Port 1 define GPIO P28 12 Port 1 Dual Bonded with P13 define GPIO P32 Port 2 define GPIO_P33 1 Port 2 define GPIO P38 6 2 Dual Bonded with P14 It may also make sense to create a more meaningful name for the individual ports as shown below define GPIO PORTO 0 define GPIO PORT1 1 define GPIO PORT2 2 So now using these defines we can easily make use of a GPIO function GPIO functions are defined in the Drivers folder in the SDK and in particular in gpiodriver h gpio configurePin GPIO PORTO GPIO GPIO OUTPUT ENABLE GPIO HIGH gpio configurePin GPIO PORTO GPIO P1 GPIO OUTPUT ENABLE GPIO HIGH gpio configurePin GPIO PORTO GPIO P2 GPIO OUTPUT ENABLE GPIO HIGH gpio configurePin GPIO PORTO GPIO P3 GPIO OUTPUT ENABLE GPIO HIGH gpio configurePi
52. erval gt maxInterval return lelZcap sendConnParamUpdateReq is defined in lel2cap h lel2cap sendConnParamUpdateReq minInterval maxInterval slaveLatency timeout EMRF 20737S BOB V1 0 1 Page 38 Embedded Masters Section 5 Create my own Project This section will give you a quick overview of how you can create your own project The easiest way to start is to simply copy one of the existing projects and then you can modify the files and or add your own files This example will make use of the same hello_sensor App we have learned about and copy it to our own project directory so we can start on our own firmware development 1 First we start out by simply copying the hello sensor project directory and paste it into a new directory in Eclipse as shown below To do this simply right click on the hello sensor folder and choose copy aue nicer 800 New Go Into Copy Ctrl C Paste Ctrl V Delete Delete Remove from Context Ctrl Alt Shift Down Move Rename F2 g Import 2 Now goto the top of the APPS folder and right click and then choose paste ST OL RR m gt Project Explorer 23 vn 4 gt Apps b adwp power receiver b adwp power transmitter antamatinn in Copy Ctrl C B Paste N Ctrl V Delete Delete 5 Remove from Context Ctrl Alt Shift Down Move Rename F2 EMRF 20
53. ke this but probably with a different COM Port being assigned 8 mybeacon BCM920736TAG Q32 download MyProject BCM920737TAG 932 download UART COM6 e MyProject BCM920737TAG_Q32 recover UART COM6 t Aas 6 If everything went according to plan you will see the following output on the Console Window E Console 5 Problems 47 Search 3 Debug 1 B bi mE CDT Build Console WICED Smart SDK OK made C Broadcom WICED BTLE SDK2 1 0 WICED Smart SDK Wiced Smart spar build MyProject BCM920736TAG Q32 rom ram Wiced release A 20736A1 MyProj ect rom ram spar cgs MD5 sum is c348f20b382c2c3b3c7146f0028deef7 build MyProject BCM920736TAG Q32 rom ram Wiced release A 20736A1 MyProject rom ram spar cgs Patches start at 0x00204568 RAM address Patches end at 9 00205280 RAM address Application starts at x00204F9C RAM address Application ends at 00205050 RAM address Patch size including reused RAM 3352 bytes Patch size 2612 bytes Application size 3521 bytes Total RAM footprint 6133 bytes 6 0kiB Converting CGS to HEX Conversion complete Creating OTA images Conversion complete OTA image footprint in NV is 6565 bytes Recovering platform Recovery complete Move DIP switch 2 of 504 to off position and push Reset button to start application 23 08 59 Build Finished took 105 375ms NOTE Another reason you may want to manually specify the COM port is so th
54. lave server to update the master client when a new measurement has been taken or the value has been updated somehow versus having to have the master client continually poll the slave Handle 0x29 characteristic Hello Notification handle x2a characteristic value we support both notification and indication Peer need to allow notifications or indications by writing in the Characteristic Client Configuration Descriptor see handle 2b below Note that UUID of the vendor specific characteristic is 16 bytes unlike standard Bluetooth UUIDs which are 2 bytes X UUID128 version of the macro should be used CHARACTERISTIC UUID128 0x0029 HANDLE HELLO SENSOR VALUE NOTIFY UUID HELLO CHARACTERISTIC NOTIFY LEGATTDB CHAR PROP READ LEGATTDB CHAR PROP NOTIFY LEGATTDB CHAR PROP INDICATE LEGATTDB PERM READABLE 7 Ho en 7 1 1 0 We are now creating a Descriptor for client master to indicate whether it shall receive Indications or Notifications Note this is defined as a 2byte value as described in the comments below https developer bluetooth org gatt descriptors Pages DescriptorViewer aspx u org blueto oth descriptor gatt client characteristic configuration xml Handle 0x2b Characteristic Client Configuration Descriptor This is standard GATT characteristic descriptor 2 byte value 0 means that message to the client is disabled Peer can write value 1 or 2 to enable notifications or indications respe
55. ldcard Wiced Platform 33 BASE location BASE LOCATIONS w SPAR location SPAR LOCATIONS Toolchain TOOLCHAINS w 37 download 38 Download firmware image to target platform 39 40 debug 41 Connect to the target platform and run the debugger 42 43 recover 44 Recover a corrupted target platform 45 46 VERBOSE 1 47 Shows the commands as they are being executed 48 49 2085 50 Sets the maximum number of parallel build threads default 4 51 52 UART yyyy 53 Use the uart specified here instead of trying to detect the Wiced Smart device 54 This is useful when you are working on multiple smart devices simultaneously 207375 V1 0 1 Page 44 Embedded Masters For example there is there rare scenario when the internal EEPROM of the Device can get corrupted somehow during development and you need to Recover the device The recovery procedure can be accomplished by the following steps 1 Force the SDA line HIGH by connecting it via a Jumper wire to either VIN or VREG 2 While the SDA line is held HIGH Press and Release the RST button 3 Now you can release the SDA line 4 This forces the device to boot from ROM and puts it into Programming Mode awaiting programming commands from the SDK 5 Create a Make Target with the COM Port for the FTDI device you are using and by specifying recover in the Make Target Your make target will look li
56. ll have correct data bleprofile ReadHandle HANDLE HELLO SENSOR VALUE NOTIFY amp db pdu ble tracen char db pdu pdu db 1 db 6 if db pdu pdu 6 gt 9 db pdu pdu 6 9 bleprofile WriteHandle HANDLE HELLO SENSOR VALUE NOTIFY amp db pdu For every button press we increment the amount of messages that we need to send to the client master remember how many messages we need to send hello sensor num to write c The hello sensor connection handleis set in the hello sensor connection up function and is cleared in the hello sensor connection down function So if it is 0 we have either lost the connection or it was never established so we start advertising to establish the connection Note that hello sensor remote is cleared if hello sensor connection down has been called after the connection has been closed If connection is down we need to start advertisements so that client can connect if hello sensor connection handle 0 bleprofile Discoverable HIGH UNDIRECTED DISCOVERABLE hello_sensor_remote_addr ble trace2 ADV start high 408xX04xWn hello sensor hostinfo bdaddr 5 lt lt 24 hello sensor hostinfo bdaddr 4 lt lt 16 hello sensor hostinfo bdaddr 3 lt lt 8 hello sensor hostinfo bdaddr 2 hello sensor hostinfo bdaddr 1 lt lt 8 hello sensor hostinfo bdaddr 0 return If we have dropped to here connection is up and hello
57. n Section 4 7 hello sensor connection down and also in Section 4 8 hello sensor advertisement stopped we saw some lines of code shown below These are the functions to put the device into DEEP SLEEP else ble_trace Entering DeepSleep Connection Lost bleapputils delayUs 500 bleprofile PrepareHidOff I This else statement followed from an if statement that checks the variable hell sensor stay connected in which if itis 1 we would typically start the Advertisements again if it is 0 the firmware drops into the else condition and then the bleprofile PrepareHidOff function is executed which puts the device into DEEP SLEEP If you use this example you can wake the device by simply pressing PO push button or possibly P4 depending on what you have configured in platform h as the push button that is configured in the BLTE stack PO is the default Keep in mind you are NOT limited to PO P4 or what is defined in platform h you can configure any GPIO to be an interrupt manually That should get you started on understanding how to put the device into its lowest power state DEEP SLEEP As indicated more to follow down the road with Timed Wakeups We now move onto Section 8 Configure GPIO EMRF 20737S BOB V1 0 1 Page 48 Embedded Masters Section 8 Configure GPIO This section is not an all inclusive section but will provide you at least a basic idea of how to configure GPIO and test the GPIO are all fu
58. n GPIO PORTO GPIO P4 GPIO OUTPUT ENABLE GPIO HIGH Again these are not by any means all inclusive of the GPIO functions but just one example of how you would go about accessing the correct Port and Port Register bit for an individual Port and then to show how these would be used with the gpio configurePin function There will be more examples to follow in future Addendums to this User Manual and or Appnotes showing more functionality Revision History V1 0 1 Added Silkscreen errata Fixed a couple of formatting errors EMRF 20737S BOB V1 0 1 Page 50 VSELI 2 Header 13 P14 P38 P13 P28 Header 13 TPS62740 2 3 DNI VSEL2 2 VSEL3 2 FA c VREG R2 R3 00 00 VSEL1 4 Determine Output Voltage of TPS62740 Default provides 3 0V output See TPS62740 Datasheet for other Output Voltage Configurations N VREG DNIS DI D2 Ww Ww RI a a 10k E RED SWI PO PO P14 P38 RS P27 15 100k GND VREG VREG R8 10k sw4 Ok sw2 RST 1K P4 mil P4 R7 GND 100k GND VREG R12 10k PL Title EMRF 2073xS BOB Embedded Masters LLC Size Nule Revision V1 0 www embeddedmasters com Date 5 16 2014 Time 1 18 23 Sheet of I File EMRF 20732S BOB SchDoc 5
59. nctional on the 207375 One of the first things to point out is that when referring to GPIO Ports P1 does not mean Pin1 there is no correlation to the actual Port to the Pin You need to check the BCM20737S Datasheet for the specific pin numbers and how the correlate to the Port 5 NOTES e All GPIO can be configured as input output or disabled HIGH Z e All GPIO have internal Pull Ups and Pull Downs that can be enabled when used as an input e An output enabled GPIO pin will retain its state in DEEP_SLEEP e All GPIO s can be configured as edge driven Interrupts rising falling both e Since All GPIO s can be configured as an Interrupt they are all capable of waking the system from SLEEP and or DEEP_SLEEP GPIO s can source sink 2mA Ports P26 P27 P28 can sink up to 16mA e Some GPIO s are bonded together and can provide different functionality depending on the Port selection Only one of the Bonded Ports can be used at a time The unused pin must be input and output disabled A How GPIO PORTS are Accessed To properly access Ports we must access them by the correct Port 0 2 and by the correct pin bit setting in the Port Register The ports are defined as shown below PO P15 PORTO P16 P31 PORT1 P32 P38 PORT2 Or another way to look at this is take the PORT and divide it by 16 The integer remainder is the PORT To access the correct Port Register Bit we take the PORT and do a Modulo 16 Using this yi
60. ndicates since we have indicated we have indicated in the BLE_PROFILE_CFG that we want Encryption we start the encryption process as we require security for every connection we will not send any indications until encryption is done if bleprofile_p_cfg gt encr_required 1 lesmp sendSecurityRequest return The next 2 lines of code we pull the Client BD Address and then store in hello_sensor_hostinfo structure which is defined just before the function prototypes at the top of the file saving bd_addr in nvram bda UINT8 emconninfo_getPeerAddr memcpy hello_sensor_hostinfo bdaddr bda sizeof BD ADDR The next 2 lines of code simply initialize the elements of a structure that stores the characteristic client configuration which is whether or not Indications or Notifications are enabled and then finally the number of Blinks that are stored from either the Pushbutton press or from the GUI This structure is defined before the function prototypes hello sensor hostinfo characteristic client configuration hello sensor hostinfo number of blinks Now we take the BD Address ofthe Client Master that was stored earlier in the structure and store it in the internal EEPROM writtenbyte bleprofile WriteNVRAM VS BLE HOST LIST sizeof hello sensor hostinfo UINT8 amp hello sensor hostinfo ble trace1 NVRAM write 4x n writtenbyte Here we call the encryption_changed function sin
61. nning of the app User can change number of blinks to send when button is pushed else if len 1 amp amp handle HANDLE HELLO SENSOR CONFIGURATION hello_sensor_hostinfo number_of_blinks attrPtr if hello_sensor_hostinfo number_of_blinks bleprofile_LEDBlink 250 250 hello_sensor_hostinfo number_of_blinks ble trace LED Blink write_handler n EMRF 20737S BOB V1 0 1 Page 34 Embedded Masters This is for the case that the write has the incorrect length and handles the fallout by printing a Debug message indicating so else ble trace2 hello sensor write handler bad write len d handle x x n len handle return 0x80 Here we are store what client master wrote to peripheral slave device in NVRAM EEPROM that is internal on the 207375 Save update to NVRAM Client does not need to set it on every connection writtenbyte bleprofile_WriteNVRAM VS_BLE_HOST_LIST sizeof hello_sensor_hostinfo UINT8 amp hello sensor hostinfo ble tracei hello sensor write handler write X04xMn writtenbyte return 0 end hello sensor write handler 14 hello sensor interrupt handler This function handles the interrupts that are generated from the pushbutton Keep in mind in this example the GPIO that is attached to the pushbutton is defined in platform h You can also manually indicate GPIO to be interrupts Note that this function is defin
62. ofile gpio p cfg this function does is it calls the blebat init function which sets up the reading the battery voltage with an A D Since don t have a battery attached to the system now I simply comment out the blebat init function call inside ofthe hello sensor database init function hello sensor database init load handle number Here is where we register setup the Callback functions for various events such as when a Connection is made a Disconnection Even happens or the Advertisements timeout We will inspect these functions later bleprofile regAppEvtHandler is defined in blecm h register connection up and connection down handler bleprofile regAppEvtHandler BLECM APP EVT LINK UP hello sensor connection up bleprofile regAppEvtHandler BLECM APP EVT LINK DOWN hello sensor connection down bleprofile regAppEvtHandler BLECM APP EVT ADV TIMEOUT hello sensor advertisement stopped The next 2 function calls are for when the encryption status has changed and the Secure Pairing Bonding has occurred handler for Encryption changed blecm regEncryptionChangedHandler hello sensor encryption changed handler for Bond result lesmp regSMPResultCb LESMP SINGLE PARAM CB hello sensor smp bond result EMRF 20737S BOB V1 0 1 Page 23 Embedded Masters This is a callback function that is called when the Client writes to the slave server In this example this would occur when the client master configu
63. on is not made within the specified High Adv Duration then it goes into a lower power mode and advertises at a slower rate This is entirely user configurable and typically the user defines a callback function to determine what to do if after the High and Low Advertising durations have expired high undirect adv interval 32 slots low undirect adv interval 1024 slots high undirect adv duration 30 seconds low undirect adv duration 300 Seconds EMRF 20737S BOB V1 0 1 Page 19 Embedded Masters high direct adv interval Qi seconds low direct adv interval 8 seconds high direct adv duration e seconds low direct adv duration 8 seconds We now define the local name This should be the same as the Device Name that is specified in the GATT database You could actually define them as different names What would happen is that the local name below is what would get advertised and once the client master sees the advertisements and reads the GATT database it will pull out the Device Name specified in the GATT database local name Hello LOCAL NAME LEN MAX cod x 0 x 0 xe0 COD LEN ver 1 00 VERSION LEN Here we are indicating that we are requiring that the device create a Secure connection encr required SECURITY ENABLED SECURITY REQUEST data encrypted and device sends security request on every
64. on the BOB go to your Device Manager or whatever tool will show you the COM ports attached to your system Find the COM Port indicated as USB Serial Port x In my case this is COM 6 gt i Network adapters gt Portable Devices Ports COM amp LPT ef Communications Port COMI f ECP Printer Port LPT1 n Intel R Active Management Technology SOL COM3 IP Standard Serial over Bluetooth link COM21 USB Serial Port COM6 p Processors Next go to Trace gt Tracing Setup in SDK2 x x gj Start Debug Traces Stop Debug Traces d Tracing Setup If you are using SDK2 0 1 it will take some time and it may seem like the SDK is hung but it is not you will eventually see the GUI below SDK2 1 0 and beyond does this much faster Choose your COM port that is associated with the USB UART device Configure COM Port EMRF 20737S BOB V1 0 1 Page 5 Embedded Masters You will now see the following output in the Console Tab The initial values printed out are values that were loaded into the GATT database and also various BTLE stack configurations and GPIO settings that have been configured in the BTLE Stack After that you will see the hello_sensor_timeout x being printed out which is the 1 second timer Console 23 i Problems Search 35 Debug Broadcom Debug Viewer 0 20 UCU tUluUUZuuu 00 40 26 00 40 26 blecm evt handler 00 40 26 0e04010a2000 0
65. ot need to be sequential but need to be in order const UINT8 hello sensor gatt database Handle x 1 GATT service Service change characteristic is optional and is not present X X X X So we can see GATT database is essentially an array of data that defines Services Characteristics and Descriptors A couple of keys to keep in mind when reading through this section of firmware are the following 1 Handles are simply addresses that make it handy to reference the individual elements with NOTE Handles do not have to be consecutive but MUST be in order 2 Services Characteristics etc defined with a UUID16 are all assigned by the Bluetooth Sig 3 Services Characteristics etc defined with a UUID128 are all custom definitions that are specific to the application 207375 V1 0 1 Page 15 Embedded Masters What is UUID SERVICE GATT If we do a search in the SDK we find that there is a file ble uuid h in which the BT Sig defined UUID Services are defined If we look in that file we see that UUID_SERVICE_GATT is defined as 0x1801 We can double check this by looking at the Bluetooth org site and we see exactly that The GAP Service further down shows as 0x1800 in ble_uuid h which is matches exactly what the BT Sig definition is I might recommend to review the other services available that are defined in this file https www bluetooth org en us specification assigned numbers generic att
66. process so that it understands the services that are offered by the slave server The definitions in the GATT database effectively provides a specification as to how the devices should pass data and or communicate This is a rather generic description of the GATT database and characteristics it is a bit more sophisticated than that but this will serve the purpose of the discussion here For further reading I would suggest actually downloading the Bluetooth Core Doc Specification manual and read through the BTLE sections Don t get overly concerned that the Core Doc PDF is 2300 pages there are only 3 4 sections that are vital for BTLE Minimally I would recommend reading the BTLE sections in Volume 1 of the Core Docs which will provide a good overview of BTLE and how it is structured Looking at the GATT database for hello sensor we see the following This is the GATT database for the Hello Sensor application It defines services characteristics and descriptors supported by the sensor Each attribute in the database has a handle characteristic has two one for characteristic itself another for the value The handles are used by the peer to access attributes and can be used locally by application for example to retrieve data written by the peer Definition of characteristics and descriptors has GATT Properties read write notify but also has permissions which identify if application is allowed to read or write into it Handles do n
67. res a Notification Indication or writes a value into the HELLO_CHARACTERISTIC_CONFIG value to blink the LED a specified amount register to process client writes legattdb_regWriteHandleCb LEGATTDB_WRITE_CB hello_sensor_write_handler This is the callback for the Pushbutton Interrupt register interrupt handler bleprofile regIntCb BLEPROFILE SINGLE PARAM CB hello sensor interrupt handler This is not in the out of box hello sensor application but it is included in my example as it is needed to make use of putting the 207375 into Deep Sleep The devlpm init initializes the low power mode and the devlpm_enableWakeFrom specifies to wake from Deep Sleep from a GPIO interrupt You can also wake up from a timed wake from either internal 128kHz LPO an external 32kHz XTAL Timed wakeups will be covered in a future Appnote with a code example devlpm init and devlpm enableWakeFrom are defined in devicelpm c power save timeout is not enabled enable device LPM If powersave timeout is enabled the FW would have enabled it already along with a number of other things This is needed for the app to be able to register a callback that is invoked to participate in sleep decisions if hello sensor cfg powersave timeout ble 11 devlpm init and Config GPIO Wakeup n devlpm_init devlpm enableWakeFrom DEV LPM WAKE SOURCE GPIO we are registering Callbacks for th
68. ribute profile GATT Services Mnemonic UUID Size Referenced Specification Generic Access Profile uuid16 0x1800 Bluetooth Core Specification Volume 3 Part C Section 12 Generic Attribute Profile uuid16 0x1801 Bluetooth Core Specification Volume 3 Part G Section 7 PRIMARY SERVICE UUID16 0x0001 UUID SERVICE GATT Handle 0x14 GAP service Device Name and Appearance are mandatory characteristics Peripheral Privacy Flag only required if privacy feature is supported Reconnection Address is optional and only when privacy feature is supported Peripheral Preferred Connection Parameters characteristic is optional and not present PRIMARY SERVICE UUID16 0x0014 UUID SERVICE GAP Handle 0x15 characteristic Device Name handle 0x16 characteristic value Any 16 byte string can be used to identify the sensor Just need to replace the Hello string below Keep it short so that it fits in advertisement data along with 16 byte UUID Now we are going to define some characteristics such as what the Device Name is The device name is what will show up after a Master has read the GATT database and has established a connection This Characteristic is a BT Defined value in which the UUID is again defined in ble uuid h Note that there are 2 handle values as indicated in the comments 0x0015 for the Device name and 0x0016 for the characteristic value Also note the characteristic
69. rs Similar to what we have done above we are going to store the number of blinks which will be 0 upon the initial connection On the terminal window you will see this output from the ble_trace4 debug output below 24 52 blecm evt handler 00 24 52 080400400001 00 24 52 Link Encrypted 89 24 52 hello sample encryption changed 000272c6a2c1 00 24 52 00 24 52 00 24 52 permission check retCode 80 00 24 52 00 24 52 permission check retCode 00 89 24 52 EncOn 272c6a2c1 client configuration 0001 blinks 5 00 24 52 Setup value of our configuration in GATT database db pdu len 1 db pdu pdu 0 hello sensor hostinfo number of blinks bleprofile WriteHandle HANDLE HELLO SENSOR CONFIGURATION amp db pdu ble trace4 EncOn 08 04 client configuration 04x blinks d n hello sensor hostinfo bdaddr 5 lt lt 24 hello sensor hostinfo bdaddr 4 lt lt 16 hello sensor hostinfo bdaddr 3 lt lt 8 hello sensor hostinfo bdaddr 2 hello sensor hostinfo bdaddr 1 lt lt 8 hello sensor hostinfo bdaddr 0 hello sensor hostinfo characteristic client configuration hello sensor hostinfo number of blinks Just as the comments indicate we will send out any outstanding messages that may be present before the encrypted connection has been established Keep in mind that Indications require an ACK from the client master there are outstanding messages that we could not send o
70. supplementary Appnote or an addendum to this User Manual at a later date Earlier in Secton 4 5 hello_sensor create we saw the following lines of code These lines of code initialize the DEEP SLEEP functionality and indicate that we want to wake from a GPIO source The devipm_init initializes the low power mode and devipm enableWakeFrom specifies to wake from Deep Sleep from a GPIO interrupt You can also wake up from a timed wake from either the internal 128kHz LPO or an external 32kHz XTAL Timed wakeups will be covered in a future Appnote with a code example devlpm init and devlpm_enableWakeFrom are defined in devicelpm c If power save timeout is not enabled enable device If powersave timeout is enabled the FW would have enabled it already along with a number of other things This is needed for the app to be able to register a callback that is invoked to participate in sleep decisions if hello sensor cfg powersave timeout ble_trace Call devlpm init and Config GPIO Wakeup n devlpm_init devlpm enableWakeFrom DEV LPM WAKE SOURCE GPIO 207375 V1 0 1 Page 47 Embedded Masters Now all we need to do is determine when we would like to put the device into DEEP SLEEP Often times this may be after a Device has been disconnected from the client master OR if both Advertising Intervals have timed out indicating there is nothing around to connect to Earlier i
71. ted in the following directory C VInstall Directory WICED Smart SDK 2 1 0 WICED Smart SDK make exe Now we can compile and download MyProject to ensure everything is setup correctly To do so we simply double click on the MyProject Green Bullseye and we can view the output on the Console Tab at the bottom of Eclipse If everything is setup correctly and you have the EMRF 20737S BOB connected to the SDK via a USB UART you will see the following output in the Console window Double Click 8 mybeacon BCM920736TAG 032 download MyProject BCM920737TAG 032 download UART COM6 I ata nnarada DORMOMTIETAG 122 NOTE I have added the UART COM6 so that the SDK already knows which COM port to connect to This is NOT required but makes downloading faster Now look at the Console Window you should see the following output The NOTE about DIP Switch is for the Broadcom TAG board In our case simply disconnect the HCI RX line from the USB UART and hit RST and you will see the Debug Messages in the Console Window by going to Trace gt Start Debug Traces If you don t then ensure you configure the correct COM port by selecting Trace gt Tracing Setup as we did in Section 2 Showing Debug Output with 207375 E Console 22 Problems Search Debug sime Build Console WICED Smart SDK OK made C Broadcom WICED BTLE SDK2 1 0 WICED Smart SDK Wiced Smart spar buil
72. ut because connection was not up and or encrypted send them now If we are sending indications we can send only one and need to wait for ack while hello sensor num to write amp amp hello sensor indication sent hello sensor num to write hello sensor send message Ifthe hello sensor stay connected variable is set to 0 then we will start a connection idle timer to disconnect after the connection has been idle for the time specified in the BLE PROFILE CFG structure As recommended for debug purposes we typically would set the con idle timeoutto 0 in the BLE PROFILE CFG so that we don t lose the connection You could set this to a specified time in Seconds if you wanted to disconnect after sending data and the connection has been idle for the specified time If configured to disconnect after delivering data start idle timeout to do disconnection if hello sensor stay connected amp amp hello sensor indication sent bleprofile StartConnIdleTimer bleprofile p cfg con idle timeout bleprofile appTimerCb return 207375 V1 0 1 Page 31 Embedded Masters As indicated in the comments we are sending a connection update to the client master to slow down the polling rate to save power We are done with initial settings and need to stay connected It is a good time to slow down the pace of master polls to save power Following request asks host to setup polling every
73. ving bd_addr in nvram UINT8 bda UINT8 writtenbyte bda UINT8 emconninfo getPeerAddr memcpy hello_sensor_hostinfo bdaddr bda sizeof BD ADDR hello_sensor_hostinfo characteristic_client_configuration hello_sensor_hostinfo number_of_blinks 0 writtenbyte bleprofile_WriteNVRAM VS_BLE_HOST_LIST sizeof hello sensor hostinfo UINT8 amp hello sensor hostinfo ble tracel1 NVRAM write 404xMn writtenbyte EMRF 20737S BOB V1 0 1 Page 29 Embedded Masters 11 hello sensor encryption changed This function is called from the hello_sensor_connection_up function to indicate to the BTLE stack that encryption has be set and if the client master has registered for notifications indications we can send them out now The EVT HDR struct is defined in cfa h The handler function is setup in hello sensor void hello sensor encryption changed HCI EVT HDR evt As a reminder BLEPROFILE_DB_PDU is defined in bleprofile h BLEPROFILE DB PDU db pdu ble traceO hello sample encryption changed n For the 207375 there is not a Buzzer so you could either comment this out or leave it in place and view the PWM output on the Pin that is assigned in platform h for the Buzzer which is P28 pin 39 bleprofile BUZBeep bleprofile p cfg buz on ms Here we are pulling the stored client master BD Address from NVRAM VS BLE HOST LIST is defined in stacknvram h The function bleprofile ReadN
74. you want to connect to you might use a DIRECTED_DISCOVERABLE advertisement which means it is specific to a particular BTLE device and uses that devices BD Bluetooth Device Address If you are designing a Beacon type of product you would make it so it is NOT Discoverable meaning a device is not allowed to connect to it as it is simply intended to send one way information default adv 4 HIGH_UNDIRECTED_DISCOVERABLE We won t worry about this setting just leave as 0 button adv toggle e pairing button make adv toggle if 1 or always on if 0 We now define the High and Low Advertising Intervals Keep in mind that the Advertising Interval is strictly defined by the BT Sig to be a multiple of 625ms So for the High Advertising Interval this is defined as 32 625ms 20ms intervals The Low Advertising interval is less frequent and is 1024 625ms 640ms We then define the High Adv duration to be 30 seconds and the Low to be 300 seconds long The Low and High intervals are used because typically an BTLE device has a use case when it is user directed say by an On Off button press and the system knows it should be in a scenario where the user is trying to connect the device to BTLE client Keep in mind ONLY slaves servers advertise it is master clients that see the advertisements Having a High and Low allows the system to send advertising packets at a fast interval to try to establish the connection quickly If a connecti

Download Pdf Manuals

image

Related Search

Related Contents

LTO Typhoon large scale mixing console  

Copyright © All rights reserved.
Failed to retrieve file