cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L432KC communication with microSD card Reader via SPI

meetudiii
Associate

I am following this video: https://www.youtube.com/watch?v=aqSNz26Cuio&t=35s

Hardware:

  1. STM32 Nucleo-32 for STM32L432
  2. Adafruit microSDcard adapter: https://www.adafruit.com/product/4682
  3. Samsung 32GB EVO (red) microSD card

Software:

  1. STM32CubeIDE

The board used in the video is different but all the settings are also present in my STM32L432 board.

My .ioc pinout view looks like this:

0693W00000QN0RvQAL.pngNote: In video, the SPI1_SCK has been automatically given to PA5, but for my board it was shown as PA1, hence have made the connections accordingly.

FatFS enabled:

  1. MAX_SS - 4096
  2. USE_LFN - Enabled with static working buffer

SPI1 enabled:

  1. Mode - Full Duplex - Master
  2. Parameter Settings - 0693W00000QN0SPQA1.png
  3. System Core SYS set to Serial Wire (as shown in video)

After following the video, My build is complete with no errors. Then I make the hardware connections for my board like this:

0693W00000QN0U1QAL.jpg0693W00000QN0U6QAL.jpg(Please excuse the microSD card not inserted in the slot)

When I am running the file to download the code to board, I am changing the run config file as shown in the video: changing the debug probe to OpenOCD (I don't know much about what this does) and changing the Reset mode to Software System Reset.

0693W00000QN0ULQA1.png 

So when I click on Run, I get the following error:

Open On-Chip Debugger 0.11.0+dev-00449-g53fa0f7 (2022-06-09-09:42) [https://github.com/STMicroelectronics/OpenOCD]
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V2J40M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.265263
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : clock speed 4000 kHz
Info : stlink_dap_op_connect(connect)
Info : SWD DPIDR 0x2ba01477
Info : STM32L432KCUx.cpu: Cortex-M4 r0p1 processor detected
Info : STM32L432KCUx.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for STM32L432KCUx.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Info : device idcode = 0x10016435 (STM32L43/L44xx - Rev Z : 0x1001)
Info : RDP level 0 (0xAA)
Info : flash size = 256kbytes
Info : flash mode : single-bank
Warn : GDB connection 1 on target STM32L432KCUx.cpu not halted
undefined debug reason 8 - target needs reset
Info : accepting 'gdb' connection on tcp/3333
Warn : GDB connection 2 on target STM32L432KCUx.cpu not halted
undefined debug reason 8 - target needs reset
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000e9c msp: 0x20010000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Padding image section 0 at 0x08006304 with 4 bytes (bank write end alignment)
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000e9c msp: 0x20010000
Info : dropped 'gdb' connection
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x08000fc4 msp: 0x2000ffdc
shutdown command invoked
Info : dropped 'gdb' connection

When I run using the default setting in Run Config; which is debug probe set to ST-LINK (ST-LINK GDB server), I get no errors while downloading to board, but I don't see any file written on to the SD card. Attaching the console log of the same below:

STMicroelectronics ST-LINK GDB server. Version 7.0.0
Copyright (c) 2022, STMicroelectronics. All rights reserved.
 
Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled
        InitWhile                  : Enabled
 
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
Debugger connected
Waiting for debugger connection...
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.11.0                  
      -------------------------------------------------------------------
 
 
 
Log output file:   C:\Users\RSL\AppData\Local\Temp\STM32CubeProgrammer_a17636.log
ST-LINK SN  : 066BFF525649898367212344
ST-LINK FW  : V2J40M27
Board       : NUCLEO-L432KC
Voltage     : 3.27V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x435
Revision ID : Rev Z
Device name : STM32L43xxx/STM32L44xxx
Flash size  : 256 KBytes
Device type : MCU
Device CPU  : Cortex-M4
BL Version  : --
 
 
 
Memory Programming ...
Opening and parsing file: ST-LINK_GDB_server_a17636.srec
  File          : ST-LINK_GDB_server_a17636.srec
  Size          : 24.75 KB 
  Address       : 0x08000000 
 
 
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 12]
Download in Progress:
 
 
File download complete
Time elapsed during download operation: 00:00:00.960
 
 
 
Verifying ...
 
 
 
 
Download verified successfully 
 
 
Shutting down...
Exit.

I am fairly new to the whole STM32 environment.

I just want to make this STM32L432 + SPI + microSDcard thing working.

Any help is appreciated. Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

SD Cards would want 512-byte sectors.

I don't use CubeMX/IDE to code.

There should be mostly working code for SPI + FATFS here

STM32Cube_FW_L4_V1.14.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

There were some bugs with the multi-sector support that I've addressed previously on the forum, but good luck finding them, search here is an abomination..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

SD Cards would want 512-byte sectors.

I don't use CubeMX/IDE to code.

There should be mostly working code for SPI + FATFS here

STM32Cube_FW_L4_V1.14.0\Drivers\BSP\Adafruit_Shield\stm32_adafruit_sd.c

There were some bugs with the multi-sector support that I've addressed previously on the forum, but good luck finding them, search here is an abomination..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you very much for the solution. I am looking at the library you just mentioned past couple of days. Will keep working on it.

Let's see. Thank you again.