1*** Variables ***
2${URL}                              https://dl.antmicro.com/projects/renode
3${AGT_ELF}                          ${URL}/renesas_ra6m5--agt.elf-s_303444-613fbe7bc11ecbc13afa7a8a907682bbbb2a3458
4${HELLO_WORLD_ELF}                  ${URL}/ra6m5-hello_world.elf-s_310112-5e896556c868826bc8d25d695202ebe0beed7df2
5${AWS_SCI_ICP10101_ELF}             ${URL}/renesas_ra6m5--aws-icp10101.elf-s_795916-3d68631f0fdfc3838fdba768d3a6d46312707ae3
6${AWS_SCI_HS3001_ELF}               ${URL}/renesas_ra6m5--aws-hs3001.elf-s_758320-642c83fb428d4ccc1e35c2908178de232744dbad
7${AWS_ZMOD4510_ELF}                 ${URL}/renesas_ra6m5--aws-zmod4510.elf-s_807176-4b4d580be7d9876f822205349432d3ea68172a17
8${AWS_ZMOD4410_ELF}                 ${URL}/renesas_ra6m5--aws-zmod4410.elf-s_808224-8d79f1a1ff242d00131c12298f64420df21bc1d3
9${SCI_SPI_ELF}                      ${URL}/renesas_ra6m5--sci_spi.elf-s_346192-72cd95f5c506423a29f654be7fb7471b3b230ed0
10${AWS_ICM20948_ELF}                 ${URL}/renesas_ra6m5--aws-icm20948.elf-s_799636-492407caeb09cadd9b5bab867955ce9dc6d7229e
11# SCI_UART demo is slightly modified version with additional printfs for better testability
12${SCI_UART_ELF}                     ${URL}/renesas_ra6m5--sci_uart.elf-s_413420-158250896f48de6bf28e409c99cdda0b2b21e43e
13${IIC_MASTER_ELF}                   ${URL}/renesas_ra6m5--iic_master.elf-s_322744-232a1bea524059a7170c97c7fa698c5efff39f03
14${AWS_CC_ELF}                       ${URL}/renesas_ra6m5--aws.elf-s_1022068-eb223bcbec23d091f52980a36dea325060d046f7
15
16${CSV2RESD}                         ${RENODETOOLS}/csv2resd/csv2resd.py
17${ICM20948_SAMPLES_CSV}             ${CURDIR}/ICM20948-samples.csv
18
19${RA6M5_REPL}                       platforms/cpus/renesas-r7fa6m5b.repl
20${CK_BOARD_REPL}                    platforms/boards/renesas-ck_ra6m5.repl
21${CK_SCI_SENSORS_BOARD_REPL}        @tests/platforms/renesas-ck_ra6m5-sensors_example.repl
22
23${LED_REPL}                         SEPARATOR=\n
24...                                 """
25...                                 led: Miscellaneous.LED @ port6 10
26...
27...                                 port6:
28...                                 ${SPACE*4}10 -> led@0
29...                                 """
30
31${BUTTON_REPL}                      SEPARATOR=\n
32...                                 """
33...                                 button: Miscellaneous.Button @ port8 4
34...                                 ${SPACE*4}-> port8@4
35...                                 """
36
37*** Keywords ***
38Create Machine
39    [Arguments]                     ${bin}  ${repl}
40    Execute Command                 using sysbus
41    Execute Command                 mach create "ra6m5"
42
43    Execute Command                 machine LoadPlatformDescription @${repl}
44
45    Execute Command                 set bin @${bin}
46    Execute Command                 macro reset "sysbus LoadELF $bin"
47    Execute Command                 runMacro $reset
48
49Prepare Machine
50    [Arguments]                     ${bin}
51    Create Machine                  ${bin}  ${RA6M5_REPL}
52
53Prepare Machine With SCI Sensors Board
54    [Arguments]                     ${bin}
55    Create Machine                  ${bin}  ${CK_SCI_SENSORS_BOARD_REPL}
56
57Prepare Machine With CK Board
58    [Arguments]                     ${bin}
59    Create Machine                  ${bin}  ${CK_BOARD_REPL}
60
61Prepare Segger RTT
62    [Arguments]                     ${with_has_key}=False  ${with_read}=False
63    Execute Command                 machine CreateVirtualConsole "segger_rtt"
64    Execute Command                 include @scripts/single-node/segger-rtt.py
65    Execute Command                 setup_segger_rtt sysbus.segger_rtt ${with_has_key} ${with_read}
66    Create Terminal Tester          sysbus.segger_rtt
67
68Prepare LED Tester
69    Execute Command                 machine LoadPlatformDescriptionFromString ${LED_REPL}
70    Create Led Tester               sysbus.port6.led
71
72Prepare UART Tester
73    Create Terminal Tester          sysbus.sci0
74
75Create ICM20948 RESD File
76    [Arguments]                     ${path}
77    ${resd_path}=                   Allocate Temporary File
78    ${args}=                        Catenate  SEPARATOR=,
79    ...                             "--input", r"${path}"
80    ...                             "--map", "angular_rate:angular_rate_x,angular_rate_y,angular_rate_z:x,y,z"
81    ...                             "--map", "acceleration:acceleration_x,acceleration_y,acceleration_z:x,y,z"
82    ...                             "--map", "magnetic_flux_density:magnetic_flux_density_x,magnetic_flux_density_y,magnetic_flux_density_z:x,y,z"
83    ...                             "--start-time", "200000000"
84    ...                             "--frequency", "5"
85    ...                             r"${resd_path}"
86    Evaluate                        subprocess.run([sys.executable, "${CSV2RESD}", ${args}])  sys,subprocess
87    RETURN                          ${resd_path}
88
89*** Test Cases ***
90Should Run Periodically Blink LED
91    Prepare Machine                 ${AGT_ELF}
92    Prepare LED Tester
93    Prepare Segger RTT              with_has_key=True  with_read=True
94
95    Execute Command                 agt0 IRQ AddStateChangedHook "Antmicro.Renode.Logging.Logger.Log(LogLevel.Error, 'AGT0 ' + str(state))"
96    # Timeout is only used for checking whether the IRQ has been handled
97    Create Log Tester               0.001
98
99    # Configuration is roughly in ms
100    Wait For Prompt On Uart         One-shot mode:
101    Write Line To Uart              10  waitForEcho=false
102    Wait For Line On Uart           Time period for one-shot mode timer: 10
103
104    Wait For Prompt On Uart         Periodic mode:
105    Write Line To Uart              5  waitForEcho=false
106    Wait For Line On Uart           Time period for periodic mode timer: 5
107
108    Wait For Prompt On Uart         Enter any key to start or stop the timers
109    Write Line To Uart              waitForEcho=false
110
111    # Timeout is extended by an additional 1ms to account for rounding errors
112    Wait For Log Entry              AGT0 True  level=Error  pauseEmulation=true  timeout=0.011
113    Wait For Log Entry              AGT0 False  level=Error  pauseEmulation=true
114    # move to the begining of a True state
115    Assert Led State                True  timeout=0.01  pauseEmulation=true
116    # Run test for 5 cycles
117    Assert Led Is Blinking          testDuration=0.05  onDuration=0.005  offDuration=0.005  tolerance=0.2  pauseEmulation=true
118    Assert Led State                True  timeout=0.005  pauseEmulation=true
119
120    # Stop timers, clear log tester history and check whether the periodic timer stops
121    Write Line To Uart              waitForEcho=false
122    Wait For Line On Uart           Periodic timer stopped. Enter any key to start timers.  pauseEmulation=true
123    Assert And Hold Led State       True  0.0  0.05
124
125Should Run Hello World Demo
126    Prepare Machine                 ${HELLO_WORLD_ELF}
127    Execute Command                 machine LoadPlatformDescriptionFromString ${BUTTON_REPL}
128    Prepare UART Tester
129
130    Start Emulation
131    Wait For Line On Uart           Hello world!
132    Wait For Line On Uart           Blinking available LEDs with 1Hz frequency: P1546, P1545, P1537, P1538, P1539, P1541
133    Wait For Line On Uart           LEDS OFF
134    Wait For Line On Uart           LEDS ON
135    Wait For Line On Uart           LEDS OFF
136    Wait For Line On Uart           LEDS ON
137
138    # Test GPIO IRQ, button (PORT8.4) allows to toggle blinking
139
140    # Stop blinking
141    Execute Command                 port8.button PressAndRelease
142    Wait For Line On Uart           Blinking has been disabled
143    # LEDS OFF and LEDS ON messages shouldn't be printed anymore
144    Should Not Be On Uart           LEDS OFF  timeout=1
145    Should Not Be On Uart           LEDS ON  timeout=1
146
147    # Star blinking again
148    Execute Command                 port8.button PressAndRelease
149    Wait For Line On Uart           Blinking has been enabled
150    Wait For Line On Uart           LEDS OFF
151    Wait For Line On Uart           LEDS ON
152    Wait For Line On Uart           LEDS OFF
153    Wait For Line On Uart           LEDS ON
154
155Should Get Correct Temperature Readouts From ICP10101
156    Prepare Machine With SCI Sensors Board  ${AWS_SCI_ICP10101_ELF}
157    Prepare SEGGER_RTT
158
159    Start Emulation
160    Wait For Line On Uart           Renesas FSP Application Project
161    Wait For Line On Uart           I2C bus setup success
162    Wait For Line On Uart           ICP Sensor Data
163    Wait For Line On Uart           Temperature -000.000
164    Wait For Line On Uart           Pressure\\s+ 29999.820  treatAsRegex=true
165
166    Execute Command                 sysbus.sci0.barometer_sci DefaultTemperature 13.5
167    Execute Command                 sysbus.sci0.barometer_sci DefaultPressure 40000
168    Wait For Line On Uart           Temperature\\s+013.498  treatAsRegex=true
169    Wait For Line On Uart           Pressure\\s+ 39999.929  treatAsRegex=true
170
171Should Get Correct Readouts from the HS3001
172
173    Prepare Machine With SCI Sensors Board  ${AWS_SCI_HS3001_ELF}
174    Prepare SEGGER RTT
175
176    # Due to rounding precision, some errors in the measured values are expected
177    Wait For Line On Uart           HS3001 sensor setup success
178    Wait For Line On Uart           HS3001 Sensor Data
179    Wait For Line On Uart           Temperature:\\s+000.000  treatAsRegex=true
180    Wait For Line On Uart           Humidity:\\s+000.000  treatAsRegex=true
181
182    Execute Command                 sysbus.sci0.hs3001_sci Temperature 13.5
183    Execute Command                 sysbus.sci0.hs3001_sci Humidity 50
184    Wait For Line On Uart           Temperature:\\s+013.500  treatAsRegex=true
185    Wait For Line On Uart           Humidity:\\s+050.099  treatAsRegex=true
186
187    Execute Command                 sysbus.sci0.hs3001_sci Temperature -40
188    Wait For Line On Uart           Temperature:\\s-039.950  treatAsRegex=true
189    Wait For Line On Uart           Humidity:\\s+050.099  treatAsRegex=true
190
191    Execute Command                 sysbus.sci0.hs3001_sci Temperature 125
192    Execute Command                 sysbus.sci0.hs3001_sci Humidity 100
193    Wait For Line On Uart           Temperature:\\s+125.000  treatAsRegex=true
194    Wait For Line On Uart           Humidity:\\s+100.000  treatAsRegex=true
195
196Should Read From The ZMOD4510 Sensor
197    Prepare Machine With SCI Sensors Board           ${AWS_ZMOD4510_ELF}
198    Prepare SEGGER_RTT
199
200    Wait For Line On Uart           ZMOD4510 sensor setup success
201    # Sensor readouts depend on the "InitConfigurationRValue", "Rvalue" and "Configuration".
202    # This test uses the default values, but it can be set using those properties
203    # As the algorithm for calculating the final result is proprietary, we expose a way of providing the complete RField input vector
204    Wait For Line On Uart           OAQ: 231.935
205    Wait For Line On Uart           OAQ: 099.132
206
207Should Read From The ZMOD4410 Sensor
208    Prepare Machine With SCI Sensors Board           ${AWS_ZMOD4410_ELF}
209    Prepare SEGGER_RTT
210
211    Wait For Line On Uart         ZMOD4410 sensor setup success
212    # Sensor readouts depend on the "InitConfigurationRValue", "Rvalue" , "ProductionData" and "Configuration".
213    # This test uses the default values, but it can be set using those properties
214    # As the algorithm for calculating the final result is proprietary, we expose a way of providing the complete RField input vector
215    Wait For Line On Uart         TVOC: 000.014
216    Wait For Line On Uart         ETOH: 000.007
217    Wait For Line On Uart         ECO2: 401.176
218    # Readouts should soon stabilize
219    Wait For Line On Uart         TVOC: 000.015
220    Wait For Line On Uart         ETOH: 000.008
221    Wait For Line On Uart         ECO2: 404.523
222
223Should Read Temperature From SPI Sensor
224    Prepare Machine                 ${SCI_SPI_ELF}
225    Prepare Segger RTT
226
227    # Sample expects the MAX31723PMB1 temperature sensor which there is no model for in Renode
228    Execute Command                 machine LoadPlatformDescriptionFromString "sensor: Sensors.GenericSPISensor @ sci0"
229
230    # Sensor initialization values
231    Execute Command                 sci0.sensor FeedSample 0x80
232    Execute Command                 sci0.sensor FeedSample 0x6
233    Execute Command                 sci0.sensor FeedSample 0x0
234
235    # Temperature of 15 °C
236    Execute Command                 sci0.sensor FeedSample 0x0
237    Execute Command                 sci0.sensor FeedSample 0xF
238    Execute Command                 sci0.sensor FeedSample 0x0
239
240    # Temperature of 10 °C
241    Execute Command                 sci0.sensor FeedSample 0x0
242    Execute Command                 sci0.sensor FeedSample 0xA
243    Execute Command                 sci0.sensor FeedSample 0x0
244
245    # Temperature of 2 °C
246    Execute Command                 sci0.sensor FeedSample 0x0
247    Execute Command                 sci0.sensor FeedSample 0x2
248    Execute Command                 sci0.sensor FeedSample 0x0
249
250    Wait For Line On Uart           Temperature:${SPACE*2}15.000000 *C
251    Wait For Line On Uart           Temperature:${SPACE*2}10.000000 *C
252    Wait For Line On Uart           Temperature:${SPACE*2}2.000000 *C
253    Wait For Line On Uart           Temperature:${SPACE*2}0.000000 *C
254
255Should Read And Write On UART
256    Prepare Machine                 ${SCI_UART_ELF}
257
258    Create Terminal Tester          sysbus.sci0
259
260    Wait For Line On Uart           Starting UART demo
261
262    Write Line To Uart              56  waitForEcho=false
263    Wait For Line On Uart           Setting intensity to: 56
264    Wait For Line On Uart           Set next value
265
266    Write Line To Uart              1  waitForEcho=false
267    Wait For Line On Uart           Setting intensity to: 1
268    Wait For Line On Uart           Set next value
269
270    Write Line To Uart              100  waitForEcho=false
271    Wait For Line On Uart           Setting intensity to: 100
272    Wait For Line On Uart           Set next value
273
274    Write Line To Uart              371  waitForEcho=false
275    Wait For Line On Uart           Invalid input. Input range is from 1 - 100
276
277    Write Line To Uart              74  waitForEcho=false
278    Wait For Line On Uart           Setting intensity to: 74
279    Wait For Line On Uart           Set next value
280
281Should Read Default Values From ICM20948
282    Prepare Machine With SCI Sensors Board  ${AWS_ICM20948_ELF}
283    Prepare Segger RTT
284
285    Execute Command                 sci0.icm_sci DefaultAccelerationX 0.3183098861837907
286    Execute Command                 sci0.icm_sci DefaultAccelerationY 1.618033988749895
287    Execute Command                 sci0.icm_sci DefaultAccelerationZ -0.36787944117144233
288
289    Execute Command                 sci0.icm_sci DefaultAngularRateX 10.604
290    Execute Command                 sci0.icm_sci DefaultAngularRateY 200.002
291    Execute Command                 sci0.icm_sci DefaultAngularRateZ -3.1
292
293    Execute Command                 sysbus.sci0.icm_sci.magnetometer_sci DefaultMagneticFluxDensityX 150
294    Execute Command                 sysbus.sci0.icm_sci.magnetometer_sci DefaultMagneticFluxDensityY 300
295    Execute Command                 sysbus.sci0.icm_sci.magnetometer_sci DefaultMagneticFluxDensityZ 450
296
297    Wait For Line On Uart           ICM Sensor Data
298    Wait For Line On Uart           AccX 000.318
299    Wait For Line On Uart           AccY 001.618
300    Wait For Line On Uart           AccZ -000.367
301
302    Wait For Line On Uart           GyrX 010.597
303    Wait For Line On Uart           GyrY 199.890
304    Wait For Line On Uart           GyrZ -003.097
305
306    Wait For Line On Uart           MagX 000.149
307    Wait For Line On Uart           MagY 000.298
308    Wait For Line On Uart           MagZ 000.448
309
310
311Should Read Values From ICM20948 Fed From RESD File
312    Prepare Machine With SCI Sensors Board  ${AWS_ICM20948_ELF}
313    Prepare Segger RTT
314
315    ${resd_path}=                   Create ICM20948 RESD File  ${ICM20948_SAMPLES_CSV}
316    Execute Command                 sysbus.sci0.icm_sci FeedAccelerationSamplesFromRESD @${resd_path}
317    Execute Command                 sysbus.sci0.icm_sci FeedAngularRateSamplesFromRESD @${resd_path}
318    Execute Command                 sysbus.sci0.icm_sci.magnetometer_sci FeedMagneticSamplesFromRESD @${resd_path}
319
320    Wait For Line On Uart           ICM Sensor Data
321    Wait For Line On Uart           AccX 000.001
322    Wait For Line On Uart           AccY 001.002
323    Wait For Line On Uart           AccZ -004.000
324
325    Wait For Line On Uart           GyrX 249.862
326    Wait For Line On Uart           GyrY -249.862
327    Wait For Line On Uart           GyrZ 003.143
328
329    Wait For Line On Uart           MagX 000.149
330    Wait For Line On Uart           MagY 000.298
331    Wait For Line On Uart           MagZ 000.448
332
333    Wait For Line On Uart           ICM Sensor Data
334    Wait For Line On Uart           AccX 000.002
335    Wait For Line On Uart           AccY 000.998
336    Wait For Line On Uart           AccZ 003.999
337
338    Wait For Line On Uart           GyrX 243.499
339    Wait For Line On Uart           GyrY -249.549
340    Wait For Line On Uart           GyrZ 003.280
341
342    Wait For Line On Uart           MagX 000.298
343    Wait For Line On Uart           MagY 000.448
344    Wait For Line On Uart           MagZ 000.597
345
346Should Communicate Over IIC
347    Prepare Machine                 ${IIC_MASTER_ELF}
348    Execute Command                 machine LoadPlatformDescriptionFromString "adxl345: Sensors.ADXL345 @ iic1 0x1D"
349    Prepare Segger RTT
350
351    # Sample displays raw data from the sensor, so printed values are different from loaded samples
352    Execute Command                 iic1.adxl345 FeedSample 1000 1000 1000
353    Wait For Line On Uart           X-axis = 250.00, Y-axis = 250.00, Z-axis = 250.00
354
355    Execute Command                 iic1.adxl345 FeedSample 2000 3000 4000
356    Wait For Line On Uart           X-axis = 500.00, Y-axis = 750.00, Z-axis = 1000.00
357
358    Execute Command                 iic1.adxl345 FeedSample 1468 745 8921
359    Wait For Line On Uart           X-axis = 367.00, Y-axis = 186.00, Z-axis = 2230.00
360
361    Execute Command                 iic1.adxl345 FeedSample 3912 8888 5456
362    Wait For Line On Uart           X-axis = 978.00, Y-axis = 2222.00, Z-axis = 1364.00
363
364    Execute Command                 iic1.adxl345 FeedSample 0 5000 0
365    Wait For Line On Uart           X-axis = 0.00, Y-axis = 1250.00, Z-axis = 0.00
366
367    Wait For Line On Uart           X-axis = 0.00, Y-axis = 0.00, Z-axis = 0.00
368
369CK IIC Board Should Work
370    Prepare Machine With CK Board   ${AWS_CC_ELF}
371    Prepare Segger RTT
372
373    Execute Command                 sysbus.iic0.hs3001 Temperature 13.5
374    Execute Command                 sysbus.iic0.hs3001 Humidity 50
375
376    Execute Command                 sysbus.iic0.barometer DefaultTemperature 13.5
377    Execute Command                 sysbus.iic0.barometer DefaultPressure 40000
378
379    Execute Command                 sysbus.iic0.icm DefaultAccelerationX 0.3183098861837907
380    Execute Command                 sysbus.iic0.icm DefaultAccelerationY 1.618033988749895
381    Execute Command                 sysbus.iic0.icm DefaultAccelerationZ -0.36787944117144233
382
383    Execute Command                 sysbus.iic0.icm DefaultAngularRateX 10.604
384    Execute Command                 sysbus.iic0.icm DefaultAngularRateY 200.002
385    Execute Command                 sysbus.iic0.icm DefaultAngularRateZ -3.1
386
387    Execute Command                 sysbus.iic0.icm.magnetometer DefaultMagneticFluxDensityX 150
388    Execute Command                 sysbus.iic0.icm.magnetometer DefaultMagneticFluxDensityY 300
389    Execute Command                 sysbus.iic0.icm.magnetometer DefaultMagneticFluxDensityZ 450
390
391    Wait For Line On Uart           IAQ Sensor Data
392    Wait For Line On Uart           TVOC: 000.015
393    Wait For Line On Uart           ETOH: 000.008
394    Wait For Line On Uart           ECO2: 404.384
395
396    Wait For Line On Uart           OAQ Sensor Data
397    Wait For Line On Uart           OAQ: 231.935
398
399    Wait For Line On Uart           HS3001 Sensor Data
400    Wait For Line On Uart           Humidity: 050.099
401    Wait For Line On Uart           Temperature: 013.500
402
403    Wait For Line On Uart           ICM Sensor Data
404    Wait For Line On Uart           AccX 000.318
405    Wait For Line On Uart           AccY 001.618
406    Wait For Line On Uart           AccZ -000.367
407
408    Wait For Line On Uart           GyrX 010.597
409    Wait For Line On Uart           GyrY 199.890
410    Wait For Line On Uart           GyrZ -003.097
411
412    Wait For Line On Uart           MagX 000.149
413    Wait For Line On Uart           MagY 000.298
414    Wait For Line On Uart           MagZ 000.448
415
416    Wait For Line On Uart           ICP Sensor Data
417    Wait For Line On Uart           Temperature: 013.498
418    Wait For Line On Uart           Pressure: 39999.929
419