diff --git a/tools/file2h.py b/tools/file2h.py
index fb5bd1a4b9c5990f725c1e04e68becea729173db..2a04ae22b94372130055dca0558ad22f138902ae 100644
--- a/tools/file2h.py
+++ b/tools/file2h.py
@@ -10,7 +10,9 @@ from __future__ import print_function
 import sys
 
 # Can either be set explicitly, or left blank to auto-detect
-line_end = ''
+# Except auto-detect doesn't work because the file has been passed
+# through Python text processing, which makes all EOL a \n
+line_end = '\\r\\n'
 
 if __name__ == "__main__":
     filename = sys.argv[1]
diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py
index af010dad954df27df60ff87a784b7dab761dbe9e..42303da8b87db60b730332f3a679fa517d8e8b6d 100644
--- a/tools/insert-usb-ids.py
+++ b/tools/insert-usb-ids.py
@@ -13,7 +13,7 @@ def parse_usb_ids(filename):
     if filename == 'usbd_desc_cdc_msc.c':
         for line in open(filename).readlines():
             line = line.rstrip('\r\n')
-            match = re.match('^#define\s+(\w+)\s+0x(\d+)$', line)
+            match = re.match('^#define\s+(\w+)\s+0x([0-9A-Fa-f]+)$', line)
             if match:
                 if match.group(1) == 'USBD_VID':
                     rv['USB_VID'] = match.group(2)