B4R Question Write alot files into SD Card

Discussion in 'B4R Questions' started by tzfpg, May 13, 2019.

  1. tzfpg

    tzfpg Member Licensed User

    Hi,

    I try to write 1K++ files into SD Card. When run the program, It pop out then error log.

    I set the Stack Buffer Size to 20000 but still go error.

    Code:
    Sub Process_Globals
    Private sd As SD
    End Sub

    Private Sub AppStart
    sd.Initialize(
    15)

    For i = 1 To 1500
            
    If sd.Exists(i) = False Then
                SaveData(i)
                
    Log("Write ", i)
                Delay(
    100)
            
    End If
        
    Next
    End Sub

    private Sub SaveData(data As String)
        
    Dim Buffer() As Byte
        
    If sd.OpenReadWrite(data) = True Then
            sd.Position = sd.CurrentFile .Size
            Buffer = bc.StringToBytes(data)
            sd.Stream.WriteBytes(Buffer,
    0,Buffer.Length)
            sd.Stream.Flush
            sd.Close
        
    End If
    End Sub
    Code:
    Exception (3):
    epc1=
    0x40100221 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4000f210 depc=0x00000000
    ctx: cont
    sp: 3ffffd00 
    end: 3fffffd0 offset: 01a0
    >>>stack>>>
    3ffffea0:  000000ff 
    00000001 3ffee874 40203e93
    3ffffeb0:  
    00000005 00000001 0000000f 401065b5
    3ffffec0:  3ffee8f4 
    00000000 3ffee874 40203eb6
    3ffffed0:  3ffee8f4 
    00000000 3ffee874 402043ec
    3ffffee0:  3ffee8f0 3ffee8f4 
    00000001 00000467
    3ffffef0:  3ffeed08 0000022e 0000022e 4010020c
    3fffff00:  3ffee810 3fff058c 3ffee818 401006dc
    3fffff10:  3ffee810 3fff058c 3ffee818 40203abc
    3fffff20:  3ffee7c8 3fff0580 3ffee85c 
    40203120
    3fffff30:  3ffee810 3fff058c 3ffee85c 40202f00
    3fffff40:  3fffff48 3fff0000 
    00000000 40205520
    3fffff50:  3ffee7c8 3ffee7c8 
    00000000 40202a90
    3fffff60:  402060d8 
    00000000 3ffee85c 0000005d
    3fffff70:  
    00000000 3ffee7c8 3ffee85c 40202f7d
    3fffff80:  3ffee810 
    00000000 0000012c 401004e4
    3fffff90:  feefeffe feefeffe 3ffeebc4 3ffeebcc
    3fffffa0:  3fffdad0 
    00000000 3ffeebc4 40203168
    3fffffb0:  feefeffe feefeffe feefeffe 40205af0
    3fffffc0:  feefeffe feefeffe 3ffe85dc 
    40100739
    <<<stack<<<
     ets Jan  
    8 2013,rst cause:2, boot mode:(3,7)
    load 
    0x4010f000, len 1384, room 16
    tail 
    8
    chksum 
    0x2d
    csum 
    0x2d
    vbb28d4a3
    ~ld
    What cause this error.

    thank you.
     
    Last edited: May 13, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Does it log anything except of the error?

    Are you able to save a single file?
     
  3. tzfpg

    tzfpg Member Licensed User

    Yes, I able to save a single file. Save until 800++ record then show out the error log.
    When increase Stack Buffer Size , it can save more.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The problem is the conversion of 'i' to string. It consumes some RAM every loop.

    Pass UInt and convert it to string or bytes inside SaveData. This way the memory will be released when the sub ends.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice