Closed camielverdult closed 5 months ago
The same thing seems to happen when using the --ascii
flag
Ampy has a similar issue, I am starting to think it's the file:
camiel@WS1420:/mnt/c/Users/c.verdult/Documents/Repos/firmware$ ampy --port /dev/ttyS4 put build/lib/ucanopen/sdo/server.mpy /flash/lib/ucanopen/sdo/server.mpy
Traceback (most recent call last):
File "/home/camiel/.local/bin/ampy", line 8, in
I think I found the suspect, if I copy all my files except the server.mpy file my flash is full:
>>> import os
>>> statvfs_data = os.statvfs('/flash')
>>> _, f_frsize, f_blocks, f_bfree = (
... statvfs_data[0],
... statvfs_data[1],
... statvfs_data[2],
... statvfs_data[3],
... )
>>> fs_total_size = f_blocks * f_frsize
>>> fs_total_size_kB = fs_total_size / 1024
>>> fs_free_size = f_bfree * f_frsize
>>> fs_free_size_kB = fs_free_size / 1024
>>> fs_free_size_kB
0.0
>>> fs_total_size_kB
143.0
This does not make much sense to me, since the total size on disk of the files I am trying to copy is 92.0KB. In reality the flash is full after 88KB of data.
Edit: It makes much more sense after checking the statvfs output with an empty /flash
folder:
MicroPython v1.22.2 on 2024-04-16; WIFLX_gt48468c1 with STM32G474
Type "help()" for more information.
>>> import os
>>> statvfs_data = os.statvfs('/flash')
>>> _, f_frsize, f_blocks, f_bfree = (
... statvfs_data[0],
... statvfs_data[1],
... statvfs_data[2],
... statvfs_data[3],
... )
>>> fs_total_size = f_blocks * f_frsize
>>> fs_total_size_kB = fs_total_size / 1024
>>> fs_free_size = f_bfree * f_frsize
>>> fs_free_size_kB = fs_free_size / 1024
>>> fs_free_size_kB
55.5
>>> fs_total_size_kB
143.0
So there is 87.5KB left on the flash for mpy files
Hello, there is one specific file that has suddenly (and now continuously) has errors when copying the file to an STM32. The file has the following content (this is not my code, used in a shared project):
Code (server.py, part of a canopen variant module)
```py import struct import sys from .base import SdoBase from .block import SdoBlockException, SdoBlock from .constants import * from .exceptions import * class SdoServer(SdoBase): # Creates an SDO server. def __init__(self, rx_cobid, tx_cobid, node): super().__init__(rx_cobid, tx_cobid, node.object_dictionary) self._node = node self._buffer = None self._toggle = 0 self._index = None self._subindex = None self.last_received_error = 0x00000000 self.sdo_block = None def on_request(self, can_id, data, timestamp): try: if self.sdo_block and self.sdo_block.state != BLOCK_STATE_NONE: if self.process_block(data): # Abort returns False return (command,) = struct.unpack_from("B", data, 0) ccs = command & 0xE0 if ccs == REQUEST_UPLOAD: self.init_upload(data) elif ccs == REQUEST_SEGMENT_UPLOAD: self.segmented_upload(command) elif ccs == REQUEST_DOWNLOAD: self.init_download(data) elif ccs == REQUEST_SEGMENT_DOWNLOAD: self.segmented_download(command, data) elif ccs == REQUEST_BLOCK_UPLOAD: self.block_upload(data) elif ccs == REQUEST_BLOCK_DOWNLOAD: self.block_download(data) elif ccs == REQUEST_ABORTED: self.request_aborted(data) else: self.abort(0x05040001) except SdoAbortedError as exc: self.abort(exc.code) self.sdo_block = None except KeyError as exc: self.abort(0x06020000) self.sdo_block = None except Exception as exc: _, index, subindex = struct.unpack_from(SDO_STRUCT, data) print(f"\n\nucanopen->sdo->server.py({can_id:03X}, {data})@{timestamp}\n") print(f"entry={index}:{subindex})n") sys.print_exception(exc) print("\n") # Reply with general error self.abort(0x08000025) def process_block(self, request): print("process_block") command, _, _ = struct.unpack_from(SDO_STRUCT, request) if command == 0x80: self.sdo_block = None # Abort received, do not reply return False if BLOCK_STATE_UPLOAD < self.sdo_block.state < BLOCK_STATE_DOWNLOAD: print("BLOCK_STATE_UPLOAD") # in upload state if self.sdo_block.state == BLOCK_STATE_UP_INIT_RESP: print("BLOCK_STATE_UP_INIT_RESP") # init response was sent, client required to send new request if (command & REQUEST_BLOCK_UPLOAD) != REQUEST_BLOCK_UPLOAD: raise SdoBlockException(0x05040001) if (command & START_BLOCK_UPLOAD) != START_BLOCK_UPLOAD: raise SdoBlockException(0x05040001) # now start blasting data to client from server self.sdo_block.update_state(BLOCK_STATE_UP_DATA) for seqno in range(1, self.sdo_block.req_blocksize + 1): block, last = self.sdo_block.get_single_upload_block(seqno) self.send_response(block) if last: break elif self.sdo_block.state == BLOCK_STATE_UP_DATA: print("BLOCK_STATE_UP_DATA") command, ackseq, newblk = struct.unpack_from( SDO_BLOCKACK_STRUCT, request ) if (command & REQUEST_BLOCK_UPLOAD) != REQUEST_BLOCK_UPLOAD: print("Command %02X", command) raise SdoBlockException(0x05040001) elif (command & BLOCK_TRANSFER_RESPONSE) != BLOCK_TRANSFER_RESPONSE: print("Command %02X", command) raise SdoBlockException(0x05040001) elif ackseq != self.sdo_block.last_seqno: self.sdo_block.data_uploaded = self.sdo_block.data_succesfull_upload self.sdo_block.req_blocksize = newblk if self.sdo_block.size == self.sdo_block.data_uploaded: print("BLOCK_STATE_UP_DATA last data") self.sdo_block.update_state(BLOCK_STATE_UP_END) response = bytearray(8) command = RESPONSE_BLOCK_UPLOAD command |= END_BLOCK_TRANSFER n = self.sdo_block.last_bytes << 2 command |= n print( "Last no byte: %d, CRC: x%04X", self.sdo_block.last_bytes, self.sdo_block.crc_value, ) struct.pack_into( SDO_BLOCKEND_STRUCT, response, 0, command, self.sdo_block.crc_value, ) self.send_response(response) else: for seqno in range(1, self.sdo_block.req_blocksize + 1): block, last = self.sdo_block.get_single_upload_block(seqno) self.send_response(block) if last: break elif self.sdo_block.state == BLOCK_STATE_UP_END: self.sdo_block = None elif BLOCK_STATE_DOWNLOAD < self.sdo_block.state: print("BLOCK_STATE_DOWNLOAD") else: # in neither raise SdoBlockException(0x08000022) return True def init_upload(self, request): _, index, subindex = struct.unpack_from(SDO_STRUCT, request) self._index = index self._subindex = subindex res_command = RESPONSE_UPLOAD | SIZE_SPECIFIED response = bytearray(8) data = self._node.get_data(index, subindex, check_readable=True) size = len(data) if size <= 4: # print("Expedited upload for 0x%X:%d", index, subindex) res_command |= EXPEDITED res_command |= (4 - size) << 2 response[4 : 4 + size] = data else: # print("Initiating segmented upload for 0x%X:%d", index, subindex) struct.pack_into("The environment is on WSL using rshell 0.0.32. I have compiled all files with mpy-cross (using the same version as the stm32 port binary flashed to the stm32) when this file started throwing errors during copy.
This is the log for copying the file: