File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010#include <stm32f4xx_rtc.h>
1111#include <stm32f4xx_usart.h>
1212#include <stm32f4xx_rng.h>
13+ #include <usbd_storage_msd.h>
1314#include <stm_misc.h>
1415#include "std.h"
1516
@@ -815,14 +816,6 @@ int main(void) {
815816 flash_error (4 );
816817 }
817818
818- #ifdef USE_HOST_MODE
819- // USB host
820- pyb_usb_host_init ();
821- #elif defined(USE_DEVICE_MODE )
822- // USB device
823- pyb_usb_dev_init ();
824- #endif
825-
826819 if (first_soft_reset ) {
827820#if MICROPY_HW_HAS_MMA7660
828821 // MMA: init and reset address to zero
@@ -839,10 +832,23 @@ int main(void) {
839832 FRESULT res = f_mount (& fatfs1 , "1:" , 1 );
840833 if (res != FR_OK ) {
841834 printf ("[SD] could not mount SD card\n" );
835+ } else {
836+ if (first_soft_reset ) {
837+ // use SD card as medium for the USB MSD
838+ usbd_storage_select_medium (USBD_STORAGE_MEDIUM_SDCARD );
839+ }
842840 }
843841 }
844842#endif
845843
844+ #ifdef USE_HOST_MODE
845+ // USB host
846+ pyb_usb_host_init ();
847+ #elif defined(USE_DEVICE_MODE )
848+ // USB device
849+ pyb_usb_dev_init ();
850+ #endif
851+
846852 // run main script
847853 {
848854 vstr_t * vstr = vstr_new ();
Original file line number Diff line number Diff line change @@ -95,6 +95,12 @@ void sdcard_power_off(void) {
9595 SD_DeInit ();
9696}
9797
98+ uint64_t sdcard_get_capacity_in_bytes (void ) {
99+ SD_CardInfo SDCardInfo ;
100+ SD_GetCardInfo (& SDCardInfo );
101+ return SDCardInfo .CardCapacity ;
102+ }
103+
98104bool sdcard_read_block (uint8_t * dest , uint32_t block_num ) {
99105 // TODO return error if not powered on
100106
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ void sdcard_init(void);
55bool sdcard_is_present (void );
66bool sdcard_power_on (void );
77void sdcard_power_off (void );
8+ uint64_t sdcard_get_capacity_in_bytes (void );
89bool sdcard_read_block (uint8_t * dest , uint32_t block_num );
910bool sdcard_write_block (const uint8_t * src , uint32_t block_num );
1011
You can’t perform that action at this time.
0 commit comments