You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/04/05 05:32:45 UTC

[6/8] incubator-mynewt-site git commit: nimble tutorial: Fix build issues with minimal app

nimble tutorial: Fix build issues with minimal app


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/da5b1d35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/da5b1d35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/da5b1d35

Branch: refs/heads/master
Commit: da5b1d35629eeaf51d41d97cb4b77983b5501de7
Parents: b337a83
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Apr 2 11:11:09 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Apr 2 11:39:40 2016 -0700

----------------------------------------------------------------------
 docs/network/ble/ini_stack/ble_ini_intro.md | 12 ++--
 docs/network/ble/nimble_setup.md            | 72 ++++++++++++++++++------
 2 files changed, 61 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/da5b1d35/docs/network/ble/ini_stack/ble_ini_intro.md
----------------------------------------------------------------------
diff --git a/docs/network/ble/ini_stack/ble_ini_intro.md b/docs/network/ble/ini_stack/ble_ini_intro.md
index e714fe7..b3b3b87 100644
--- a/docs/network/ble/ini_stack/ble_ini_intro.md
+++ b/docs/network/ble/ini_stack/ble_ini_intro.md
@@ -1,12 +1,13 @@
 ## Nimble stack initialization
 
-We are now going to explain how to setup your application to initialize the nimble stack and to get the basic stack, and its required modules, initialized and up and running. Note that the code shown here is an example of what is required for nimble stack operation; it is not intended to dictate to the developer exactly how to organize/setup your code. For example, the code sample shows modification of main.c in the application /src folder. The developer has the flexibility to organize the code as they see fit so this code does not need to reside in /src/main.c or in the main() function itself. The only possible issue is the order of some of the initializations. Where this order is important it is indicated in the sections covering stack initialization. 
+We are now going to explain how to set up your application to initialize the nimble stack and to get the basic stack, and its required modules, initialized and up and running. Note that the code shown here is an example of what is required for nimble stack operation; it is not intended to dictate to the developer exactly how to organize and set up your code. For example, the code sample shows modification of main.c in the application _/src_ folder. The developer has the flexibility to organize the code as they see fit so this code does not need to reside in _/src/main.c_ or in the _main()_ function itself. The only possible issue is the order of some of the initializations. Where this order is important it is indicated in the sections covering stack initialization.
 
-A note about the code samples: the main() function in each code sample builds upon the previous example. However, code outside of main() shows only what we add for each step. The last code sample shows the entire main.c that we created.
+A note about the code samples: the _main()_ function in each code sample builds upon the previous example. However, code outside of _main()_ shows only what we add for each step. The last code sample shows the entire _main.c_ that we created.
 
-Let's start with a very basic main() function (shown below). In this main all we are doing is initializing the Mynewt OS and starting it.
+Let's start with a very basic _main()_ function (shown below). This _main()_ function is identical to the minimal version used in the [Set up application](../nimble_setup/) introductory page.  In this _main()_ all we are doing is initializing the Mynewt OS and starting it.
 
 ```c
+#include <assert.h>
 #include "os/os.h"
 
 int
@@ -22,7 +23,4 @@ main(void)
     assert(0);
 }
 ```
-The Nimble stack requires a number of packages/modules to be initialized prior to being started. We are going to add these one by one to the application and describe each.
-
-<br>
-
+The Nimble stack requires a number of packages to be initialized prior to being started. We are going to add these one by one to the application and describe each.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/da5b1d35/docs/network/ble/nimble_setup.md
----------------------------------------------------------------------
diff --git a/docs/network/ble/nimble_setup.md b/docs/network/ble/nimble_setup.md
index d4ae32a..6715740 100644
--- a/docs/network/ble/nimble_setup.md
+++ b/docs/network/ble/nimble_setup.md
@@ -10,11 +10,11 @@ This tutorial assumes that you have already installed the newt tool and are fami
 You start by creating a project space for your own application work using the Newt tool (`my_proj1` in this example) and installing all the additional apps and libraries available by adding the repo `apache-mynewt-core`. See the tutorial on [adding a repo](../../os/tutorials/add_repos.md) for more on working with repos.
 
 ```
-$ newt new my_proj1
+~/dev$ newt new my_proj1
 Downloading project skeleton from apache/incubator-mynewt-blinky...
 Installing skeleton in my_proj1...
 Project my_proj1 successfully created.
-$ tree my_proj1
+~/dev$ tree my_proj1
 my_proj1
 ├── DISCLAIMER
 ├── LICENSE
@@ -36,10 +36,10 @@ my_proj1
 
 6 directories, 11 files
     
-$ cd my_proj1
-$ newt install
+~/dev$ cd my_proj1
+~/dev/my_proj1$ newt install
 apache-mynewt-core
-$ tree 
+~/dev/my_proj1$ tree
 .
 ├── DISCLAIMER
 ├── LICENSE
@@ -87,14 +87,53 @@ $ tree
 It's time to build your own app using one or more of the example apps available in the repo `apache-mynewt-core`. 
 
 ```
-$ ls repos/apache-mynewt-core/apps
+~/dev/my_proj1$ ls repos/apache-mynewt-core/apps
 bleprph		bletiny		boot		luatest		test
 bletest		blinky		ffs2native	slinky
 ```
 
 <br>
 
-At the very least your app must contain a `main.c()` and a `pkg.yml` file. So copy the ones from `bletiny` and start enhancing it for your own custom use case!
+At the very least your app must contain a `main()` function and a `pkg.yml` file.  Use the following steps to create minimal ...
+
+*1. Create the app directory structure.*
+```no-highlight
+~/dev/my_proj1$ mkdir -p apps/ble_app/src
+```
+<br>
+*2. Paste the following contents into `apps/ble_app/pkg.yml`.*
+
+```no-highlight
+pkg.name: apps/ble_app
+pkg.type: app
+
+pkg.deps:
+    - "@apache-mynewt-core/libs/baselibc"
+    - "@apache-mynewt-core/libs/console/full"
+    - "@apache-mynewt-core/libs/os"
+    - "@apache-mynewt-core/net/nimble/controller"
+    - "@apache-mynewt-core/net/nimble/host"
+```
+<br>
+*3. Paste the following contents into `apps/ble_app/src/main.c`.*
+```c
+#include <assert.h>
+#include "os/os.h"
+
+int
+main(void)
+{
+    /* Initialize OS */
+    os_init();
+
+    /* Start the OS */
+    os_start();
+
+    /* os_start should never return. If it does, this should be an error */
+    assert(0);
+}
+```
+In this _main()_ all we are doing is initializing the Mynewt OS and starting it.
 
 <br>
 
@@ -103,7 +142,7 @@ At the very least your app must contain a `main.c()` and a `pkg.yml` file. So co
 Now you have to create the target that you will use to build your application. We will call this target "ble\_tgt". Type the `newt target create ble_tgt` command. You should get this:
 
 ```no-highlight
-$ newt target create ble_tgt
+~/dev/my_proj1$ newt target create ble_tgt
 Target targets/ble_tgt successfully created
 ```
 
@@ -114,9 +153,10 @@ The target is not yet complete though! We need to set some target variables for
 Here is the command you will need to set up your target for the nrf52:
 
 ```no-highlight
-$ newt target set ble_tgt app=apps/ble_app                              \
-                          bsp=@apache-mynewt-core/hw/bsp/nrf52pdk       \
-                          build_profile=optimized
+~/dev/my_proj1$ newt target set ble_tgt     \
+    app=apps/ble_app                        \
+    bsp=@apache-mynewt-core/hw/bsp/nrf52pdk \
+    build_profile=optimized
 Target targets/ble_tgt successfully set target.app to apps/ble_app
 Target targets/ble_tgt successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf52pdk
 Target targets/ble_tgt successfully set target.build_profile to optimized
@@ -125,9 +165,10 @@ Target targets/ble_tgt successfully set target.build_profile to optimized
 Here is the command you will need to set up your target for the nrf51:
 
 ```no-highlight
-$ newt target set ble_tgt app=apps/ble_app                              \
-                          bsp=@apache-mynewt-core/hw/bsp/nrf51dk        \
-                          build_profile=optimized
+~/dev/my_proj1$ newt target set ble_tgt     \
+    app=apps/ble_app                        \
+    bsp=@apache-mynewt-core/hw/bsp/nrf51dk  \
+    build_profile=optimized
 Target targets/ble_tgt successfully set target.app to apps/ble_app
 Target targets/ble_tgt successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf51dk
 Target targets/ble_tgt successfully set target.build_profile to optimized
@@ -135,7 +176,6 @@ Target targets/ble_tgt successfully set target.build_profile to optimized
 
 <br>
 
-
 ### Nimble stack initialization
 
 There are certain stack initialization steps that are required for a BLE application to be up and running. If you are running a canned example (e.g. bletiny), these steps are already done for you. When you are writing your own app, you may want to assign different initial values or initialize additional packages that you may have added to your project or written yourself. 
@@ -149,7 +189,7 @@ Details of the initialization step requirements are covered in [Initialize Stack
 Now that we have created the application and the target we can build it and test it out. The command you need to run is the `newt build` command with the target we created (_ble\_tgt_). The output will show the files being compiled and linked. You should see this when all is done (except for the _..._ of course):
 
 ```no-highlight
-wes@~/dev/my_proj1$ newt build ble_tgt
+~/dev/my_proj1$ newt build ble_tgt
 ...
 Archiving os.a
 Compiling cons_fmt.c