| 45 | |
| 46 | #reduce the heap size as 0x000 |
| 47 | def stm32update_heap2zero(path): |
| 48 | oldline = '' |
| 49 | newline = '' |
| 50 | for root, dirs, files in os.walk(path): |
| 51 | for file in files: |
| 52 | file_path = os.path.join(root,file) |
| 53 | if os.path.splitext(file)[1] == '.s': # find .s files (Keil MDK) |
| 54 | with open(file_path,'r+',) as f: |
| 55 | flag_need_replace = False |
| 56 | while True: |
| 57 | line = f.readline() |
| 58 | if line == '': |
| 59 | break |
| 60 | |
| 61 | re_result = re.match('\s*Heap_Size\s+EQU\s+0[xX][0-9a-fA-F]+', line) |
| 62 | if re_result != None: |
| 63 | oldline = line |
| 64 | newline = re.sub('0[xX][0-9a-fA-F]+','0x00000000', oldline) |
| 65 | flag_need_replace = True |
| 66 | break |
| 67 | |
| 68 | if flag_need_replace == True: |
| 69 | f.seek(0) |
| 70 | content = f.read() |
| 71 | f.seek(0) |
| 72 | f.truncate() |
| 73 | newcontent = content.replace(oldline, newline) |
| 74 | f.write(newcontent) |
| 75 | |
| 76 | elif os.path.splitext(file)[1] == '.icf': # find .icf files (IAR) |
| 77 | with open(file_path,'r+',) as f: |
| 78 | flag_need_replace = False |
| 79 | while True: |
| 80 | line = f.readline() |
| 81 | if line == '': |
| 82 | break |
| 83 | |
| 84 | re_result = re.match('\s*define\s+symbol\s+__ICFEDIT_size_heap__\s*=\s*0[xX][0-9a-fA-F]+', line) |
| 85 | if re_result != None: |
| 86 | oldline = line |
| 87 | newline = re.sub('0[xX][0-9a-fA-F]+','0x000', oldline) |
| 88 | flag_need_replace = True |
| 89 | break |
| 90 | |
| 91 | if flag_need_replace == True: |
| 92 | f.seek(0) |
| 93 | content = f.read() |
| 94 | f.seek(0) |
| 95 | f.truncate() |
| 96 | newcontent = content.replace(oldline, newline) |
| 97 | f.write(newcontent) |
| 98 | |
| 99 | elif os.path.splitext(file)[1] == '.lds': # find .lds files (GCC) |
| 100 | with open(file_path,'r+',) as f: |
| 101 | flag_need_replace = False |
| 102 | while True: |
| 103 | line = f.readline() |
| 104 | if line == '': |