<?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>Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104062/problems-with-can-libraries</link><description>Regarding the error ASSERTION FAIL [!arch_is_in_isr()], it appears that you are attempting to use a mutex within an ISR (Interrupt Service Routine). 
 I am using Zephyr 3.2.99 and NCS v2.3.0. 
 On the custom board that I am using, I have a CAN port with</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 Oct 2023 11:27:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104062/problems-with-can-libraries" /><item><title>RE: Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/thread/451268?ContentTypeID=1</link><pubDate>Thu, 19 Oct 2023 11:27:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e47da50e-2e73-48da-b23a-b6dd9f62222e</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;We are not familiar with this&lt;span&gt;&amp;nbsp;MCP2515 chip from Microchip. Maybe someone in the Zephyr discord&amp;nbsp;can help out.&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/develop/getting_started/index.html#asking-for-help"&gt;https://docs.zephyrproject.org/latest/develop/getting_started/index.html#asking-for-help&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/thread/448449?ContentTypeID=1</link><pubDate>Mon, 02 Oct 2023 07:57:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c0f30b0-ec47-4900-b35c-0c8bf0ffe231</guid><dc:creator>babos</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I discovered that the problem arises because at a certain point, I no longer receive data from the ISR queue of the MCP2515 chip (I still don&amp;#39;t know the real reason). However, I would like to restart the 2515 chip through software, stopping all the specific threads and reconfiguring it to temporarily circumvent the problem. I have tried to stop the threads, remove the filters, stop the CAN, and restart it using API commands, but it does not reboot.I&amp;#39;m currently using &lt;code&gt;NVIC_SystemReset();&lt;/code&gt; for error handling, which restarts the whole system and gets it back up and running. However, this causes a Bluetooth connection reset, which takes too long to reconnect. The alternatives would be to either find the root issue or only restart the CAN chip or perform a warm reboot without disconnecting the Bluetooth (if that&amp;#39;s even possible). I haven&amp;#39;t been able to do it yet. Is there anyone who can support me?&lt;br /&gt;I&amp;#39;m attaching the codes that I have tested:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/// @brief re-initialize can devices and start relative thread(s)
/// @param
void can_reinit()
{
    /* Do NOT WORK */
    can_stop(can_dev_0);
    k_thread_abort(get_state_tid);
    k_thread_abort(rx_tid);
    can_api_initialized = false;
    can_api_init();

    /* al posto di &amp;#39;NVIC_SystemReset()&amp;#39; reinizializzare il solo chip CAN eventualmente bloccato (TODO) */
    // NVIC_SystemReset(); // reset nrf52840
    LOG_INF(&amp;quot;CAN API re-initialized&amp;quot;);
}&lt;/pre&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;Attached is the &amp;#39;.c&amp;#39; file&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank you&amp;nbsp;&lt;/p&gt;
&lt;p&gt;S&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/can_5F00_trouble.c"&gt;devzone.nordicsemi.com/.../can_5F00_trouble.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/thread/447980?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2023 14:07:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d473550-edf0-4dc0-90aa-04bdb6b35d67</guid><dc:creator>babos</dc:creator><description>&lt;p&gt;in fact I have two called within ISR; one during the CAN interrupt, where I should pass what is highlighted below in the code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;K_SEM_DEFINE(uart_sem, 1, 1);
/// @brief
/// @param work
void can_refresh_send(struct k_work *work)
{
    if (uart_dev == NULL || k_sem_take(&amp;amp;uart_sem, K_NO_WAIT) != 0)
    {
        return;
    }

    /* atomic_get(&amp;amp;amsgCAN_array[3]); */
    sprintf(msg, &amp;quot;events cd %04X%02X%04X%02X%04X%04X%04X\r\n&amp;quot;,
            atomic_get(&amp;amp;amsgCAN[8]) + atomic_get(&amp;amp;amsgCAN[9]) * 256, // consumption lt/h
            atomic_get(&amp;amp;amsgCAN[7]),                                 // motor load percentage
            atomic_get(&amp;amp;amsgCAN[5]) + atomic_get(&amp;amp;amsgCAN[6]) * 256, // battery voltage
            atomic_get(&amp;amp;amsgCAN[4]),                                 // refrigerant temperature
            atomic_get(&amp;amp;amsgCAN[2]) + atomic_get(&amp;amp;amsgCAN[3]) * 256, // speed Km/h
            atomic_get(&amp;amp;amsgCAN[0]) + atomic_get(&amp;amp;amsgCAN[1]) * 256, // rpm
            atomic_get(&amp;amp;amsgCAN[13]) + atomic_get(&amp;amp;amsgCAN[14]) * 256);

    LOG_INF(&amp;quot;cd event&amp;quot;);
    // uart_tx(uart_dev, msg, strlen(msg), 10);
    int len = strlen(msg);
    for (int i = 0; i &amp;lt; len; i++)
    {
        uart_poll_out(uart_dev, msg[i]);
    }
    k_sem_give(&amp;amp;uart_sem);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and the one already posted above. It is not necessary to send them during the callback of either one or the other, in fact I would put the messages in a queue and process them in a separate thread. However, I don&amp;#39;t really understand how I can use the uart queues.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thx&lt;/p&gt;
&lt;p&gt;Babos&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/thread/447914?ContentTypeID=1</link><pubDate>Wed, 27 Sep 2023 10:54:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e44c7ca9-82ae-453d-8346-d5d7e4a4e50f</guid><dc:creator>Hakon</dc:creator><description>[quote user="babos"]I need to send a string to UART1 during a UART0 callback, as shown in the attached code, and another one within the CAN chip&amp;#39;s interrupt.[/quote]
&lt;p&gt;Do you need to send the string during the callback, or can you do it after? That way you won&amp;#39;t trigger the assertion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with CAN Libraries</title><link>https://devzone.nordicsemi.com/thread/447338?ContentTypeID=1</link><pubDate>Mon, 25 Sep 2023 05:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:116d8389-e272-4113-bc73-0233ba1ea01f</guid><dc:creator>babos</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/// @brief
/// @param dev
/// @param evt
/// @param user_data
static void uart_callback(const struct device *dev, struct uart_event *evt,
						  void *user_data)
{
	int dev_idx = (int)user_data;
	struct uart_data_event *event;
	struct uart_rx_buf *buf;
	int err;

	switch (evt-&amp;gt;type)
	{
	case UART_RX_RDY:
		uart_rx_buf_ref(evt-&amp;gt;data.rx.buf);
		event = new_uart_data_event();
		event-&amp;gt;dev_idx = dev_idx;
		event-&amp;gt;buf = &amp;amp;evt-&amp;gt;data.rx.buf[evt-&amp;gt;data.rx.offset];
		event-&amp;gt;len = evt-&amp;gt;data.rx.len;
		/* insert decode CAN data */
		char *compare = NULL;
		size_t length = event-&amp;gt;len;

		compare = malloc(length + 1); // Alloca memoria per la variabile &amp;#39;compare&amp;#39;
		if (compare != NULL)
		{
			strncpy(compare, event-&amp;gt;buf, length);
			compare[length] = &amp;#39;\0&amp;#39;; // Aggiungi il terminatore di stringa

			if (strstr((const char *)compare, &amp;quot;[M1]&amp;quot;) &amp;amp;&amp;amp; dev_idx == 1)
			{
				uint16_t numero;
				sscanf(compare, &amp;quot;[%*2s]%hu&amp;quot;, &amp;amp;numero);
				rpm_memo = numero;// no offset / 0.125;
				flag_memo_rpm = true;
				//err = uart_tx(devices[0], compare, length, 0); // opzionale
			}
			else if (strstr((const char *)compare, &amp;quot;[M0]&amp;quot;) &amp;amp;&amp;amp; dev_idx == 1)
			{
				flag_memo_rpm = false;
				rpm_memo = 0;
				//err = uart_tx(devices[0], compare, length, 0); // opzionale
			}
			free(compare); // Libera la memoria allocata per &amp;#39;compare&amp;#39;
		}
		else
		{
			// Gestisci l&amp;#39;errore di allocazione della memoria
		}
		APP_EVENT_SUBMIT(event);
		break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Hello guys, the previous issue lies in the fact that I&amp;#39;m using serial port transmissions incorrectly within ISR, and this is causing my program to lock up. I need to send a string to UART1 during a UART0 callback, as shown in the attached code, and another one within the CAN chip&amp;#39;s interrupt. This is why I&amp;#39;m experiencing abnormal behavior. How can I work around this issue? Thank you.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BAbos&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>