<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to add support for SAM D51&#x2F;Cortex M4?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
my name is Karl-Heinz and I discovered MySensor a few days ago. I am very impressed and would like to use it for all my sensors.<br />
I have 8bit and 32bit MCUs.<br />
My latest MCU is an SAM D51 (Adafruit Itsybitsy M4).<br />
I can use it when I make a minor modification to MySensors/hal/architecture/SAMD/MyHwSAMD.cpp.<br />
When I try to compile Arduino IDE throws an error, that ADC is not defined in this context -&gt; uint16_t hwCPUVoltage()<br />
I have not much experience with programming. Therefore I commented all code lines in uint16_t hwCPUVoltage() and added hardcoded     "return 3.3;"<br />
Then I can compile at least what I tested so far for the SAM D51.</p>
<p dir="auto">Of course this is not a solution. Therefore I would like to ask what is the proper way to modify MySensors for use with the Cortex M4 processors.</p>
<p dir="auto">Thanks a lot and keep the good work going!!</p>
<p dir="auto">Sincerely</p>
<p dir="auto">Karl-Heinz</p>
]]></description><link>https://forum.mysensors.org/topic/9708/how-to-add-support-for-sam-d51-cortex-m4</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Jul 2026 19:16:42 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/9708.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Sep 2018 09:27:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to add support for SAM D51&#x2F;Cortex M4? on Mon, 10 Sep 2018 16:57:27 GMT]]></title><description><![CDATA[<p dir="auto">Hallo Mikael,<br />
thank you for your hint.</p>
<p dir="auto">I modified the hwCPUVoltage() part of MyHwSAMD.cpp like this. It works for me. Maybe it is not the best solution, however.</p>
<p dir="auto">Sincerely</p>
<p dir="auto">Karl-Heinz</p>
<pre><code>uint16_t hwCPUVoltage()
{
	#ifdef __SAMD51__ 
	   return FUNCTION_NOT_SUPPORTED;
	#else

	// disable ADC
	while (ADC-&gt;STATUS.bit.SYNCBUSY);
	ADC-&gt;CTRLA.bit.ENABLE = 0x00;

	// internal 1V reference (default)
	analogReference(AR_INTERNAL1V0);
	// 12 bit resolution (default)
	analogWriteResolution(12);
	// MUXp 0x1B = SCALEDIOVCC/4 =&gt; connected to Vcc
	ADC-&gt;INPUTCTRL.bit.MUXPOS = 0x1B ;

	// enable ADC
	while (ADC-&gt;STATUS.bit.SYNCBUSY);
	ADC-&gt;CTRLA.bit.ENABLE = 0x01;
	// start conversion
	while (ADC-&gt;STATUS.bit.SYNCBUSY);
	ADC-&gt;SWTRIG.bit.START = 1;
	// clear the Data Ready flag
	ADC-&gt;INTFLAG.bit.RESRDY = 1;
	// start conversion again, since The first conversion after the reference is changed must not be used.
	while (ADC-&gt;STATUS.bit.SYNCBUSY);
	ADC-&gt;SWTRIG.bit.START = 1;

	// waiting for conversion to complete
	while (!ADC-&gt;INTFLAG.bit.RESRDY);
	const uint32_t valueRead = ADC-&gt;RESULT.reg;

	// disable ADC
	while (ADC-&gt;STATUS.bit.SYNCBUSY);
	ADC-&gt;CTRLA.bit.ENABLE = 0x00;

	return valueRead * 4;
        #endif
}
</code></pre>
]]></description><link>https://forum.mysensors.org/post/93472</link><guid isPermaLink="true">https://forum.mysensors.org/post/93472</guid><dc:creator><![CDATA[Karl-Heinz K]]></dc:creator><pubDate>Mon, 10 Sep 2018 16:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to How to add support for SAM D51&#x2F;Cortex M4? on Mon, 10 Sep 2018 12:08:19 GMT]]></title><description><![CDATA[<p dir="auto">A (still incomplete but) less inelegant solution is to</p>
<pre><code>return FUNCTION_NOT_SUPPORTED;
</code></pre>
<p dir="auto">As is done for esp32 for example: <a href="https://github.com/mysensors/MySensors/blob/6ffe29cb5fcfa33fa83133044c2d16ee45c66697/hal/architecture/ESP32/MyHwESP32.cpp#L119" rel="nofollow ugc">https://github.com/mysensors/MySensors/blob/6ffe29cb5fcfa33fa83133044c2d16ee45c66697/hal/architecture/ESP32/MyHwESP32.cpp#L119</a></p>
]]></description><link>https://forum.mysensors.org/post/93458</link><guid isPermaLink="true">https://forum.mysensors.org/post/93458</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Mon, 10 Sep 2018 12:08:19 GMT</pubDate></item></channel></rss>