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
|
# Microchip BSP
## 1. Microchip BSP Introduction
Supported Microchip SAM (ARM Cortex-Mx Core) MCU is as following:
### ARM Cortex-M23 Series
- saml10 | 3.3V Cortex-M23 with ultra low power
- saml11 | 3.3V Cortex-M23 with ultra low power and trust-zone
### ARM Cortex-M0+ Series
- samc21 | 5V Cortex-M0+ with 2 CAN-FD support
- saml21 | 3.3V low power Cortex-M0+
- samd21 | 3.3V industrial level Cortex-M0+
### ARM Cortex-M4 Series
- same54 | 3.3V 120MHz Cortex-M4F core with CAN-FD/USB/Ethernet support
### ARM Cortex-M7 Series
- same70 | 3.3V 300MHz Cortex-M7 core with CAN-FD/High speed USB/Ethernet support
### Directory description:
* applications:
* user main function entrance,
* driver example - like i2c, can, adc ...
* application example
* board:
* user board initialization
* user driver adpater code, like console device, ethernet device
* bsp:
* MCU BSP files - startup file, peripheral drivers, configuation headers and linker script
* generated from start.atmel.com - DO NOT modify it
## 2. RT-Thread porting guide of Microchip SAM MCU
### 2.1 Configure project BSP on Atmel Start
Visit <https://start.atmel.com/#> and click CREATE NEW PROJECT.

Input MCU part number and then select device, click CREATE NEW PROJECT.

Add STDIO and other driver/middleware to project.

Configure STDIO driver.

Configure CAN module clock.

Configure CAN module driver.


Add LED pin description.

Rename project.

Save project configuration.

Export project source code.

### 2.2 Add project to RT-Thread source code
Link: <https://github.com/RT-Thread/rt-thread> and download RT souce code.

Unzip downloaded RT-Thread and SAME70 CAN Example

Enter *rt-thread-xxx/bsp/microchip* directory and copy **same70** folder and rename it to **same70q20**.

Enter same70q20 directory and remove all files except SConscript file.

Copy all files from SAME70 CAN Example to rt-thread-xxx/bsp/microchip/same70q20/bsp.

Modify rt-thread-xxx\bsp\microchip\same70q20\rtconfig.py.

Modify rt-thread-xxx\bsp\microchip\same70q20\bsp\SConscript.

Modify rt-thread-xxx\bsp\microchip\same70q20\bsp\same70b\gcc\gcc\same70q20b_flash.ld.

Modify rt-thread-xxx\bsp\microchip\same70q20\bsp\same70b\gcc\gcc\startup_same70q20b.c.

Alright, now you can use RT-Thread env tools to compile the project.
### 2.3 Compile project with RT-Thread env tools
About RT-Thread env tools, click [Here](https://github.com/RT-Thread/rt-thread/blob/master/documentation/env/env.md).
Download RT-Thread env tools <https://www.rt-thread.org/download.html#download-rt-thread-env-tool>

Unzip downloaded file and run env.exe.

Enter your project directory and run scons command to compile it.

Compile error you may have and proposed solution.

Fix compiling error

Compiling success

In the following chapter I will show you how to debug RT-Thread with Studio 7.
## 3. RT-Thread debugging with Microchip IDE
Link: <https://www.microchip.com/en-us/tools-resources/develop/microchip-studio>, download & install Microchip Studio 7.

Open installed Microchip Studio 7 and open object file for debugging.

Choose object file, fill project name and select where to save this project.

Select the right part number and complete object set up.

Object file import complete and you can see related files are linked to project.

Right click the project and choose the debug tools in project propertities setting.

Choose debugger/programmer and debugger interface - SWD or JTGA.

Press debugging button and enjoy your debugging journey.

Debugging start and you can add breakpoint.

Debugging paused at breakpoint and you can monitor local variables at Watch window.

Debugging message output.

## 4. Reconfigure MCU BSP
Visit <https://start.atmel.com/#> and upload project configuration.

Now you can reconfigure your project.

## 5. Microchip SAM MCU BSP configuration and user guide
Please refer to [ASF4 API Reference Manual](https://ww1.microchip.com/downloads/en/DeviceDoc/50002633B.pdf) for more details
### 5.1 SAMC2x/E5x/E70 CAN Driver
CAN driver configuration.


CAN driver user guide - see [ASF4 API Reference Manual](https://ww1.microchip.com/downloads/en/DeviceDoc/50002633B.pdf) P121 for more details.
To be continued.
## 6. Contact Info
- [Kevin Liu](https://github.com/klmchp), email: <[email protected]>
- [luhuadong](https://github.com/luhuadong), email: <[email protected]>
|