<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1652709#M206074</link>
    <description>&lt;P&gt;I think I may have (finally) found the fix. I had to &lt;STRONG&gt;remove&lt;/STRONG&gt; the entire reset logic for it to work i.e.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;remove hardware reset&lt;/STRONG&gt; or power-cycling logic (this was done by muxing the uSDHC2’s RESET line to gpio-mode and toggling gpio pin 19 to power-cycle the sd-card) and&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;remove software reset&lt;/STRONG&gt; logic (performed by setting RSTA)&lt;/LI&gt;&lt;LI&gt;and set the reset line’s mux-mode to uSDHC-mode.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;and it magically started working.&lt;BR /&gt;&lt;BR /&gt;I still have to no idea &lt;STRONG&gt;why this works?&lt;/STRONG&gt; I hope &lt;EM&gt;NXP can explain&lt;/EM&gt; why this works? But until then, my best guess is that the &lt;STRONG&gt;i.MX 8M Nano EVK board&lt;/STRONG&gt; deviates from both the SD spec and the reference manual.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If anyone wants to test this. Please clone the latest (master) commit, build and flash. You should see debug output below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ 0.000005] imx8mn-rs version 0.1.0
[ 0.003617] Booting on: [i.MX](https://i.mx/) 8M Nano EVK
[ 0.007682] Current privilege level: EL3
[ 0.011755] Exception handling state:
[ 0.015561] Debug: Masked
[ 0.018894] SError: Unmasked
[ 0.022413] IRQ: Masked
[ 0.025746] FIQ: Masked
[ 0.028993] Drivers loaded:
[ 0.031841] 1. i.MX8M Uart2
[ 0.035289] Chars written: 382
[ 0.038436] uSDHC2 supports 1.8v, 3.0v, 3.3v ...
[ 0.043311] NO RESET, PRES_STAT: 0xff8d8088
...
[ 0.050676] NO RSTA, PRES_STAT: 0xff8d8088
...
[ 0.082844] Sd clock stablized in 37us
[ 0.086777] Prescaler = 64, Divisor = 16, Freq = 390625 Hz
...
[ 0.108591] before CMD0 sent, PRES_STAT: 0xff8d8088
[ 0.113783] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[ 0.126803] Sd: sending command, CMD_NAME: "SEND_IF_COND", CMD_CODE: 0x081a0000, CMD_ARG: 0x000001aa
[ 0.137920] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.148645] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.560598] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.571475] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.583475] Sd: sending command, CMD_NAME: "ALL_SEND_CID", CMD_CODE: 0x02090000, CMD_ARG: 0x00000000
[ 0.595085] Sd: sending command, CMD_NAME: "SEND_REL_ADDR", CMD_CODE: 0x03020000, CMD_ARG: 0x00000000
[ 0.606431] Sd: sending command, CMD_NAME: "SEND_CSD", CMD_CODE: 0x09010000, CMD_ARG: 0x00010000
[ 0.617763] CSD Contents : 00 40 0e 00 32 5b 59 00 003b 83 7f 80 0a 40 00
[ 0.624947] cemmc_structure=1, spec_vers=0, taac=0x0E, nsac=0x00, tran_speed=0x32,ccc=0x05B5, read_bl_len=0x09, read_bl_partial=0b, write_blk_misalign=0b,read_blk_mi
salign=0b, dsr_imp=0b, sector_size =0x7F, erase_blk_en=1b
[ 0.645753] CSD 2.0: ver2_c_size = 0x3BFF, card capacity: 7987527680 bytes or 7.99GiB
[ 0.654006] wp_grp_size=0x0000000b, wp_grp_enable=0b, default_ecc=00b, r2w_factor=010b, write_bl_len=0x09, write_bl_partial=0b, file_format_grp=0, copy=0b, perm_writ
e_protect=0b, tmp_write_protect=0b, file_format=0b ecc=00b&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2023 03:13:51 GMT</pubDate>
    <dc:creator>npashi</dc:creator>
    <dc:date>2023-05-18T03:13:51Z</dc:date>
    <item>
      <title>Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1623344#M203357</link>
      <description>&lt;P&gt;I've been working on adding &lt;STRONG&gt;Rust&lt;/STRONG&gt; support for the i.MX 8M nano and managed to get the board up and running along with a working uart driver - code &lt;A href="https://github.com/nihalpasham/rustBoot/tree/main/boards/bootloaders/imx8mn" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The next step in my plan is to add a uSDHC driver for the nano. Here's a link to the initial &lt;A href="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/drivers/usdhc.rs" target="_self"&gt;implementation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The implementation keeps throwing some i.MX specific uSDHC &lt;U&gt;command&lt;/U&gt; errors. I was hoping someone here can shed some light on this.&lt;/P&gt;&lt;P&gt;The sequence of steps I used are as follows&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;enable the usdhc2 clocks via the ccm peripheral,&lt;/LI&gt;&lt;LI&gt;set mux state for the uSDHC2 peripheral via the iomuxc peripheral&lt;/LI&gt;&lt;LI&gt;&lt;DIV&gt;initialize uSDHC driver and send a couple of commands to verify we have working driver&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;So far, steps 1 and 2 seem to work (i think)&lt;/P&gt;&lt;P&gt;Here's the debug log output. From what I gather by looking at the contents of the uSDHC's interrupt status field (i.e. a value of &lt;U&gt;0x00048001&lt;/U&gt;), the command (i.e. SEND_IF_CMD) was successfully sent and a response was received, however the response returned contains an error - &lt;STRONG&gt;command end bit error. &lt;/STRONG&gt;Not entirely sure why this is happening. &lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Also the present status register has the &lt;SPAN&gt;SDOFF bit set (SD clock gated off internally). Again not sure why this is happening. The reference manual doesn't provide more information about these bits or the errors. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any inputs would be greatly appreciated. Please let me know if more information is required.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[    0.000004] imx8mn-rs version 0.1.0
[    0.003516] Booting on: i.MX 8M Nano EVK
[    0.007340] Current privilege level: EL3
[    0.011254] Exception handling state:
[    0.014966]       Debug:  Masked
[    0.018166]       SError: Unmasked
[    0.021464]       IRQ:    Masked
[    0.024758]       FIQ:    Masked
[    0.027968] Drivers loaded:
[    0.030739]       1. i.MX8M Uart2
[    0.034045] Chars written: 382
[    0.036995] Sd host circuit reset..
[    0.040462] Prescaler = 4, Divisor = 15, Freq Set = 400000
[    0.045966] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[    0.056378] Sd: sending command, CMD_NAME: "SEND_IF_COND", CMD_CODE: 0x08020000, CMD_ARG: 0x000001aa
[    0.066602] Sd Error: Cmd response returned an error, PresentStatus: 0xf0048088, intStatus: 0x00048001, Resp0: 0x00000000, timeDiff: 0

[    0.078923] Sd host circuit reset..
[    0.082293] Prescaler = 4, Divisor = 15, Freq Set = 400000
[    0.087788] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[    0.098218] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x17000000, CMD_ARG: 0x00000000
[    0.108176] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x09020000, CMD_ARG: 0x00ff8000
[    0.119630] Sd Error: Cmd response returned an error, PresentStatus: 0xf0048088, intStatus: 0x00048001, Resp0: 0x00000000, timeDiff: 0

[    0.131839] Sd Error: ACMD41 returned non-timeout error SdError

[    0.137829] uSDHC: PRES_STATE: 0xf0048088, SYS_CTRL: 0x000e02e0, INT_STATUS: 0x00048001

[    0.146063] uSDHC: CMD "APP_SEND_OP_COND", resp: SdError, CMD_RSP3: 0x00000000, CMD_RSP2: 0x00000000, CMD_RSP1: 0x00000000, CMD_RSP0: 0x00000000

[    0.159382] failed to initialize
[    0.162494]

[    0.164107]  ... wait forever&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 12:14:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1623344#M203357</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-03-28T12:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1624408#M203427</link>
      <description>&lt;DIV&gt;&lt;STRONG&gt;Update: &lt;/STRONG&gt;I think I made some headway but the error still seems baffling. &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So, I used the (exact) same &lt;STRONG&gt;pad-ctrl&lt;/STRONG&gt;&amp;nbsp;settings as the ones from the linux device tree in `imx8mn.dtsi` and I am now able to detect and report if an sd-card is inserted. But I still cant figure out what's causing the command error (i.e. &lt;STRONG&gt;CEBE bit error&lt;/STRONG&gt;).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[   71.987092] imx8mn-rs version 0.1.0
[   71.990506] Booting on: i.MX 8M Nano EVK
[   71.994481] Current privilege level: EL3
[   71.998294] Exception handling state:
[   72.002008]       Debug:  Masked
[   72.005139]       SError: Unmasked
[   72.008524]       IRQ:    Masked
[   72.011811]       FIQ:    Masked
[   72.014926] Drivers loaded:
[   72.017677]       1. i.MX8M Uart2
[   72.020958] Chars written: 382
[   72.023983] Sd host circuit reset..
[   72.027439] card inserted...
[   72.030367] Prescaler = 4, Divisor = 15, Freq Set = 400000
[   72.035865] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[   72.049859] Sd: sending command, CMD_NAME: "ALL_SEND_CID", CMD_CODE: 0x02010000, CMD_ARG: 0x00000000
[   72.065140] Sd Error: Cmd response returned an error, VendSpec: 0x2000f800, ProtCtrl: 0x00800040, PresentStatus: 0xf00d8088, intStatus: 0x00048001, Re
sp0: 0x00000000, timeDiff: 5062

[   72.081495] uSDHC: PRES_STATE: 0xf00d8088, SYS_CTRL: 0x000e02ef, INT_STATUS: 0x00048001

[   72.089641] uSDHC: CMD "ALL_SEND_CID", resp: SdError, CMD_RSP3: 0x00000000, CMD_RSP2: 0x00000000, CMD_RSP1: 0x00000000, CMD_RSP0: 0x00000000

[   72.102677] failed to initialize
[   72.105781]

[   72.107302]  ... wait forever&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;On a side note, I noticed that one of the pins in the device tree is referenced as uSDHC2's voltage regulator (i.e. pad &amp;nbsp;&lt;EM&gt;iomuxc_sw_mux_ctl_pad_sd2_reset_b&lt;/EM&gt;) but its pinmux configuration uses a mux mode that doesn't make sense. The device-tree contains a mux mode of 0x5 for this pin instead of a 0. Would anyone know why?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I set the pin’s mux-mode to 0x5, the &lt;EM&gt;uSDH controller&lt;/EM&gt; simply times out i.e. it doesn’t even detect the card.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Device tree source for the usdhc2’s voltage regular:&lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;reg_usdhc2_vmmc: regulator-usdhc2 {
 compatible = "regulator-fixed";
 pinctrl-names = "default";
 pinctrl-0 = &amp;lt;&amp;amp;pinctrl_reg_usdhc2_vmmc&amp;gt;;
 regulator-name = "VSD_3V3";
 regulator-min-microvolt = &amp;lt;3300000&amp;gt;;
 regulator-max-microvolt = &amp;lt;3300000&amp;gt;;
 gpio = &amp;lt;&amp;amp;gpio2 19 GPIO_ACTIVE_HIGH&amp;gt;;
 off-on-delay-us = &amp;lt;12000&amp;gt;;
 enable-active-high;
};

&amp;amp;usdhc2 {
assigned-clock-rates = &amp;lt;200000000&amp;gt;;
assigned-clocks = &amp;lt;&amp;amp;clk IMX8MN_CLK_USDHC2&amp;gt;;
pinctrl-names = "default", "state_100mhz", "state_200mhz";
pinctrl-0 = &amp;lt;&amp;amp;pinctrl_usdhc2&amp;gt;, &amp;lt;&amp;amp;pinctrl_usdhc2_gpio&amp;gt;;
pinctrl-1 = &amp;lt;&amp;amp;pinctrl_usdhc2_100mhz&amp;gt;, &amp;lt;&amp;amp;pinctrl_usdhc2_gpio&amp;gt;;
pinctrl-2 = &amp;lt;&amp;amp;pinctrl_usdhc2_200mhz&amp;gt;, &amp;lt;&amp;amp;pinctrl_usdhc2_gpio&amp;gt;;
cd-gpios = &amp;lt;&amp;amp;gpio1 15 GPIO_ACTIVE_LOW&amp;gt;;
bus-width = &amp;lt;4&amp;gt;;
vmmc-supply = &amp;lt;&amp;amp;reg_usdhc2_vmmc&amp;gt;;
status = "okay";
};

pinctrl_reg_usdhc2_vmmc: regusdhc2vmmcgrp {
fsl,pins = &amp;lt;MX8MN_IOMUXC_SD2_RESET_B_GPIO2_IO19 0x41&amp;gt;;
};​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Device tree binary for the usdhc2 voltage regulator :&lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;regusdhc2vmmcgrp {
                    fsl,pins = &amp;lt;0xec 0x354 0x00 0x05 0x00 0x41&amp;gt;;
                    u-boot,dm-spl;
                    phandle = &amp;lt;0x42&amp;gt;;
                };

regulator-usdhc2 {
        compatible = "regulator-fixed";
        pinctrl-names = "default";
        pinctrl-0 = &amp;lt;0x42&amp;gt;;
        regulator-name = "VSD_3V3";
        regulator-min-microvolt = &amp;lt;0x325aa0&amp;gt;;
        regulator-max-microvolt = &amp;lt;0x325aa0&amp;gt;;
        gpio = &amp;lt;0x26 0x13 0x00&amp;gt;;
        enable-active-high;
        u-boot,off-on-delay-us = &amp;lt;0x4e20&amp;gt;;
        phandle = &amp;lt;0x2d&amp;gt;;
    };

mmc@30b50000 {
                compatible = "fsl,imx8mn-usdhc\0fsl,imx8mm-usdhc\0fsl,imx7d-usdhc";
                reg = &amp;lt;0x30b50000 0x10000&amp;gt;;
                interrupts = &amp;lt;0x00 0x17 0x04&amp;gt;;
                clocks = &amp;lt;0x02 0x56 0x02 0x4d 0x02 0xaf&amp;gt;;
                clock-names = "ipg\0ahb\0per";
                fsl,tuning-start-tap = &amp;lt;0x14&amp;gt;;
                fsl,tuning-step = &amp;lt;0x02&amp;gt;;
                bus-width = &amp;lt;0x04&amp;gt;;
                status = "okay";
                assigned-clocks = &amp;lt;0x02 0x68&amp;gt;;
                assigned-clock-rates = &amp;lt;0xbebc200&amp;gt;;
                pinctrl-names = "default\0state_100mhz\0state_200mhz";
                pinctrl-0 = &amp;lt;0x29 0x2a&amp;gt;;
                pinctrl-1 = &amp;lt;0x2b 0x2a&amp;gt;;
                pinctrl-2 = &amp;lt;0x2c 0x2a&amp;gt;;
                cd-gpios = &amp;lt;0x23 0x0f 0x01&amp;gt;;
                vmmc-supply = &amp;lt;0x2d&amp;gt;;
                u-boot,dm-spl;
                sd-uhs-sdr104;
                sd-uhs-ddr50;
            };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 17:42:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1624408#M203427</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-03-29T17:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1626370#M203570</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;Update: &lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;I pushed the latest version of my implementation to GitHub.&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;A title="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/drivers/usdhc.rs" href="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/drivers/usdhc.rs" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;usdhc driver impl&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A title="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/clocks/ccm.rs" href="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/clocks/ccm.rs" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;clock control impl&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A title="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/mux/usdhc2grp.rs" href="https://github.com/nihalpasham/rustBoot/blob/main/boards/hal/src/nxp/imx8mn/bsp/mux/usdhc2grp.rs" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;pin-mux config impl&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;After including changes in latest version, I noticed the following - when I set the command index enable bit in the CMD_XFR_TYP register, I now get 2 errors.&lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Command index error&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt;: which means the response did not contain the&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN class=""&gt;command index&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN class=""&gt;&amp;nbsp;the host sent.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Command end bit error&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt;: which occurs when detecting that the end field of a command response is 0.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN class=""&gt;Given the above - I can summarise the issue as the following (with some degree of certainty)&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;SD commands from the host are&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;not&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt;&amp;nbsp;going through to the sd-card. But the host controller seems to believe that it did send the command and it also acknowledges having received a response. But the response is (probably) always a string of zeroes.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;Some extra context: just in case this is required&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Build and test instructions: &lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;clone the git repo from &lt;/SPAN&gt;&lt;A title="https://github.com/nihalpasham/rustBoot" href="https://github.com/nihalpasham/rustBoot" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;here&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;navigate to the path- &lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN class=""&gt;rustBoot/boards/bootloaders/imx8mn &lt;/SPAN&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;assuming you have &lt;/SPAN&gt;&lt;A title="https://www.rust-lang.org/tools/install" href="https://www.rust-lang.org/tools/install" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;rust nightly installed&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN class=""&gt; and the &lt;/SPAN&gt;&lt;A title="https://rust-lang.github.io/rustup/cross-compilation.html" href="https://rust-lang.github.io/rustup/cross-compilation.html" target="_blank" rel="noopener noreferrer"&gt;&lt;SPAN class=""&gt;aarch64-unknown-none-softfloat target added&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN class=""&gt;, simply run `&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;cargo build --release&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt;` to compile and build the bootloader. &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;once done you can either use a jtag programmer or some other method to load the code on to the device and run it. Debug logs will be output to the default serial peripheral at 0x30890000.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;The compiled elf binary will be located at the following path- &lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN class=""&gt;boards/target/aarch64-unknown-none-softfloat/release/imx8mn-rs&lt;/SPAN&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Sat, 01 Apr 2023 09:42:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1626370#M203570</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-04-01T09:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1647568#M205572</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Update: &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Just thought I'd add this here, in case anyone finds this useful or can figure out what I'm missing.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;During uSDHC initialization, I use an identification clock of 400Khz and a 3.3 volts setting. I'm currently testing an 8GB card.&lt;/P&gt;&lt;P&gt;Here is the list of steps in my initialization routine&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Reset the entire host controller by setting the RSTA bit. Just to be sure I also set the RSTC + RSTD bits&lt;/LI&gt;&lt;LI&gt;set sd-clock to 400khz i.e. the prescaler field in the SYS_CTRL register is set to 0x20 and divisor field is set to 0xf.&lt;/LI&gt;&lt;LI&gt;Note - I'm using PLL1_DIV2 as my source&amp;nbsp;&lt;SPAN&gt;root clock i.e. SYSTEM_PLL1_DIV2_CLK or 800Mhz/2 for uSDHC2. (note: I have not configured the source clock, I use it as-is. I assume this is OK).&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;enable relevant IRQ bits via the &lt;STRONG&gt;interrupt status enable&lt;/STRONG&gt; register&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;set the &lt;STRONG&gt;initialize active&lt;/STRONG&gt; field in SYS_CTRL register and wait until it is cleared&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;set the little-endian and four-bit wide fields in the PROT_CTRL register&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;set data timeout value field in the SYS_CTRL to its maximum i.e. 0xf&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;at this point, I assume the card is initialized&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;and send &lt;STRONG&gt;CMD0&lt;/STRONG&gt; wait &lt;U&gt;2ms&lt;/U&gt; and send a &lt;STRONG&gt;CMD8&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;It fails to initialize after CMD8 is sent. Looking at the command completion bit in the interrupt status register, we can conclude that a response was received but it contains errors. &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;For pinmux settings - I use the values from the imx8mn nano device-tree, as listed below&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;clock line&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xd4 0x33c 0x00 0x00 0x00 0x190&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;cmd line&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xd8 0x340 0x00 0x00 0x00 0x1d0&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;data0 line&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xdc 0x344 0x00 0x00 0x00 0x1d0&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;data1 line&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xe0 0x348 0x00 0x00 0x00 0x1d0&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;data2 line&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xe4 0x34c 0x00 0x00 0x00 0x1d0&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;data3 line&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xe8 0x350 0x00 0x00 0x00 0x1d0&amp;gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;cd line&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp; - &amp;lt;0x38 0x2a0 0x00 0x01 0x00 0x1d0&amp;gt;;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;reset line&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - &amp;lt;0xec 0x354 0x00 0x05 0x00 0x41&amp;gt;;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;with some modifications.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have applied a drive strength of 6 instead of 1.&lt;/LI&gt;&lt;LI&gt;the reset line is set is set to GPIO output mode before setting the mux-modes and pad config for all the other pins. Once done, we clear it. If this is not done, we get a sd-timeout error instead of sd-command errors.&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 05:07:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1647568#M205572</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-05-10T05:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1652709#M206074</link>
      <description>&lt;P&gt;I think I may have (finally) found the fix. I had to &lt;STRONG&gt;remove&lt;/STRONG&gt; the entire reset logic for it to work i.e.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;remove hardware reset&lt;/STRONG&gt; or power-cycling logic (this was done by muxing the uSDHC2’s RESET line to gpio-mode and toggling gpio pin 19 to power-cycle the sd-card) and&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;remove software reset&lt;/STRONG&gt; logic (performed by setting RSTA)&lt;/LI&gt;&lt;LI&gt;and set the reset line’s mux-mode to uSDHC-mode.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;and it magically started working.&lt;BR /&gt;&lt;BR /&gt;I still have to no idea &lt;STRONG&gt;why this works?&lt;/STRONG&gt; I hope &lt;EM&gt;NXP can explain&lt;/EM&gt; why this works? But until then, my best guess is that the &lt;STRONG&gt;i.MX 8M Nano EVK board&lt;/STRONG&gt; deviates from both the SD spec and the reference manual.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If anyone wants to test this. Please clone the latest (master) commit, build and flash. You should see debug output below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ 0.000005] imx8mn-rs version 0.1.0
[ 0.003617] Booting on: [i.MX](https://i.mx/) 8M Nano EVK
[ 0.007682] Current privilege level: EL3
[ 0.011755] Exception handling state:
[ 0.015561] Debug: Masked
[ 0.018894] SError: Unmasked
[ 0.022413] IRQ: Masked
[ 0.025746] FIQ: Masked
[ 0.028993] Drivers loaded:
[ 0.031841] 1. i.MX8M Uart2
[ 0.035289] Chars written: 382
[ 0.038436] uSDHC2 supports 1.8v, 3.0v, 3.3v ...
[ 0.043311] NO RESET, PRES_STAT: 0xff8d8088
...
[ 0.050676] NO RSTA, PRES_STAT: 0xff8d8088
...
[ 0.082844] Sd clock stablized in 37us
[ 0.086777] Prescaler = 64, Divisor = 16, Freq = 390625 Hz
...
[ 0.108591] before CMD0 sent, PRES_STAT: 0xff8d8088
[ 0.113783] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[ 0.126803] Sd: sending command, CMD_NAME: "SEND_IF_COND", CMD_CODE: 0x081a0000, CMD_ARG: 0x000001aa
[ 0.137920] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.148645] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.560598] Sd: sending command, CMD_NAME: "APP_CMD", CMD_CODE: 0x371a0000, CMD_ARG: 0x00000000
[ 0.571475] Sd: sending command, CMD_NAME: "APP_SEND_OP_COND", CMD_CODE: 0x29020000, CMD_ARG: 0x50ff8000
[ 0.583475] Sd: sending command, CMD_NAME: "ALL_SEND_CID", CMD_CODE: 0x02090000, CMD_ARG: 0x00000000
[ 0.595085] Sd: sending command, CMD_NAME: "SEND_REL_ADDR", CMD_CODE: 0x03020000, CMD_ARG: 0x00000000
[ 0.606431] Sd: sending command, CMD_NAME: "SEND_CSD", CMD_CODE: 0x09010000, CMD_ARG: 0x00010000
[ 0.617763] CSD Contents : 00 40 0e 00 32 5b 59 00 003b 83 7f 80 0a 40 00
[ 0.624947] cemmc_structure=1, spec_vers=0, taac=0x0E, nsac=0x00, tran_speed=0x32,ccc=0x05B5, read_bl_len=0x09, read_bl_partial=0b, write_blk_misalign=0b,read_blk_mi
salign=0b, dsr_imp=0b, sector_size =0x7F, erase_blk_en=1b
[ 0.645753] CSD 2.0: ver2_c_size = 0x3BFF, card capacity: 7987527680 bytes or 7.99GiB
[ 0.654006] wp_grp_size=0x0000000b, wp_grp_enable=0b, default_ecc=00b, r2w_factor=010b, write_bl_len=0x09, write_bl_partial=0b, file_format_grp=0, copy=0b, perm_writ
e_protect=0b, tmp_write_protect=0b, file_format=0b ecc=00b&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 03:13:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1652709#M206074</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-05-18T03:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging a bare-metal uSDHC driver, written in Rust for the i.MX 8M nano</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1652730#M206077</link>
      <description>&lt;DIV class=""&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;STRONG&gt;Some context for why the (above) fix works:&lt;/STRONG&gt; I zeroed-in on the issue with the following observation which was consistent across multiple rounds of testing&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;I looked at (a working execution trace of) U-boot's register values and saw the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;PRES_STAT&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; register (always) has DLSL and CLSL bits set. This makes sense as the pad (or pin) configuration is set to &lt;/SPAN&gt;&lt;STRONG&gt;&lt;U&gt;&lt;SPAN class=""&gt;0x1d0&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; (taken from the device-tree) or more precisely is as follows.&lt;/SPAN&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Dse::DseX1,&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Fsel::Fast,&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Ode::Disabled,&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Pue::PullUp,&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Hys::Enabled,&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;Pe::Enabled,&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;they should always be pulled high. In u-boot's case, the &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;PRES_STAT&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; register always has CLSL and DLSL bits set and contains the following value - &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;0xff888088&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class=""&gt;but in my case, applying the same pin configuration results in &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;a PRES_STAT&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; value of &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;0xff8d8088 and upon&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; performing a software RESET i.e. setting the RSTA bit in SYS_CTRL and waiting for it to be cleared, I saw that CLSL and DLSL lines are pulled low. &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;PRES_STAT&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt; value changes to &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class=""&gt;0xf00d8088. &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN class=""&gt;This happens consistently.&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[   0.000005] imx8mn-rs version 0.1.0
[   0.003618] Booting on: i.MX 8M Nano EVK
[   0.007667] Current privilege level: EL3
[   0.011687] Exception handling state:
[   0.015349]      Debug: Masked
[   0.018745]      SError: Unmasked
[   0.022187]      IRQ:   Masked
[   0.025411]      FIQ:   Masked
[   0.028761] Drivers loaded:
[   0.031530]      1. i.MX8M Uart2
[   0.034922] Chars written: 382
[   0.038160] uSDHC2 has support for 1.8v, 3.0v, 3.3v ...
[   0.044572] after HW RESET, PRES_STAT: 0xff8d8088
[   0.049441] checking register value
[   0.051909] after RSTA cleared, PRES_STAT: 0xf40d8088
[   0.057188] Sd host circuit reset in 3us
[   0.061136] after Sd host cicuit reset, PRES_STAT: 0xf00d8088
...
[   0.087812] Sd clock stablized in 38us
[   0.091674] Prescaler = 64, Divisor = 16, Freq = 390625 Hz
...
[   0.118224] Sd: sending command, CMD_NAME: "GO_IDLE_STATE", CMD_CODE: 0x00000000, CMD_ARG: 0x00000000
[   0.131208] Sd: sending command, CMD_NAME: "SEND_IF_COND", CMD_CODE: 0x081a0000, CMD_ARG: 0x000001aa
[   0.145884] Error: we got a response for the last cmd but it contains errors, decode contents of interrupt status register for details
 VendSpec: 0x30007809, SysCtrl: 0x000f20ff, ProtCtrl: 0x08800022, PresentStatus: 0xf00d8088, intStatus: 0x000c8001, Resp0: 0x00000000, Resp1: 0x00000000, Resp2: 0x00000000, Resp3: 0x00000000, CC_bit set in 4131us
[   0.177955] SdError: Send interface condition command (CMD8) returned an error
[   0.185646] failed to initialize
[   0.189029]
[   0.190608] ... wait forever&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 03:39:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Debugging-a-bare-metal-uSDHC-driver-written-in-Rust-for-the-i-MX/m-p/1652730#M206077</guid>
      <dc:creator>npashi</dc:creator>
      <dc:date>2023-05-18T03:39:20Z</dc:date>
    </item>
  </channel>
</rss>

