<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HSL Model Error</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77493/hsl-model-error</link><description>Hi Al, 
 
 I am trying to use HSL Model to control RGB lights and getting this error. I am using nRF Connect SDK and nRF52-DK. 
 
 Regards, 
 Zolu</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 28 Jul 2021 14:12:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77493/hsl-model-error" /><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/322274?ContentTypeID=1</link><pubDate>Wed, 28 Jul 2021 14:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a58860d3-d8a2-4f16-a638-6747bff23c0a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zolu,&amp;nbsp;&lt;br /&gt;Have you managed to correct the functions ?&amp;nbsp;&lt;br /&gt;I have got more instruction from our team:&amp;nbsp;&lt;br /&gt;===============&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is worth to read CONTAINER_OF macro documentation :&amp;nbsp;&lt;br /&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/main/include/sys/util.h#L111"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/include/sys/util.h#L111&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This macro is used to get a pointer on the parent structure if you know pointer to the one of a member of a structure.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How do we use it in our app?&lt;/p&gt;
&lt;p&gt;We have app structure:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
struct lightness_ctx {
	struct bt_mesh_lightness_srv lightness_srv;
	struct k_work_delayable per_work;
	uint16_t target_lvl;
	uint16_t current_lvl;
	uint32_t time_per;
	uint16_t rem_time;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This structure has `lightness_srv` that we initialize and use to handle the Light Lightness model states via registered callbacks like `light_set()`.&lt;/p&gt;
&lt;p&gt;When&amp;nbsp;`light_set()` is called, the fist argument is pointer to `lightness_srv`. Using `CONTAINER_OF ` we get pointer to `struct lightness_ctx` global context variable and etc etc ect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How does customer use it?&lt;/p&gt;
&lt;p&gt;Customer has app structure:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
struct lightness_ctx {
        struct bt_mesh_lightness_srv light_cb;
	struct bt_mesh_light_hue_srv hue_cb;
        struct bt_mesh_light_sat_srv sat_cb;
	struct k_delayed_work per_work;
	uint16_t target_lvl;
	uint16_t current_lvl;
        uint16_t target_hue;
        uint16_t current_hue;
        uint16_t target_sat;
        uint16_t current_sat;
	uint32_t time_per;
	uint16_t rem_time;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It does not have any servers. Customer uses HSL server. According to spec HSL server has 3 `light_lightness servers` (1 itsown and 2 belong Hue and Saturation servers). Callbacks that customer register via `BT_MESH_LIGHT_HSL_SRV_INIT` belongs `light_lightness server` to HSL server. Looking at structure we can see:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**/** * Light HSL Server instance. */
struct bt_mesh_light_hsl_srv {
 /** Light Hue Server instance. */ 
struct bt_mesh_light_hue_srv hue; 
/** Light Saturation Server instance. */
 struct bt_mesh_light_sat_srv sat;
 
 /** Lightness Server instance. */
 struct bt_mesh_lightness_srv lightness;   &amp;lt;------------------- here
 
 
 /** Model entry. */
 struct bt_mesh_model *model;
 /** Publish parameters. */
 struct bt_mesh_model_pub pub;
 /** Publish message buffer */
 struct net_buf_simple buf;
 /** Publish message buffer data */
 uint8_t pub_data[BT_MESH_MODEL_BUF_LEN( BT_MESH_LIGHT_HSL_OP_STATUS, BT_MESH_LIGHT_HSL_MSG_MAXLEN_STATUS)];
 /** A publication is pending, and any calls to
  *  @ref bt_mesh_light_hsl_srv_pub will return successfully without
  *  sending a message.  */
 bool pub_pending;
 /** Transaction ID tracker for the set messages. */
 struct bt_mesh_tid_ctx prev_transaction;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;light_lightness server is located here.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Why customer does such actions this:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void light_set(struct bt_mesh_lightness_srv *srv,
		      struct bt_mesh_msg_ctx *ctx,
		      const struct bt_mesh_lightness_set *set,
		      struct bt_mesh_lightness_status *rsp)
{
        struct lightness_ctx *l_ctx =
		CONTAINER_OF(srv, struct lightness_ctx, light_cb);//	start_new_light_trans(set, l_ctx);
	rsp-&amp;gt;current = l_ctx-&amp;gt;current_lvl;
	rsp-&amp;gt;target = l_ctx-&amp;gt;target_lvl;
	rsp-&amp;gt;remaining_time = set-&amp;gt;transition-&amp;gt;time + set-&amp;gt;transition-&amp;gt;delay;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Gets pointer on server from `struct bt_mesh_light_hsl_srv` but interprets it as `struct lightness_ctx`.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The same for hue and saturation callbacks.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is obvious access to the wrong addresses that will cause memory faults.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;To get correct behavior customer needs to use the correct data structure.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;================&lt;br /&gt;&lt;br /&gt;Hope this helps.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/321478?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 06:58:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:370bd986-6dd9-4480-99f7-8db71a18709d</guid><dc:creator>Zolu</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&lt;/p&gt;
&lt;p&gt;We are a team working on BLE Mesh project. We took light_ctrl as the base and started building RGB on top of that.&lt;/p&gt;
&lt;p&gt;Is there any sample which we can take as reference?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Zolu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/321400?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 14:31:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc910e04-7a15-432e-bef7-daec4dff8ae0</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zolu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I got the code reviewed by our R&amp;amp;D and they suspect that the use of&amp;nbsp;&lt;br /&gt;struct lightness_ctx *l_ctx = CONTAINER_OF(srv, struct lightness_ctx, hue_cb);&lt;/p&gt;
&lt;p&gt;struct lightness_ctx *l_ctx =CONTAINER_OF(srv, struct lightness_ctx, sat_cb);&lt;/p&gt;
&lt;p&gt;was wrong. If you comment out&amp;nbsp;start_new_hue_trans() and&amp;nbsp;start_new_sat_trans() it would work fine. At least for provisioning and configuration (of course&amp;nbsp;hue_set and sat set won&amp;#39;t work as it should).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;From where did you get the code from ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is the quote from our R&amp;amp;D:&amp;nbsp;&lt;br /&gt;&lt;em&gt;&amp;nbsp;It is not possible to provide an occasional pointer to calculate the offset of the structure field. He performs to wrong addresses access after provisioning when models set initial values that causes hardfaults.&amp;nbsp;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/320950?ContentTypeID=1</link><pubDate>Tue, 20 Jul 2021 14:18:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20ebd40f-307b-4b70-acaf-e6ebd2047afc</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zolu,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I have reproduced the issue here. I&amp;#39;m checking internally to figure out what could be wrong.&amp;nbsp;&lt;br /&gt;It seems to me it has something to do with the usage of memory. It somehow trying to execute code in RAM. &lt;br /&gt;How did you implement the model ? Have you got at any step that it was working and when you added some code it crashed ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/320819?ContentTypeID=1</link><pubDate>Tue, 20 Jul 2021 07:28:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36e55d83-c30e-44f0-a299-8769f4a40cf6</guid><dc:creator>Zolu</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/rgb_5F00_folder.zip"&gt;devzone.nordicsemi.com/.../rgb_5F00_folder.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have attached the .zip file with basic implementation. This is not the final implementation though.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Zolu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/320419?ContentTypeID=1</link><pubDate>Fri, 16 Jul 2021 11:59:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce8a669f-9029-4ee6-9c76-2dc2f6d5bf1c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zolu,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you provide a minimal example that can reproduce the issue so we can test here ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I assume in the prj.conf you have&amp;nbsp;CONFIG_BT_LL_SW_SPLIT=y (so that the Zephyr BLE controller will be used).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/320352?ContentTypeID=1</link><pubDate>Fri, 16 Jul 2021 05:19:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d64cca1c-42fb-437f-a6bb-5ff8ce1b3904</guid><dc:creator>Zolu</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;- No such issue is seen while testing other mesh sample.&lt;/p&gt;
&lt;p&gt;- After provisioning&lt;/p&gt;
&lt;p&gt;- nRF52832&lt;/p&gt;
&lt;p&gt;I have used the light_ctrl sample code from NCS v1.5.0 as a reference and tried to build RGB on top of that. On the SDK release selection I have not selected Zephyr Base.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HSL Model Error</title><link>https://devzone.nordicsemi.com/thread/320307?ContentTypeID=1</link><pubDate>Thu, 15 Jul 2021 14:43:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a891191a-6b7c-4c79-8ae1-b8e61958e966</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Zolu,&amp;nbsp;&lt;br /&gt;Could you give some more information:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- Do you see the same issue if you test on other mesh sample ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- When do you see the error as on the SES screenshot ? Is it right after booting or after provisioning ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- Which chip are you running ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- Have you flashed the Zephyr BLE controller or it&amp;#39;s the Softdevice BLE controller ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>