-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xml
926 lines (830 loc) · 97.2 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>RBahrami's Blog</title>
<link>https://RBahrami.github.io/</link>
<description>Recent content on RBahrami's Blog</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<lastBuildDate>Tue, 20 Dec 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://RBahrami.github.io/index.xml" rel="self" type="application/rss+xml" /><item>
<title>Xamarin.Forms and C++</title>
<link>https://RBahrami.github.io/p/xamarin.forms-and-c-/</link>
<pubDate>Tue, 20 Dec 2022 00:00:00 +0000</pubDate>
<guid>https://RBahrami.github.io/p/xamarin.forms-and-c-/</guid>
<description><blockquote>
<p>This walkthrough will show the process of creating and using C++ library in Xamarin.Forms project (Only Android).</p>
</blockquote>
<h3 id="my-environment">My Environment</h3>
<table>
<thead>
<tr>
<th>Syntax</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>OS</td>
<td>Windows 10 (64bit)</td>
</tr>
<tr>
<td>IDE/Compiler</td>
<td>VS 2022 Community</td>
</tr>
<tr>
<td>Target</td>
<td>Android 11</td>
</tr>
</tbody>
</table>
<h2 id="step-1---creating-android-native-library-in-c">Step 1 - Creating Android Native library in C++</h2>
<style type="text/css">.notice{padding:18px;line-height:24px;margin-bottom:24px;border-radius:4px;color:#444;background:#e7f2fa}.notice p:last-child{margin-bottom:0}.notice-title{margin:-18px -18px 12px;padding:4px 18px;border-radius:4px 4px 0 0;font-weight:700;color:#fff;background:#6ab0de}.notice.warning .notice-title{background:rgba(217,83,79,.9)}.notice.warning{background:#fae2e2}.notice.info .notice-title{background:#f0b37e}.notice.info{background:#fff2db}.notice.note .notice-title{background:#6ab0de}.notice.note{background:#e7f2fA}.notice.tip .notice-title{background:rgba(92,184,92,.8)}.notice.tip{background:#e6f9e6}.icon-notice{display:inline-flex;align-self:center;margin-right:8px}.icon-notice img,.icon-notice svg{height:1em;width:1em;fill:currentColor}.icon-notice img,.icon-notice.baseline svg{top:0.125em;position:relative}</style>
<div><svg width="0" height="0" display="none" xmlns="http://www.w3.org/2000/svg"><symbol id="tip-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"/></symbol><symbol id="note-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></symbol><symbol id="warning-notice" viewBox="0 0 576 512" preserveAspectRatio="xMidYMid meet"><path d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></symbol><symbol id="info-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"/></symbol></svg></div><div class="notice note" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#note-notice"></use></svg></span>Note</p><p>Make sure that <strong>Mobile development with C++</strong> component is installed in your Visual Studio.</p></div>
<p>In Visual Studio, Create A New <strong>Dynamic Shared Library (Android)</strong> named &ldquo;MyMathFuncsLib&rdquo; and for simplicity rename solution to &ldquo;XamarinFormsCpp&rdquo;.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProject.png"
width="650"
height="377"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProject_hu5fdd56dcf065273ed114455236a788c1_16730_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProject_hu5fdd56dcf065273ed114455236a788c1_16730_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Dynamic Shared Library (Android) Project"
class="gallery-image"
data-flex-grow="172"
data-flex-basis="413px"
></p>
<p>Delete the auto-created files, then create 4 new files named <strong>MyMathFuncs.h</strong>, <strong>MyMathFuncs.cpp</strong>, <strong>MyMathFuncsWrapper.h</strong>, and <strong>MyMathFuncsWrapper.cpp</strong> and copy the below codes in them (Respectively).</p>
<!-- raw HTML omitted -->
<!-- raw HTML omitted -->
<blockquote>
<p><strong>MyMathFuncs.h</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="n">namespace</span> <span class="n">MathFuncs</span>
<span class="p">{</span>
<span class="n">class</span> <span class="n">MyMathFuncs</span>
<span class="p">{</span>
<span class="nl">public</span><span class="p">:</span>
<span class="kt">double</span> <span class="n">Add</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Subtract</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Multiply</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Divide</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">};</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<blockquote>
<p><strong>MyMathFuncs.cpp</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="cp">#include</span> <span class="cpf">&#34;MyMathFuncs.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="n">namespace</span> <span class="n">MathFuncs</span>
<span class="p">{</span>
<span class="kt">double</span> <span class="n">MyMathFuncs</span><span class="o">::</span><span class="n">Add</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="n">MyMathFuncs</span><span class="o">::</span><span class="n">Subtract</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">-</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="n">MyMathFuncs</span><span class="o">::</span><span class="n">Multiply</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">*</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="n">MyMathFuncs</span><span class="o">::</span><span class="n">Divide</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">/</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<blockquote>
<p><strong>MyMathFuncsWrapper.h</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="cp">#include</span> <span class="cpf">&#34;MyMathFuncs.h&#34;</span><span class="cp">
</span><span class="cp"></span><span class="n">using</span> <span class="n">namespace</span> <span class="n">MathFuncs</span><span class="p">;</span>
<span class="k">extern</span> <span class="s">&#34;C&#34;</span> <span class="p">{</span>
<span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">CreateMyMathFuncsClass</span><span class="p">();</span>
<span class="kt">void</span> <span class="nf">DisposeMyMathFuncsClass</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsAdd</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsSubtract</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsMultiply</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsDivide</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<blockquote>
<p><strong>MyMathFuncsWrapper.cpp</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="cp">#include</span> <span class="cpf">&#34;MyMathFuncsWrapper.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="n">MyMathFuncs</span><span class="o">*</span> <span class="nf">CreateMyMathFuncsClass</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">new</span> <span class="n">MyMathFuncs</span><span class="p">();</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">DisposeMyMathFuncsClass</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ptr</span> <span class="o">!=</span> <span class="n">nullptr</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">delete</span> <span class="n">ptr</span><span class="p">;</span>
<span class="n">ptr</span> <span class="o">=</span> <span class="n">nullptr</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsAdd</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">ptr</span><span class="o">-&gt;</span><span class="n">Add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsSubtract</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">ptr</span><span class="o">-&gt;</span><span class="n">Subtract</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsMultiply</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">ptr</span><span class="o">-&gt;</span><span class="n">Multiply</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">double</span> <span class="nf">MyMathFuncsDivide</span><span class="p">(</span><span class="n">MyMathFuncs</span><span class="o">*</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">ptr</span><span class="o">-&gt;</span><span class="n">Divide</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<p>By now your project structure should look like this:</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectStructure.png"
width="348"
height="283"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectStructure_hu51e252015617b3a17b938d04562cfb20_13488_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectStructure_hu51e252015617b3a17b938d04562cfb20_13488_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Dynamic Shared Library (Android) Project - Configuration"
class="gallery-image"
data-flex-grow="122"
data-flex-basis="295px"
></p>
<div class="notice info" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#info-notice"></use></svg></span>Info</p><p>For information about above codes, refer to <a href="https://github.com/xamcat/mobcat-samples/tree/master/cpp_with_xamarin#writing-the-library-code">This link</a></p></div>
<p>Now we should configure the project. First make sure that project is in <strong>Release for ARM64</strong> configuration, then in <em>Project Properties -&gt; Configuration -&gt; General</em> change the target API level to the maximum value that is posible for your needs.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectConfiguration.png"
width="1554"
height="652"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectConfiguration_huc3672a86a78f85f7bd51e2a1d9b91c84_109706_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectConfiguration_huc3672a86a78f85f7bd51e2a1d9b91c84_109706_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Dynamic Shared Library (Android) Project - Configuration"
class="gallery-image"
data-flex-grow="238"
data-flex-basis="572px"
></p>
<p>And also rename the <em>Root Namespace</em> of the project to <strong>MathFuncs</strong>.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectProperties.png"
width="320"
height="252"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectProperties_hub978a85cbb70d030cc3008aa248382b3_11702_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/DynamicSharedLibraryProjectProperties_hub978a85cbb70d030cc3008aa248382b3_11702_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Dynamic Shared Library (Android) Project - Properties"
class="gallery-image"
data-flex-grow="126"
data-flex-basis="304px"
></p>
<p>At the end build the project (again make sure that project is in <strong>Release for ARM64</strong> configuration!). If every thing is OK, the project should build successfully and a file named <strong>libMathFuncs.so</strong> is created in project output directory (SolutionDir\MyMathFuncsLib\ARM64\Release).</p>
<h2 id="step-2---creating-xamarinform-application">Step 2 - Creating Xamarin.Form application</h2>
<p>Right click on the solution on <em>Solution Explorer</em>, then select <em>New Project</em> from <em>Add</em> menu. Choose <em><strong>Mobile App (Xamarin.Forms)</strong></em>, and name it <em>XamarinApp</em> and create the project. In the next window select <em>Blank</em> as app template and only select <em>Android</em> as platform.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject.png"
width="1355"
height="734"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject_hub6e9832277099a4b7cdb54c3ac76891d_33916_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject_hub6e9832277099a4b7cdb54c3ac76891d_33916_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Xamarin.Forms Project"
class="gallery-image"
data-flex-grow="184"
data-flex-basis="443px"
></p>
<p>In Solution Explorer, right click on <strong>XamarinApp.Android</strong> and select <strong>Set As Startup Project</strong>.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject.Android-StartupProject.png"
width="341"
height="534"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject.Android-StartupProject_huac47744fc597e6922e64ac89fb52b12d_23803_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppProject.Android-StartupProject_huac47744fc597e6922e64ac89fb52b12d_23803_1024x0_resize_box_3.png 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="63"
data-flex-basis="153px"
></p>
<div class="notice tip" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#tip-notice"></use></svg></span>Tip</p><p>To make sure that every thing in the <strong>XamarinApp.Android</strong> project is ok, before going any further, first build and deploy the project.</p></div>
<h2 id="step-3---adding-the-c-library-to-the-xamarin-forms-project">Step 3 - Adding the C++ library to the Xamarin Forms Project</h2>
<p>Add a new folder to the <strong>XamarinApp.Android</strong> project named <em>lib</em> and another new folder to the <strong>lib</strong> folder named <em>arm64-v8a</em> and copy the <strong>libMathFuncs.so</strong> from the privious step to this folder. Then select the <strong>libMathFuncs.so</strong> and in <strong>Properties</strong> window, set the build action to <strong>AndroidNativeLibrary</strong>.
<div class="notice info" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#info-notice"></use></svg></span>Info</p><p>If you are using the <em>.so</em> file in a Xamarin.Android <strong>library</strong> project insted of Xamarin.Android <strong>application</strong> project, replace <strong>AndroidNativeLibrary</strong> with <strong>EmbeddedNativeLibrary</strong>.
For more information refer to <a href="https://learn.microsoft.com/en-us/xamarin/android/platform/native-libraries">This link</a></p></div>
</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinApp.Android-sofile.png"
width="345"
height="663"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinApp.Android-sofile_hu5dfb2f0b8114c714a9658f5d02ce5000_28411_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinApp.Android-sofile_hu5dfb2f0b8114c714a9658f5d02ce5000_28411_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Adding .so file to the project"
class="gallery-image"
data-flex-grow="52"
data-flex-basis="124px"
></p>
<h2 id="step-4---creating-wrapper-of-c-library-for-c">Step 4 - Creating Wrapper of C++ library for C#</h2>
<p>Add a new folder to the <strong>XamarinApp.Android</strong> project named <em>Models</em> and then add a new class named <em>MyMathFuncs.cs</em> in <strong>Models</strong> folder and replace the content of MyMathFuncs.cs with bellow code:</p>
<blockquote>
<p><strong>MyMathFuncs.cs</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span><span class="lnt">47
</span><span class="lnt">48
</span><span class="lnt">49
</span><span class="lnt">50
</span><span class="lnt">51
</span><span class="lnt">52
</span><span class="lnt">53
</span><span class="lnt">54
</span><span class="lnt">55
</span><span class="lnt">56
</span><span class="lnt">57
</span><span class="lnt">58
</span><span class="lnt">59
</span><span class="lnt">60
</span><span class="lnt">61
</span><span class="lnt">62
</span><span class="lnt">63
</span><span class="lnt">64
</span><span class="lnt">65
</span><span class="lnt">66
</span><span class="lnt">67
</span><span class="lnt">68
</span><span class="lnt">69
</span><span class="lnt">70
</span><span class="lnt">71
</span><span class="lnt">72
</span><span class="lnt">73
</span><span class="lnt">74
</span><span class="lnt">75
</span><span class="lnt">76
</span><span class="lnt">77
</span><span class="lnt">78
</span><span class="lnt">79
</span><span class="lnt">80
</span><span class="lnt">81
</span><span class="lnt">82
</span><span class="lnt">83
</span><span class="lnt">84
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="n">using</span> <span class="n">Microsoft</span><span class="p">.</span><span class="n">Win32</span><span class="p">.</span><span class="n">SafeHandles</span><span class="p">;</span>
<span class="n">using</span> <span class="n">System</span><span class="p">;</span>
<span class="n">using</span> <span class="n">System</span><span class="p">.</span><span class="n">Runtime</span><span class="p">.</span><span class="n">InteropServices</span><span class="p">;</span>
<span class="n">namespace</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Droid</span><span class="p">.</span><span class="n">Models</span>
<span class="p">{</span>
<span class="n">internal</span> <span class="n">class</span> <span class="nl">MyMathFuncsSafeHandle</span> <span class="p">:</span> <span class="n">SafeHandleZeroOrMinusOneIsInvalid</span>
<span class="p">{</span>
<span class="n">public</span> <span class="n">MyMathFuncsSafeHandle</span><span class="p">()</span> <span class="o">:</span> <span class="n">base</span><span class="p">(</span><span class="nb">true</span><span class="p">)</span> <span class="p">{</span> <span class="p">}</span>
<span class="n">public</span> <span class="n">IntPtr</span> <span class="n">Ptr</span> <span class="o">=&gt;</span> <span class="n">this</span><span class="p">.</span><span class="n">handle</span><span class="p">;</span>
<span class="n">protected</span> <span class="n">override</span> <span class="kt">bool</span> <span class="nf">ReleaseHandle</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">DisposeMyMathFuncs</span><span class="p">(</span><span class="n">handle</span><span class="p">);</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">internal</span> <span class="k">static</span> <span class="n">class</span> <span class="n">MyMathFuncsWrapper</span>
<span class="p">{</span>
<span class="k">const</span> <span class="n">string</span> <span class="n">DllName</span> <span class="o">=</span> <span class="s">&#34;libMathFuncs.so&#34;</span><span class="p">;</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;CreateMyMathFuncsClass&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="n">MyMathFuncsSafeHandle</span> <span class="n">CreateMyMathFuncs</span><span class="p">();</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;DisposeMyMathFuncsClass&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="kt">void</span> <span class="n">DisposeMyMathFuncs</span><span class="p">(</span><span class="n">IntPtr</span> <span class="n">ptr</span><span class="p">);</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;MyMathFuncsAdd&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="kt">double</span> <span class="n">Add</span><span class="p">(</span><span class="n">MyMathFuncsSafeHandle</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;MyMathFuncsSubtract&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="kt">double</span> <span class="n">Subtract</span><span class="p">(</span><span class="n">MyMathFuncsSafeHandle</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;MyMathFuncsMultiply&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="kt">double</span> <span class="n">Multiply</span><span class="p">(</span><span class="n">MyMathFuncsSafeHandle</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">[</span><span class="n">DllImport</span><span class="p">(</span><span class="n">DllName</span><span class="p">,</span> <span class="n">EntryPoint</span> <span class="o">=</span> <span class="s">&#34;MyMathFuncsDivide&#34;</span><span class="p">)]</span>
<span class="n">internal</span> <span class="k">static</span> <span class="k">extern</span> <span class="kt">double</span> <span class="n">Divide</span><span class="p">(</span><span class="n">MyMathFuncsSafeHandle</span> <span class="n">ptr</span><span class="p">,</span> <span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="n">class</span> <span class="nl">MyMathFuncs</span> <span class="p">:</span> <span class="n">IDisposable</span>
<span class="p">{</span>
<span class="n">readonly</span> <span class="n">MyMathFuncsSafeHandle</span> <span class="n">handle</span><span class="p">;</span>
<span class="n">public</span> <span class="nf">MyMathFuncs</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">handle</span> <span class="o">=</span> <span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">CreateMyMathFuncs</span><span class="p">();</span>
<span class="p">}</span>
<span class="n">protected</span> <span class="n">virtual</span> <span class="kt">void</span> <span class="nf">Dispose</span><span class="p">(</span><span class="kt">bool</span> <span class="n">disposing</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">handle</span> <span class="o">!=</span> <span class="n">null</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">handle</span><span class="p">.</span><span class="n">IsInvalid</span><span class="p">)</span>
<span class="n">handle</span><span class="p">.</span><span class="n">Dispose</span><span class="p">();</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">void</span> <span class="nf">Dispose</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">Dispose</span><span class="p">(</span><span class="nb">true</span><span class="p">);</span>
<span class="n">GC</span><span class="p">.</span><span class="n">SuppressFinalize</span><span class="p">(</span><span class="n">this</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="nf">Add</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="nf">Subtract</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">Subtract</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="nf">Multiply</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">Multiply</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="nf">Divide</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">MyMathFuncsWrapper</span><span class="p">.</span><span class="n">Divide</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<div class="notice info" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#info-notice"></use></svg></span>Info</p><p>For information about above codes, refer to <a href="https://github.com/xamcat/mobcat-samples/tree/master/cpp_with_xamarin#writing-the-managed-library-code">This link</a></p></div>
<h2 id="step-5---using-the-wrapper-in-xamarinforms">Step 5 - Using the Wrapper in Xamarin.Forms</h2>
<p>Add a new folder named <em>Interfaces</em> to the <em>XamarinApp</em> project. then add a new interface named <em>IMathFuncs.cs</em> to this folder.</p>
<p><img src="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppIMathFuncs.png"
width="1278"
height="687"
srcset="https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppIMathFuncs_hu49647f52d27fb4a876ea412524ac9907_61680_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/xamarin.forms-and-c/XamarinAppIMathFuncs_hu49647f52d27fb4a876ea412524ac9907_61680_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Interface for Xamarin App"
class="gallery-image"
data-flex-grow="186"
data-flex-basis="446px"
></p>
<p>Replace the content of <strong>IMathFuncs.cs</strong> with this code:</p>
<blockquote>
<p><strong>IMathFuncs.cs</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="n">namespace</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Interfaces</span>
<span class="p">{</span>
<span class="n">public</span> <span class="n">interface</span> <span class="n">IMathFuncs</span>
<span class="p">{</span>
<span class="kt">double</span> <span class="n">Add</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Subtract</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Multiply</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="kt">double</span> <span class="nf">Divide</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<p>Add a new folder named <em>DependencyService</em> to the <strong>XamarinApp.Android</strong> project, then add a class to it named <em>MathFuncs.cs</em> and replace its content with:</p>
<blockquote>
<p><strong>MyMathFuncs.cs</strong>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="n">using</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Droid</span><span class="p">.</span><span class="n">DependencyService</span><span class="p">;</span>
<span class="n">using</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Droid</span><span class="p">.</span><span class="n">Models</span><span class="p">;</span>
<span class="n">using</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Interfaces</span><span class="p">;</span>
<span class="n">using</span> <span class="n">Xamarin</span><span class="p">.</span><span class="n">Forms</span><span class="p">;</span>
<span class="p">[</span><span class="nl">assembly</span><span class="p">:</span> <span class="n">Dependency</span><span class="p">(</span><span class="n">typeof</span><span class="p">(</span><span class="n">MathFuncs</span><span class="p">))]</span>
<span class="n">namespace</span> <span class="n">XamarinApp</span><span class="p">.</span><span class="n">Droid</span><span class="p">.</span><span class="n">DependencyService</span>
<span class="p">{</span>
<span class="n">public</span> <span class="n">class</span> <span class="nl">MathFuncs</span> <span class="p">:</span> <span class="n">IMathFuncs</span>
<span class="p">{</span>
<span class="n">public</span> <span class="kt">double</span> <span class="n">Add</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">MyMathFuncs</span> <span class="n">o</span> <span class="o">=</span> <span class="n">new</span> <span class="n">MyMathFuncs</span><span class="p">();</span>
<span class="k">return</span> <span class="n">o</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="n">Subtract</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">MyMathFuncs</span> <span class="n">o</span> <span class="o">=</span> <span class="n">new</span> <span class="n">MyMathFuncs</span><span class="p">();</span>
<span class="k">return</span> <span class="n">o</span><span class="p">.</span><span class="n">Subtract</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="n">Multiply</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">MyMathFuncs</span> <span class="n">o</span> <span class="o">=</span> <span class="n">new</span> <span class="n">MyMathFuncs</span><span class="p">();</span>
<span class="k">return</span> <span class="n">o</span><span class="p">.</span><span class="n">Multiply</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">public</span> <span class="kt">double</span> <span class="n">Divide</span><span class="p">(</span><span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="kt">double</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">MyMathFuncs</span> <span class="n">o</span> <span class="o">=</span> <span class="n">new</span> <span class="n">MyMathFuncs</span><span class="p">();</span>
<span class="k">return</span> <span class="n">o</span><span class="p">.</span><span class="n">Divide</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span></code></pre></td></tr></table>
</div>
</div></p>
</blockquote>
<p>Finally to call a function in <strong>Xamarin.Forms</strong> application, i.e. <em>XamarinApp</em> in this example:</p>
<blockquote>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="c1">// Calling &#39;Add&#39; function implemented in C++ library:
</span><span class="c1"></span><span class="kt">double</span> <span class="n">c</span> <span class="o">=</span> <span class="n">DependencyService</span><span class="p">.</span><span class="n">Get</span><span class="o">&lt;</span><span class="n">IMathFuncs</span><span class="o">&gt;</span><span class="p">().</span><span class="n">Add</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">12</span><span class="p">);</span></code></pre></td></tr></table>
</div>
</div>
</blockquote>
<h2 id="source-code">Source Code</h2>
<p><a class="link" href="https://github.com/RBahrami/XamarinForms_and_Cpp" target="_blank" rel="noopener"
>Source code</a> of this walkthrough.</p>
<hr>
<blockquote>
<p>Refrences:</p>
<ol>
<li><a class="link" href="https://github.com/xamcat/mobcat-samples/tree/master/cpp_with_xamarin#writing-the-managed-library-code" target="_blank" rel="noopener"
>Walkthrough: Using C/C++ with Xamarin</a></li>
<li><a class="link" href="https://learn.microsoft.com/en-us/xamarin/cross-platform/cpp/" target="_blank" rel="noopener"
>Use C/C++ libraries with Xamarin</a></li>
<li><a class="link" href="https://learn.microsoft.com/en-us/xamarin/android/platform/native-libraries" target="_blank" rel="noopener"
>Xamarin.Android Using Native Libraries</a></li>
</ol>
</blockquote>
</description>
</item>
<item>
<title>MSD using tinyUSB stack in STM32</title>
<link>https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/</link>
<pubDate>Wed, 23 Feb 2022 00:00:00 +0000</pubDate>
<guid>https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/</guid>
<description><blockquote>
<p>TinyUSB is an open-source cross-platform USB Host/Device stack for embedded systems, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events being deferred and then handled in the non-ISR task function.</p>
</blockquote>
<h2 id="introduction">Introduction</h2>
<p>The ST&rsquo;s USB stack that is included in STM32CubeIDE, has lots of problems, including:</p>
<ol>
<li>Large footprint.</li>
<li>All of the USB services are running on ISR</li>
<li>Can&rsquo;t correctly use it in RTOS</li>
</ol>
<p>In this article, I&rsquo;m going to show you how to use <a class="link" href="https://www.tinyusb.org" target="_blank" rel="noopener"
>TinyUSB</a> stack to create a USB mass storage device (MSD) using STM32.</p>
<h3 id="my-environment">My Environment</h3>
<table>
<thead>
<tr>
<th>Syntax</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>OS</td>
<td>Windows 10 (64bit)</td>
</tr>
<tr>
<td>Language</td>
<td>C</td>
</tr>
<tr>
<td>IDE/Compiler</td>
<td>STM32CubeIDE/GCC</td>
</tr>
<tr>
<td>Target</td>
<td>STM32F429ZITx</td>
</tr>
<tr>
<td>STM32Cube Firmware</td>
<td>FW_F4 V1.26.2</td>
</tr>
<tr>
<td>TinyUSB Version</td>
<td>0.13.0</td>
</tr>
</tbody>
</table>
<h3 id="hardware">Hardware</h3>
<p>I&rsquo;m using a custom board with STM32F429ZI, but process isn&rsquo;t diffrent for other chips and other supported <a class="link" href="https://github.com/hathach/tinyusb" target="_blank" rel="noopener"
>ST MCUs</a>. My board uses Full Speed USB connected to USB_OTG_FS of MCU, based on your hardware, you may also use High Speed or Full Speed USB connected to USB_OTG_HS of MCU.</p>
<h2 id="project-configuration-in-cubemx">Project Configuration in CubeMX</h2>
<h3 id="usb-peripheral">USB Peripheral</h3>
<p>As i mentioned before, i&rsquo;m using USB_OTG_FS for usb communication, so first step is to enable this peripheral in cube mx. to do so, must set the Mode of USB_OTG_FS to <em><strong>Device Only</strong></em> and enable global interrupt of USB in <em><strong>NVIC Settings</strong></em> tab of <em><strong>Configuration</strong></em> window.</p>
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/usb_config.png"
width="697"
height="360"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/usb_config_hu06948f5aef267d68b9c1317898f8d356_45052_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/usb_config_hu06948f5aef267d68b9c1317898f8d356_45052_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="USB configuration in CubeMX"
class="gallery-image"
data-flex-grow="193"
data-flex-basis="464px"
></p>
<h3 id="clock-configuration">Clock Configuration</h3>
<p>After enabling USB hardware, we must configure the clock of the MCU.
<style type="text/css">.notice{padding:18px;line-height:24px;margin-bottom:24px;border-radius:4px;color:#444;background:#e7f2fa}.notice p:last-child{margin-bottom:0}.notice-title{margin:-18px -18px 12px;padding:4px 18px;border-radius:4px 4px 0 0;font-weight:700;color:#fff;background:#6ab0de}.notice.warning .notice-title{background:rgba(217,83,79,.9)}.notice.warning{background:#fae2e2}.notice.info .notice-title{background:#f0b37e}.notice.info{background:#fff2db}.notice.note .notice-title{background:#6ab0de}.notice.note{background:#e7f2fA}.notice.tip .notice-title{background:rgba(92,184,92,.8)}.notice.tip{background:#e6f9e6}.icon-notice{display:inline-flex;align-self:center;margin-right:8px}.icon-notice img,.icon-notice svg{height:1em;width:1em;fill:currentColor}.icon-notice img,.icon-notice.baseline svg{top:0.125em;position:relative}</style>
<div><svg width="0" height="0" display="none" xmlns="http://www.w3.org/2000/svg"><symbol id="tip-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"/></symbol><symbol id="note-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></symbol><symbol id="warning-notice" viewBox="0 0 576 512" preserveAspectRatio="xMidYMid meet"><path d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"/></symbol><symbol id="info-notice" viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet"><path d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"/></symbol></svg></div><div class="notice note" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#note-notice"></use></svg></span>Note</p><p>USB peripheral in STM32 need external clock source to work!</p></div>
</p>
<!-- raw HTML omitted -->
<!-- raw HTML omitted -->
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/clock_config.png"
width="1122"
height="489"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/clock_config_hu1494f085a2776b5d9976f60c13f2e152_66572_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/clock_config_hu1494f085a2776b5d9976f60c13f2e152_66572_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Clock configuration in CubeMX"
class="gallery-image"
data-flex-grow="229"
data-flex-basis="550px"
></p>
<h2 id="importing-tinyusb-library-into-project">Importing TinyUSB library into project</h2>
<p>Clone or download the <a class="link" href="https://github.com/hathach/tinyusb" target="_blank" rel="noopener"
>TinyUSB reposetory</a> in a folder. The library itself is in <em><strong>src</strong></em> folder in repository and example codes are in <em><strong>examples</strong></em>.</p>
<p>Create a new folder in <em><strong>Core</strong></em> folder of project structure and name it <em><strong>TinyUSB</strong></em>. Then right click on it and select <em><strong>Import</strong></em>. In the open window select <em><strong>File System</strong></em> (in <em><strong>General</strong></em> category), then click on <em><strong>Browse</strong></em> and navigate to the downloaded folder from last step and select <em><strong>src</strong></em> folder. In the <em><strong>Import</strong></em> window, select src folder, the rest of options in this window must be the same as following image and click on <em><strong>Finish</strong></em>.</p>
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/import_window.png"
width="612"
height="680"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/import_window_hu3ecf41d9f2d418b4bb02c3976430825f_39240_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/import_window_hu3ecf41d9f2d418b4bb02c3976430825f_39240_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Importing TinyUSB libraries in CubeIDE"
class="gallery-image"
data-flex-grow="90"
data-flex-basis="216px"
></p>
<p>The next step is to add the folder to include paths. To do so, right click on project (or <em><strong>Project</strong></em> menu) and select <em><strong>Properties</strong></em>. Then go to <em><strong>C/C++ General -&gt; Paths and Symbols -&gt; Includes</strong></em> and add <strong>&ldquo;Core/TinyUSB&rdquo;</strong>, then click on <em><strong>Apply and Close</strong></em>.</p>
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/add_to_path.png"
width="807"
height="546"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/add_to_path_hu0e5b65f590f8596e5e3c4845c7029a3d_58357_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/add_to_path_hu0e5b65f590f8596e5e3c4845c7029a3d_58357_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Adding TinyUSB libraries to Include Path in CubeIDE"
class="gallery-image"
data-flex-grow="147"
data-flex-basis="354px"
></p>
<h2 id="the-code">The Code</h2>
<h3 id="adding-example-files-for-msd-to-project">Adding example files for MSD to project</h3>
<p>TinyUSB MSD example is in <em><strong>TinyUSB repository -&gt; examples -&gt; device -&gt; msc_dual_lun</strong></em>. from <em><strong>src</strong></em> folder, import or copy <em><strong>msc_disk_dual.c</strong></em> and <em><strong>usb_descriptors.c</strong></em> files into <em><strong>Src</strong></em> folder of the project structure and <em><strong>tusb_config.h</strong></em> into <em><strong>Inc</strong></em> folder of the project structure.</p>
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/project_structure.png"
width="325"
height="424"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/project_structure_hu240b88ff80f50f745526ac24b2330c54_16682_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/project_structure_hu240b88ff80f50f745526ac24b2330c54_16682_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Project Structure"
class="gallery-image"
data-flex-grow="76"
data-flex-basis="183px"
></p>
<h3 id="edit-example-codes">Edit example codes</h3>
<p>In <em><strong>msc_disk_dual.c</strong></em>, remove <em><strong>#include &ldquo;bsp/board.h&rdquo;</strong></em> to prevent causing error when compling the code. The default way to configure TinyUSB is to pass configuration symbols in compile time (in <em><strong>board.mk</strong></em> file). to make things easier i directly define the needed symbols in <em><strong>tusb_config.h</strong></em> file in project.</p>
<!-- raw HTML omitted -->
<!-- raw HTML omitted -->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="c1">//--------------------------------------------------------------------
</span><span class="c1">// COMMON CONFIGURATION
</span><span class="c1">//--------------------------------------------------------------------
</span><span class="hl"><span class="c1"></span><span class="cp">#define CFG_TUSB_MCU OPT_MCU_STM32F4
</span></span><span class="hl"><span class="cp">#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
</span></span><span class="hl"><span class="cp">#define BOARD_DEVICE_RHPORT_NUM 0
</span></span><span class="hl"><span class="cp">#define CFG_TUSB_RHPORT_MODE (OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED)</span></span></code></pre></div>
<h3 id="redirecting-stm32-usb-interrupt-to-tinyusb-stack">Redirecting STM32 USB interrupt to TinyUSB stack</h3>
<p>Add below code to <em><strong>stm32f4xx_it.c</strong></em> (or it&rsquo;s equivalent if you are using another STM32 family).</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="cm">/* USER CODE BEGIN Includes */</span>
<span class="hl"><span class="cp">#include</span> <span class="cpf">&#34;tusb.h&#34;</span><span class="cp">
</span></span><span class="cp"></span><span class="cm">/* USER CODE END Includes */</span>
<span class="p">...</span>
<span class="cm">/**
</span><span class="cm"> * @brief This function handles USB On The Go FS global interrupt.
</span><span class="cm"> */</span>
<span class="kt">void</span> <span class="n">OTG_FS_IRQHandler</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
<span class="cm">/* USER CODE BEGIN OTG_FS_IRQn 0 */</span>
<span class="hl"> <span class="n">tud_int_handler</span><span class="p">(</span><span class="n">BOARD_DEVICE_RHPORT_NUM</span><span class="p">);</span>
</span><span class="hl"> <span class="k">return</span><span class="p">;</span>
</span> <span class="cm">/* USER CODE END OTG_FS_IRQn 0 */</span>
<span class="n">HAL_PCD_IRQHandler</span><span class="p">(</span><span class="o">&amp;</span><span class="n">hpcd_USB_OTG_FS</span><span class="p">);</span>
<span class="cm">/* USER CODE BEGIN OTG_FS_IRQn 1 */</span>
<span class="cm">/* USER CODE END OTG_FS_IRQn 1 */</span>
<span class="p">}</span></code></pre></div>
<p>After doing above steps, we must first initialize TinyUSB stack by calling <em><strong>tusb_init()</strong></em> and then continuously calling <em><strong>tud_task()</strong></em> in the main loop of program (or in a task if using RTOS) to service the USB requests.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="cm">/* USER CODE BEGIN Includes */</span>
<span class="hl"><span class="cp">#include</span> <span class="cpf">&#34;tusb.h&#34;</span><span class="cp">
</span></span><span class="cp"></span><span class="cm">/* USER CODE END Includes */</span>
<span class="cm">/* Infinite loop */</span>
<span class="cm">/* USER CODE BEGIN WHILE */</span>
<span class="hl"><span class="n">tusb_init</span><span class="p">();</span>
</span><span class="k">while</span> <span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="hl"> <span class="n">tud_task</span><span class="p">();</span>
</span> <span class="cm">/* USER CODE END WHILE */</span>
<span class="cm">/* USER CODE BEGIN 3 */</span>
<span class="p">}</span>
<span class="cm">/* USER CODE END 3 */</span></code></pre></div>
<p>Now compile and flash the code.
<div class="notice info" >
<p class="first notice-title"><span class="icon-notice baseline"><svg><use href="#info-notice"></use></svg></span>Info</p><p>The TinyUSB version that i used (0.13.0), has a code guard bug for synopsis port, that cause the multiple <em><strong>multiple definition of &hellip;</strong></em> error when compling the code. for simplicity i deleted all ports in <em><strong>portable</strong></em> folder of imported TinyUSB library but the ST port from the project.</p>
<p><img src="portable_folder.png" alt="Deleting unused ports"></p>
<p>After deleting the mentioned files, performe a clean build of project!</p></div>
Now when connecting the board to PC (via USB!), you should see to mass storage devices (This is a two LUN example):</p>
<p><img src="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/Results.png"
width="561"
height="109"
srcset="https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/Results_hu2eddd697513620a8e69a73a823699a5a_5781_480x0_resize_box_3.png 480w, https://RBahrami.github.io/p/msd-using-tinyusb-stack-in-stm32/Results_hu2eddd697513620a8e69a73a823699a5a_5781_1024x0_resize_box_3.png 1024w"
loading="lazy"
alt="Mass Storage Devices"
class="gallery-image"
data-flex-grow="514"
data-flex-basis="1235px"
></p>
<hr>
<blockquote>
<p>Refrences:</p>
<ol>
<li><a class="link" href="https://docs.tinyusb.org" target="_blank" rel="noopener"
>TinyUSB Offital website</a></li>
<li><a class="link" href="https://github.com/hathach/tinyusb" target="_blank" rel="noopener"
>TinyUSB GitHUB repository</a></li>
<li><a class="link" href="https://anvilelectronics.ovh/tinyusb-na-stm32-device-cdc/" target="_blank" rel="noopener"
>A CDC (CDC+MSD) example using TinyUSB and STM32</a></li>
</ol>
</blockquote>
</description>
</item>
</channel>
</rss>