Page 5 of 8
Re: SDIO port to STM32F4x
Posted: Fri Mar 30, 2012 9:13 am
by barthess
Thanks for feadback. I will try to reproduce bug on this weekend.
Re: SDIO port to STM32F4x
Posted: Sat Mar 31, 2012 8:15 pm
by barthess
Hi Eric,
Your error looks like false detection of v1.1 card like v2.0. I have no v1.1 card to reproduce and fix bug. Could you do it yourself and submit a patch?
Like written on
http://elm-chan.org/docs/mmc/mmc_e.htmlHow to support SDC Ver2 and high capacity cards
After the card enters idle state with a CMD0, send a CMD8 with argument of 0x000001AA and correct CRC prior to initialization process. When the CMD8 is rejected with an illigal command error (0x05), the card is SDC V1 or MMC. When the CMD8 is accepted, R7 response (R1(0x01) and trailing 32 bit data) will be returned. The lower 12 bits in the return value 0x1AA means that the card is SDC V2 and it can work at voltage range of 2.7 to 3.6 volts. If not the case, the card must be rejected. And then initiate initialization with ACMD41 with HCS (bit 30). After the initialization completed, read OCR register and check CCS (bit 30). When it is set, subsequent data read/write operations that described below are commanded in block address insted of byte address. The block size is always fixed to 512 bytes.
Re: SDIO port to STM32F4x
Posted: Wed Apr 11, 2012 3:12 pm
by efs113
I'll look into this as soon as I can. Unfortunately, both of our prototype boards have experienced hardware problems and it will be another week or two till I have hardware I can test with.
Eric
Re: SDIO port to STM32F4x
Posted: Sun Apr 15, 2012 11:11 am
by Giovanni
Hi,
I haven't studied the code in detail, I trust it just works, I have some notes:
- The new driver defines SDC_SUCCESS/SDC_FAILED macros, the convention in ChibiOS is to simply use a boolean condition for error conditions. This should be respected.
- The driver now has an errors field, probably we should add an sdcGetAndClearErrors() function like other drivers do. In general application should never access driver fields directly.
- I saw in some places mixing uint8_t and unit32_t in expressions, in general this is not a good idea, uint8_t is promoted to uint32_t anyway and the code size could increase and a 32 bits register is allocated for the variable anyway.
- There are small doxygen related problems but those can be fixed after merging.
Are there any other pending problems on this driver? I think that except for the above notes it could be merged.
Giovanni
Re: SDIO port to STM32F4x
Posted: Mon Apr 16, 2012 7:21 pm
by barthess
Giovanni wrote:- I saw in some places mixing uint8_t and unit32_t in expressions, in general this is not a good idea, uint8_t is promoted to uint32_t anyway and the code size could increase and a 32 bits register is allocated for the variable anyway.
Fixed in rev.4098. 16 bytes of flash win with -O2. I remember mixed usage only in line 330 of sdc.c. Are there any more?
Giovanni wrote:- The new driver defines SDC_SUCCESS/SDC_FAILED macros, the convention in ChibiOS is to simply use a boolean condition for error conditions. This should be respected.
That defines significantly increase code readability. What about slightly changing of conventions and introducing of global OS defines like CH_SUCCESS and CH_FAILED?
Giovanni wrote:- The driver now has an errors field, probably we should add an sdcGetAndClearErrors() function like other drivers do. In general application should never access driver fields directly.
Done in rev.4099.
Giovanni wrote:Are there any other pending problems on this driver?
1) I am in doubt about "capacity" field. Probably better to remove it and move capacity calculation code in separate function and call it when needed. Capacity value needs significantly rare and calculation process are not expensive.
2) Eric report some problems with V1.1 card. I can not reproduce and fix it myself due to lack of needed hardware.
Re: SDIO port to STM32F4x
Posted: Mon Apr 16, 2012 7:36 pm
by Giovanni
Hi,
barthess wrote:Fixed in rev.4098. 16 bytes of flash win with -O2. I remember mixed usage only in line 330 of sdc.c. Are there any more?
I remember only that one.
That defines significantly increase code readability. What about slightly changing of conventions and introducing of global OS defines like CH_SUCCESS and CH_FAILED?
The idea is not bad, I was considering that too but is it worth reworking a lot of code because of this? lets keep booleans for the time being and focus on things with higher returns.
Done in rev.4099.
Thanks, I saw the commit, a note, there is no need to implement it in the low level driver, I assume the field "errors" is defined in the standard part of the driver structure.
I am in doubt about "capacity" field. Probably better to remove it and move capacity calculation code in separate function and call it when needed. Capacity value needs significantly rare and calculation process are not expensive.
Good idea, I like the idea sdcGetCapacity() function too or, may be, would be better a function that returns the whole card information block with various "get" macros?
Eric report some problems with V1.1 card. I can not reproduce and fix it myself due to lack of needed hardware.
I don't have one, is it worth waiting for this?
BTW, sorry if this took a while but that OTG driver is driving me nuts and it still has problems.
Giovanni
Re: SDIO port to STM32F4x
Posted: Mon Apr 16, 2012 9:24 pm
by barthess
Giovanni wrote:lets keep booleans for the time being and focus on things with higher returns.
Ok, reverted to boolean values.
Giovanni wrote:is it worth reworking a lot of code because of this?
I think it is. Could you schedule that task somewhere in timeline in TODO list?
Giovanni wrote: I assume the field "errors" is defined in the standard part of the driver structure.
Fixed.
Giovanni wrote:Good idea, I like the idea sdcGetCapacity() function too or
Too much time has passed since I wrote code, much has been forgotten. Driver checks capacity every read/write access to card (not only in diskio.c during card mounting). I think that having of cached value in driver structure is better decision.
Giovanni wrote:the whole card information block with various "get" macros?
IMO overkill. Some fields in information block are meaningless at all, some unneeded by current driver realization. I propose to add features just as needed in future.
Giovanni wrote:I don't have one, is it worth waiting for this?
No, it is not. It can be easy (without compatibility breaks) fixed in future.
Good night.
Re: SDIO port to STM32F4x
Posted: Tue Apr 17, 2012 2:10 pm
by Giovanni
I think it is. Could you schedule that task somewhere in timeline in TODO list?
Thinking again, there is no need to put it in the to-do list, we can keep bool_t as return type and simply add the constant CH_FAILED and CH_SUCCESS as redefinitions of TRUE and FALSE in ch.h, simple and zero effort.
Re: SDIO port to STM32F4x
Posted: Tue Apr 17, 2012 3:41 pm
by efs113
New boards will be done in a week or so. I'll do some further testing/debugging when they arrive.
In regards to CH_SUCCESS/CH_FAILURE, booleans can lead to confusing code. While reviewing chibios code, I was confused by:
I initially interrpreted this as disabling the RCC which is wrong.
Code: Select all
rccEnable<func>(LOW_POWER_MODE_ON);
rccEnable<func>(LOW_POWER_MODE_OFF);
Would have eliminated the confusion. Just something to think about when designing APIs.
Eric
Re: SDIO port to STM32F4x
Posted: Tue Apr 17, 2012 5:43 pm
by mabl
Hi Eric,
you are right, this also got me once. Generally I think an API should not use Boolean as function parameter, rather two separated functions should be used in general.