I decided to test the SDCard support on iMXRT1050-EVK board, but go these errors:
chip/imxrt_lowputc.c: In function 'imxrt_lpuart_configure':
chip/imxrt_lowputc.c:559:2: warning: #warning missing logic [-Wcpp]
559 | #warning missing logic
chip/imxrt_timerisr.c:63:2: warning: #warning REVISIT these clock settings [-Wcpp]
63 | #warning REVISIT these clock settings
chip/imxrt_usdhc.c:100:4: error: #error "CONFIG_SDIO_BLOCKSETUP is mandatory for this driver"
100 | # error "CONFIG_SDIO_BLOCKSETUP is mandatory for this driver"
In file included from chip/imxrt_usdhc.c:60:
chip/imxrt_usdhc.c: In function 'imxrt_usdhc_initialize':
chip/imxrt_usdhc.c:3144:25: error: 'GPIO_USDHC1_DATA0' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA0_1'?
3144 | imxrt_config_gpio(PIN_USDHC1_D0);
chip/imxrt_usdhc.c:3144:25: note: each undeclared identifier is reported only once for each function it appears in
chip/imxrt_usdhc.c:3145:25: error: 'GPIO_USDHC1_CLK' undeclared (first use in this function); did you mean 'GPIO_USDHC1_CLK_1'?
3145 | imxrt_config_gpio(PIN_USDHC1_DCLK);
chip/imxrt_usdhc.c:3146:25: error: 'GPIO_USDHC1_CMD' undeclared (first use in this function); did you mean 'GPIO_USDHC1_CMD_1'?
3146 | imxrt_config_gpio(PIN_USDHC1_CMD);
make: *** [Makefile:151: imxrt_usdhc.o] Error 1
The first error as easy to fix: just run “make menuconfig” press the key “/” and search for “CONFIG_SDIO_BLOCKSETUP” you will find the:
Prompt: SDIO block setup
Just press 1 do go directly to it and then enable it:
[*] SDIO block setup
After trying to compile again you will see that the pins definition still missing: PIN_USDHC1_D0, PIN_USDHC1_DCLK, PIN_USDHC1_CMD. Just like we did for SPI in the previous post, you need to start looking the schematics.
First let see the SDCard slot:
So, let search for these pins: SD1_CLK, SD1_CMD, SD1_D0, SD1_D1, SD1_SD2, SD1_D3 and SD_CD_SW:
Ok, after defining these pins the compilation finished correctly. But the fact of the USDHC driver is only failing because DATA0 rings a bell! Probably it is using SD Card with 1-bit interface, we need to enable 4-bits interface:
$ make menuconfig
System Type -> USDHC Configuration -> Bus width for USDHC1 (Four bit)
Perfect, now the compilation is failing, this is exactly what I was waiting for:
CC: chip/imxrt_usdhc.c In file included from chip/imxrt_usdhc.c:60: chip/imxrt_usdhc.c: In function 'imxrt_usdhc_initialize': chip/imxrt_usdhc.c:3138:25: error: 'GPIO_USDHC1_DATA1' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA2_1'? 3138 | imxrt_config_gpio(PIN_USDHC1_D1); | ^ chip/imxrt_usdhc.c:3138:25: note: each undeclared identifier is reported only once for each function it appears in chip/imxrt_usdhc.c:3139:25: error: 'GPIO_USDHC1_DATA2' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA2_1'? 3139 | imxrt_config_gpio(PIN_USDHC1_D2); | ^ chip/imxrt_usdhc.c:3140:25: error: 'GPIO_USDHC1_DATA3' undeclared (first use in this function); did you mean 'GPIO_USDHC1_DATA3_1'? 3140 | imxrt_config_gpio(PIN_USDHC1_D3); | ^ make: *** [Makefile:151: imxrt_usdhc.o] Error 1 make: Leaving directory '/comum/workspace/Consultancy/iDTech/NuttX/nuttx/arch/arm/src' make: *** [tools/LibTargets.mk:155: arch/arm/src/libarch.a] Error 2
You already know what to do, right? Just insert all the pins to board.h :
Excellent! Now it is compiling with 4-bit SDCard interface.
But wait! What about the SDCard insertion pin (SD_CD_SW)? If you look at arch/arm/src/imxrt/imxrt_usdhc.c you will see that it is waiting for a pin named PIN_USDHC1_CD_GPIO, so let to declare it pointing to our pin:
I decided to document the steps needed to get the Low Power SPI working on iMXRT1050-EVKB and I hope it could be useful for other people using this board. But the basic idea apply to any other board supported by NuttX.
Everything starts with the schematic, you need to spot the SPI pins that you want to use and which SPI Port it belongs to.
Perfect, but here you need to know an important information about NuttX: normally the NuttX SPI drivers don’t use the native CS (Chip Select) pin, instead it use ordinary GPIO pins to work as CS. The reason behind it is because normally the SPI Hardware has a limited number os HW CS pins (normally 4 pins). So instead of limiting the user to only 4 devices (CS), NuttX allow you to use how many CS pins as you wish.
Now we need to see in the LPSPI driver what is the name of pins it uses, so we will associate these pins to those from the pinmux header file.
Just open the file arch/arm/src/imxrt/imxrt_lpspi.c and search for imxrt_config_gpio(), this is the function used to configure the pins on iMXRT10xx chips.
Don’t worry, if you look at iMXRT1050 Datasheet you will see that this CS pin (GPIO_SD_B0_01) is the GPIO3.IO and it is already defined at boards/arm/imxrt/imxrt1050-evk/src/imxrt1050-evk.h this way:
So, with the basic configuration in place, now we can start defining our SPI device initialization. Let me think what SPI device we could you. Well, since I want you to “see” the SPI working, let’s to use the MAX7219 7-segment numeric display! 🙂
Fortunately we have the boards/arm/stm32/stm32f4discovery/src/stm32_max7219_leds.c as example to initialize our MAX7219 display.
We can copy it and modify to become an iMXRT file:
I was trying to run NuttX RTOS on iMXRT1060_EVK board (it has an external 8MiB QSPI Flash), but because my JLink EDU is version V8 it doesn’t supports Cortex-M7.
Using the DAPLink drag-and-drop I can copy small nuttx firmwares (i.e.: up to 73KB worked), but when I compile NuttX to PROTECTED Mode it doesn’t work. Because the kernel is at the beginning of the flash and the userspace is at offset +2MB. Then during the copy it reports timeout.
Then I tried to use OpenOCD. I got it working for debugging, but it doesn’t have support to flash the QSPI for NXP chips, only for STMicro.
[ 638.833516] usb 1-1: new high-speed USB device number 9 using xhci_hcd [ 638.982422] usb 1-1: New USB device found, idVendor=1fc9, idProduct=000c, bcdDevice= 1.00 [ 638.982428] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 638.982434] usb 1-1: Product: LPC [ 638.982436] usb 1-1: Manufacturer: NXP [ 638.982439] usb 1-1: SerialNumber: ABCD
Found SW-DP with ID 0x2BA01477 Unknown DP version. Assuming DPv0 Scanning AP map to find all available APs AP: Stopped AP scan as end of AP map has been reached AP: AHB-AP (IDR: 0x24770011) Iterating through AP map to find AHB-AP to use AP: Core found AP: AHB-AP ROM base: 0xE00FF000 CPUID register: 0x410FC241. Implementer code: 0x41 (ARM) Found Cortex-M4 r0p1, Little endian. FPUnit: 6 code (BP) slots and 2 literal slots CoreSight components: ROMTbl @ E00FF000 ROMTbl: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7 ROMTbl: E0001000, CID: B105E00D, PID: 003BB002 DWT ROMTbl: E0002000, CID: B105E00D, PID: 002BB003 FPB ROMTbl: E0000000, CID: B105E00D, PID: 003BB001 ITM ROMTbl: E0040000, CID: B105900D, PID: 000BB9A1 TPIU ROMTbl: E0041000, CID: B105900D, PID: 000BB925 ETM Cortex-M4 identified. J-Link>loadbin nuttx.bin, 0 Halting CPU for downloading file. Downloading file [nuttx.bin]… Writing target memory failed.
J-Link>erase Erasing device… J-Link: Flash download: Only internal flash banks will be erased. To enable erasing of other flash banks like QSPI or CFI, it needs to be enabled via "exec EnableEraseAllFlashBanks" Erasing flash [100%] Done.
Error: Failed to erase chip @ address 0x08000000 (Algo87: Unspecified error #1) Failed to erase chip. Failed to execute RAMCode for chip erase! J-Link: Flash download: Total time needed: 0.105s (Prepare: 0.064s, Compare: 0.000s, Erase: 0.001s, Program: 0.000s, Verify: 0.000s, Restore: 0.038s) ERROR: Erase returned with error code -5. J-Link>
Strange, after resetting the board and writing a .hex instead of a .bin worked…
qa -- Record a macro in hotkey a
0 -- Go to the beginning of the line
f= -- Go to the first equals sign
100i <Esc> -- (There's a single space after the i, and the <Esc> means press escape, don't type "<Esc>".) Insert 100 spaces
8| -- Go to the 8th column (sorry, you'll have to manually figure out which column to align to)
dw -- Delete until the next non-space character
j -- Go to the next line
q -- Stop recording.
In my case I just replaced the “f=” with “f0” and “8|” with “33|”
If you follow this blog you know that I already show how to use NuttX as a library to avoid compiling it all the time using the build system. But unfortunately I did it more than 3 years ago and NuttX changed a lot since that time.
So, let’s to start configuring the STM32F429IDISCOVERY board.
Create the nuttxspace directory and clone the nuttx and apps: