Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e2eb38

Browse files
committed
[drv] Fix CMD18 issue of SD driver
[ulog] Fix line ending issue
1 parent 3fec906 commit 1e2eb38

File tree

14 files changed

+68
-56
lines changed

14 files changed

+68
-56
lines changed

‎examples/Blink/Blink.ino‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void rt_setup(void) {
4242
void setup() {
4343
pinMode(LED_BUILTIN, OUTPUT);
4444
RT_T.begin();
45+
// no code here as RT_T.begin() never return
4546
}
4647

4748
// this function will be called by "Arduino" thread

‎examples/DataLogger/DataLogger.ino‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ void rt_setup(void) {
66

77
void setup() {
88
RT_T.begin();
9+
// no code here as RT_T.begin() never return
910
}
1011

1112
// this function will be called by "Arduino" thread

‎examples/FinSH/FinSH.ino‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern "C" {
8686
void setup() {
8787
pinMode(LED_BUILTIN, OUTPUT);
8888
RT_T.begin();
89+
// no code here as RT_T.begin() never return
8990
}
9091

9192
// this function will be called by "Arduino" thread

‎examples/RttMutex/RttMutex.ino‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void rt_setup(void) {
6363

6464
void setup() {
6565
RT_T.begin();
66+
// no code here as RT_T.begin() never return
6667
}
6768

6869
// this function will be called by "Arduino" thread

‎examples/SysLog/SysLog.ino‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void rt_setup(void) {
2020

2121
void setup() {
2222
RT_T.begin();
23+
// no code here as RT_T.begin() never return
2324
}
2425

2526
// this function will be called by "Arduino" thread

‎library.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=RT-Thread
2-
version=0.5.0
2+
version=0.5.1
33
author=Bernard Xiong <bernard.xiong@gmail.com>, onelife <onelife.real@gmail.com>
44
maintainer=onelife <onelife.real@gmail.com>
55
sentence=Real Time Operating System porting for Arduino SAM and SAMD boards

‎src/components/arduino/drv_spi.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
# define LOG_TAG "SPI"
3535
# include "components/utilities/ulog/ulog.h"
3636
#else /* RT_USING_ULOG */
37-
# define LOG_E rt_kprintf
37+
# define LOG_E(format, args...) rt_kprintf(format "\n", ##args)
3838
# ifdef BSP_SPI_DEBUG
3939
# define LOG_D(format, args...) rt_kprintf(format "\n", ##args)
4040
# else
@@ -101,7 +101,7 @@ static rt_err_t bsp_spi_open(rt_device_t dev, rt_uint16_t oflag) {
101101
} while (0);
102102

103103
if (RT_EOK != ret) {
104-
LOG_D("[SPI%d E] open failed [%08x]", ctx->chn, ret);
104+
LOG_W("[SPI%d E] open failed [%08x]", ctx->chn, ret);
105105
}
106106
return ret;
107107
}
@@ -118,7 +118,7 @@ static rt_err_t bsp_spi_close(rt_device_t dev) {
118118
} while (0);
119119

120120
if (RT_EOK != ret) {
121-
LOG_D("[SPI%d E] close failed [%08x]", ctx->chn, ret);
121+
LOG_W("[SPI%d E] close failed [%08x]", ctx->chn, ret);
122122
}
123123
return ret;
124124
}
@@ -172,7 +172,7 @@ static rt_size_t bsp_spi_read(rt_device_t dev, rt_off_t token, void *buf,
172172
if (i >= SPI_DEFAULT_RETRY) {
173173
SPI_STOP(ctx);
174174
err = -RT_EBUSY;
175-
LOG_D("[SPI%d E] read busy", ctx->chn);
175+
LOG_W("[SPI%d E] read busy", ctx->chn);
176176
break;
177177
}
178178

@@ -189,7 +189,7 @@ static rt_size_t bsp_spi_read(rt_device_t dev, rt_off_t token, void *buf,
189189
if (i >= SPI_DEFAULT_RETRY) {
190190
SPI_STOP(ctx);
191191
err = -RT_EIO;
192-
LOG_D("[SPI%d E] no token", ctx->chn);
192+
LOG_W("[SPI%d E] no token", ctx->chn);
193193
break;
194194
}
195195
}
@@ -248,7 +248,7 @@ static rt_size_t bsp_spi_write(rt_device_t dev, rt_off_t pos, const void *buf,
248248
if (i >= SPI_DEFAULT_RETRY) {
249249
SPI_STOP(ctx);
250250
err = -RT_EBUSY;
251-
LOG_D("[SPI%d E] write busy", ctx->chn);
251+
LOG_W("[SPI%d E] write busy", ctx->chn);
252252
break;
253253
}
254254

‎src/components/arduino/drv_spisd.cpp‎

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern "C" {
3535
# define LOG_TAG "SD"
3636
# include "components/utilities/ulog/ulog.h"
3737
#else /* RT_USING_ULOG */
38-
# define LOG_E rt_kprintf
38+
# define LOG_E(format, args...) rt_kprintf(format "\n", ##args)
3939
# ifdef BSP_SD_DEBUG
4040
# define LOG_D(format, args...) rt_kprintf(format "\n", ##args)
4141
# else
@@ -89,7 +89,6 @@ static rt_uint16_t _sd_send_cmd(struct bsp_sd_contex *ctx, rt_uint8_t cmd,
8989
do {
9090
rt_size_t read_len;
9191
rt_uint8_t len_trl, i, j;
92-
rt_bool_t skip;
9392

9493
/* build cmd inst
9594
- inst len: 6
@@ -138,32 +137,33 @@ static rt_uint16_t _sd_send_cmd(struct bsp_sd_contex *ctx, rt_uint8_t cmd,
138137
tmp[j+4], tmp[j+5], tmp[j+6], tmp[j+7]);
139138
# endif
140139
#endif
141-
LOG_D("[SD E] send cmd failed! [%d]", read_len);
140+
LOG_W("[SD E] send cmd failed! [%d]", read_len);
142141
break;
143142
}
144143

145-
/* skip one byte when stop reading */
146-
skip = (cmd == CMD12) ? RT_TRUE : RT_FALSE;
147-
148144
/* find valid response: the response is read back within command
149145
response time (NCR), 0 to 8 bytes for SDC, 1 to 8 bytes for MMC */
150146
for (i = 0; i < sizeof(buf_res); i++) {
151147
if (0xff != buf_res[i]) {
152-
if (skip) {
153-
LOG_D("[SD] skip %02x (@ %d)", buf_res[i], i);
154-
skip = RT_FALSE;
155-
continue;
148+
if (cmd == CMD12) {
149+
/* may skip one byte when stop reading */
150+
if (((i + 1u) < sizeof(buf_res)) && \
151+
(0xff != buf_res[i + 1u])) {
152+
LOG_D("[SD] >>>skip %02x (@ %d)", buf_res[i], i);
153+
i++;
154+
}
156155
}
157-
if (cmd == (ACMD13 & 0x7f))
156+
if (cmd == (ACMD13 & 0x7f)) {
158157
ret = (rt_uint16_t)buf_res[i]; /* R2 response */
159-
else
158+
} else {
160159
ret = (rt_uint8_t)buf_res[i];
160+
}
161161
break;
162162
}
163163
}
164164
LOG_D("[SD] response %02x (@ %d)", ret, i);
165165
i++;
166-
166+
167167
/* copy trailing data */
168168
if ((0xffff != ret) && len_trl && trail) {
169169
/* read CSD/CID */
@@ -173,7 +173,7 @@ static rt_uint16_t _sd_send_cmd(struct bsp_sd_contex *ctx, rt_uint8_t cmd,
173173
if (buf_res[i] == 0xfe) break;
174174
/* check if valid */
175175
if (sizeof(buf_res) <= i) {
176-
LOG_D("[SD E] no CSD/CID!");
176+
LOG_W("[SD E] no CSD/CID!");
177177
ret = 0xffff;
178178
break;
179179
}
@@ -220,7 +220,7 @@ rt_uint16_t sd_send_cmd(struct bsp_sd_contex *ctx, rt_uint8_t cmd,
220220
static rt_err_t sd_read_block(struct bsp_sd_contex *ctx, void *buf,
221221
rt_size_t size) {
222222
rt_uint8_t buf_ins[RT_ALIGN(5, RT_ALIGN_SIZE)];
223-
rt_uint8_t buf_res[8];
223+
//rt_uint8_t buf_res[8];
224224
rt_err_t ret;
225225

226226
LOG_D("[SD] read block [%d]", size);
@@ -241,11 +241,15 @@ static rt_err_t sd_read_block(struct bsp_sd_contex *ctx, void *buf,
241241
/* read with token (starting indicator) 0xfe */
242242
read_len = rt_device_read(ctx->ldev, 0xfe, buf_ins, size);
243243
if (0 == read_len) {
244-
LOG_D("[SD E] read data failed!");
244+
LOG_W("[SD E] read data failed!");
245245
ret = -RT_EIO;
246246
break;
247247
}
248248

249+
/* it seems if read a response by two separate calls, some bytes will be
250+
ate by SPI library.
251+
*/
252+
#if 0
249253
/* build read CRC inst
250254
- inst len: 0
251255
- rx buf addr: offset align with RT_ALIGN_SIZE
@@ -257,17 +261,18 @@ static rt_err_t sd_read_block(struct bsp_sd_contex *ctx, void *buf,
257261

258262
read_len = rt_device_read(ctx->ldev, 0, buf_ins, sizeof(buf_res));
259263
if (0 == read_len) {
260-
LOG_D("[SD E] read CRC failed!");
264+
LOG_W("[SD E] read CRC failed!");
261265
ret = -RT_EIO;
262266
break;
263267
}
264268
LOG_D("[SD] read CRC %x %x", buf_res[0], buf_res[1]);
269+
#endif
265270

266271
ret = RT_EOK;
267272
} while(0);
268273

269274
if (RT_EOK != ret) {
270-
LOG_D("[SD E] read block failed! [%02x]", ret);
275+
LOG_W("[SD E] read block failed! [%02x]", ret);
271276
}
272277
return ret;
273278
}
@@ -312,7 +317,7 @@ static rt_size_t sd_read(struct bsp_sd_contex *ctx, void *buf, rt_size_t size) {
312317
tmp[j+4], tmp[j+5], tmp[j+6], tmp[j+7]);
313318
# endif
314319
#endif
315-
LOG_D("[SD E] read raw failed! [%d]", ret);
320+
LOG_W("[SD E] read raw failed! [%d]", ret);
316321
}
317322

318323
return ret;
@@ -352,7 +357,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
352357
SD_STOP_TIMER(ctx);
353358

354359
if (0xff != buf_res[sizeof(buf_res) - 1]) {
355-
LOG_D("[SD E] SD busy b/f write! [%02x]", \
360+
LOG_W("[SD E] SD busy b/f write! [%02x]", \
356361
buf_res[sizeof(buf_res) - 1]);
357362
ret = -RT_EBUSY;
358363
break;
@@ -375,7 +380,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
375380

376381
write_len = rt_device_write(ctx->ldev, 0, buf_ins, SD_SECTOR_SIZE);
377382
if (0 == write_len) {
378-
LOG_D("[SD E] write data failed!");
383+
LOG_W("[SD E] write data failed!");
379384
ret = -RT_EIO;
380385
break;
381386
}
@@ -392,7 +397,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
392397

393398
read_len = rt_device_read(ctx->ldev, 0, buf_ins, sizeof(buf_res));
394399
if (0 == read_len) {
395-
LOG_D("[SD E] write CRC failed!");
400+
LOG_W("[SD E] write CRC failed!");
396401
ret = -RT_EIO;
397402
break;
398403
}
@@ -405,7 +410,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
405410
}
406411
}
407412
if (0x05 != buf_res[i]) {
408-
LOG_D("[SD E] write is not accepted! (%02x @ %d)", \
413+
LOG_W("[SD E] write is not accepted! (%02x @ %d)", \
409414
buf_res[i], i);
410415
ret = -RT_EIO;
411416
break;
@@ -427,7 +432,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
427432

428433
write_len = rt_device_write(ctx->ldev, 0, buf_ins, 0);
429434
if (0 != write_len) {
430-
LOG_D("[SD E] write token failed!");
435+
LOG_W("[SD E] write token failed!");
431436
ret = -RT_EIO;
432437
break;
433438
}
@@ -440,7 +445,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
440445
SD_STOP_TIMER(ctx);
441446

442447
if (0xff != buf_res[sizeof(buf_res) - 1]) {
443-
LOG_D("[SD E] SD busy a/f write! [%02x]",
448+
LOG_W("[SD E] SD busy a/f write! [%02x]",
444449
buf_res[sizeof(buf_res) - 1]);
445450
ret = -RT_EBUSY;
446451
break;
@@ -451,7 +456,7 @@ static rt_err_t sd_write_block(struct bsp_sd_contex *ctx, void *buf,
451456
} while (0);
452457

453458
if (RT_EOK != ret) {
454-
LOG_D("[SD E] write block failed! [%02x]", ret);
459+
LOG_W("[SD E] write block failed! [%02x]", ret);
455460
}
456461
return ret;
457462
}
@@ -544,7 +549,7 @@ static rt_err_t bsp_spiSd_init(rt_device_t dev) {
544549
rt_device_close(ctx->ldev);
545550

546551
if (RT_EOK != ret) {
547-
LOG_D("[SD E] init failed! (%08x)", ret);
552+
LOG_W("[SD E] init failed! (%08x)", ret);
548553
}
549554
return ret;
550555
}
@@ -559,6 +564,7 @@ static rt_size_t bsp_spiSd_read(rt_device_t dev, rt_off_t sector, void *buf,
559564
err = rt_device_open(ctx->ldev, RT_DEVICE_OFLAG_RDWR);
560565
if (RT_EOK != err) {
561566
rt_set_errno(err);
567+
LOG_W("[SD] read err %x", err);
562568
return 0;
563569
}
564570
LOG_D("[SD] read sect %d [%d]", sector, count);
@@ -586,7 +592,7 @@ static rt_size_t bsp_spiSd_read(rt_device_t dev, rt_off_t sector, void *buf,
586592
}
587593

588594
if (sd_send_cmd(ctx, cmd, sector, RT_NULL)) {
589-
LOG_D("[SD E] read cmd failed!");
595+
LOG_W("[SD E] read cmd failed!");
590596
err = -RT_EIO;
591597
break;
592598
}
@@ -601,7 +607,7 @@ static rt_size_t bsp_spiSd_read(rt_device_t dev, rt_off_t sector, void *buf,
601607
/* stop transmission */
602608
if (CMD18 == cmd)
603609
if (sd_send_cmd(ctx, CMD12, 0x00000000, RT_NULL)) {
604-
err = -RT_EOK;
610+
err = -RT_EIO;
605611
break;
606612
}
607613

@@ -612,7 +618,7 @@ static rt_size_t bsp_spiSd_read(rt_device_t dev, rt_off_t sector, void *buf,
612618
rt_device_close(ctx->ldev);
613619
if (RT_EOK != err) {
614620
rt_set_errno(err);
615-
LOG_D("[SD E] read failed! [%08x]", err);
621+
LOG_W("[SD E] read failed! [%08x]", err);
616622
}
617623

618624
LOG_D("[SD] read ok! [%d]", ret);
@@ -657,29 +663,29 @@ static rt_size_t bsp_spiSd_write(rt_device_t dev, rt_off_t sector,
657663
LOG_D("[SD] write multiple blocks");
658664
if (ctx->type & CT_SDC)
659665
if (sd_send_cmd(ctx, ACMD23, count, RT_NULL)) {
660-
err = -RT_EOK;
666+
err = -RT_EIO;
661667
break;
662668
}
663669
}
664670

665671
if (sd_send_cmd(ctx, cmd, sector, RT_NULL)) {
666-
LOG_D("[SD E] write command error!");
667-
err = -RT_EOK;
672+
LOG_W("[SD E] write command error!");
673+
err = -RT_EIO;
668674
break;
669675
}
670676

671677
/* write data */
672678
do {
673679
if (sd_write_block(ctx, ptr, token)) {
674-
err = -RT_EOK;
680+
err = -RT_EIO;
675681
break;
676682
}
677683
ptr += SD_SECTOR_SIZE;
678684
} while (--cnt);
679685

680686
/* stop transmission token */
681687
if (sd_write_block(ctx, RT_NULL, 0xfd)) {
682-
err = -RT_EOK;
688+
err = -RT_EIO;
683689
break;
684690
}
685691

@@ -690,7 +696,7 @@ static rt_size_t bsp_spiSd_write(rt_device_t dev, rt_off_t sector,
690696
rt_device_close(ctx->ldev);
691697
if (RT_EOK != err) {
692698
rt_set_errno(err);
693-
LOG_D("[SD E] write failed! [%08x]", err);
699+
LOG_W("[SD E] write failed! [%08x]", err);
694700
}
695701

696702
LOG_D("[SD] write ok! [%d]", ret);
@@ -827,7 +833,7 @@ static rt_err_t bsp_spiSd_control(rt_device_t dev, rt_int32_t cmd, void *buf) {
827833
}
828834

829835
if (RT_EOK != ret) {
830-
LOG_D("[SD E] control failed! [%08x]", ret);
836+
LOG_W("[SD E] control failed! [%08x]", ret);
831837
}
832838
return ret;
833839
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /