Russian Qt Forum
Апрель 23, 2024, 12:07 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.
Вам не пришло письмо с кодом активации?

Войти
 
  Начало   Форум  WIKI (Вики)FAQ Помощь Поиск Войти Регистрация  

Страниц: 1 [2]   Вниз
  Печать  
Автор Тема: QBS для микроконтроллера.  (Прочитано 18271 раз)
arhiv6
Гость
« Ответ #15 : Октябрь 10, 2015, 19:52 »

Разобрался с builtByDefault:false. Не то Грустный  В интерфейсе QtCreator я смогу запускать сборку этого продукта (тем самым запуская прошивку МК), выбирая пункт "Собрать" в контекстном меню на продукте. Мне-то надо по кнопке "Запустить" (точнее по сочетанию клавиш Ctrl+R).
Похоже по-прежнему придётся использовать запуск стороннего bash-скрипта (Конфигурация запуска: Сторонняя программа), в котором руками прописывать путь по нужного файла.
Записан
arhiv6
Гость
« Ответ #16 : Октябрь 17, 2015, 19:43 »

Решил проблему таким костылём: раз я не могу в скрипт прошивки передать путь до прошиваемого файла, то проще прописать этот путь в скрипте. Разумеется, не вручную, а средствами самого qbs:
Код
Javascript
import qbs
import qbs.TextFile
 
Product {
   name: "my_firmware"
   type: ["elf","hex","bin","sh"]
 
   property string compilerPath: "/home/user/ti/gcc/bin/msp430-elf-gcc"
   property string objcopyPath: "/home/user/ti/gcc/bin/msp430-elf-objcopy"
   property string includePath: "/home/user/ti/gcc/include"
   property string mspdebugPath: "/usr/local/bin/mspdebug"
 
   property string hwVersion: "0.0"
   property string fwVersion: "0.0"
   property string device: "msp430f5529"
 
   property var compilerOptions: [
        "-I" + includePath,
       "-mmcu=" + device,
       "-O2", "-g", "-std=gnu99", "-Wall",
       "-fdata-sections","-ffunction-sections",
       "-D HW_VERSION=" + hwVersion,
       "-D FW_VERSION=" + fwVersion
   ];
 
   property var linkerOptions: [
       "-L" + includePath,
       "-T"+ device +".ld",
       "-Wl,-gc-sections"
   ];
 
   Group {
       name: "sources"
       files: 'src/*.c'
       fileTags: ['c']
   }
 
   Group {
       name: "headers"
       files: 'src/*.h'
       fileTags: ['h']
   }
 
   Group {
       name: "others"
       files: [
           'README',
           'program.sh',
           'Makefile'
       ]
   }
 
   Rule {
      inputs: ["c"]
       Artifact {
           fileTags: ['obj']
           filePath: '.obj/' + qbs.getHash(input.baseDir) + '/' + input.fileName + '.o'
       }
       prepare: {
           var args = [];
           args = args.concat(product.compilerOptions)
           args.push('-c');
           args.push(input.filePath);
           args.push('-o');
           args.push(output.filePath);
           var cmd = new Command(product.compilerPath, args);
           cmd.description = 'compiling ' + input.fileName;
           return cmd;
       }
   }
 
   Rule {
       multiplex: true
       inputs: ['obj']
       Artifact {
           fileTags: ['elf']
           filePath: product.name + '.elf'
       }
       prepare: {
           var args = [];
           args = args.concat(product.compilerOptions)
           args = args.concat(product.linkerOptions)
           for (i in inputs["obj"])
                       args.push(inputs["obj"][i].filePath);
           args.push('-o');
           args.push(output.filePath);
           var cmd = new Command(product.compilerPath, args);
           cmd.description = 'linking ' + product.name;
           return cmd;
       }
   }
 
   Rule {
       inputs: "elf"
       Artifact {
           fileTags: ["bin"]
          filePath: product.name + ".bin"
       }
       prepare: {
           var args = ["-O", "binary", input.filePath, output.filePath];
           var cmd = new Command(product.objcopyPath, args);
           cmd.description = "converting to bin";
           return cmd;
       }
   }
 
   Rule {
       inputs: "elf"
       Artifact {
           fileTags: ["hex"]
           filePath: product.name + ".hex"
       }
       prepare: {
           var args = ["-O", "ihex", input.filePath, output.filePath];
           var cmd = new Command(product.objcopyPath, args);
           cmd.description = "converting to hex";
           return cmd;
       }
   }
 
   Rule {
       inputs: "elf"
       Artifact {
           fileTags: ["sh"]
       }
       prepare: {
           var  cmd  =  new  JavaScriptCommand();
           cmd.sourceCode  =  function()  {
               var  file  =  new  TextFile(project.sourceDirectory+"/program.sh", TextFile.WriteOnly);
               file.write("#!/bin/bash\n");
               file.write(product.mspdebugPath +" tilib \"prog " + input.filePath + " reset\"");
               file.close();
           }
           cmd.description = "create program.sh script";
           return cmd;
       }
   }
}
 
Последнее правило создает в каталоге проекта скрипт program.sh который и указываем запускаемой программой.
Записан
RShaman
Гость
« Ответ #17 : Июль 07, 2016, 15:19 »

Я просто оставлю это здесь, дабы самому не потерять, и может кому то поможет.
Код
Javascript
import qbs
import qbs.Environment
 
Project {
   Product {
       Depends { name: "cpp" }
 
       type: "hex"
       name: "firmware"
 
       property string workDirectory: Environment.getEnv("FIRMWARES_WORKDIR")
       property string hexExtractor: cpp.toolchainInstallPath + "/" + cpp.toolchainPrefix + "objcopy";
 
       cpp.positionIndependentCode: false
       cpp.debugInformation: true
       cpp.executableSuffix: ".elf"
       cpp.commonCompilerFlags:
       [
           "-mcpu=cortex-m4",
           "-mfpu=fpv4-sp-d16",
           "-mfloat-abi=hard",
           //"-ffunction-sections",
           //"-fdata-sections",
           //"-mthumb",
           //"-fno-inline",
           //"-flto"
           //"-std=c99",
       ]
       cpp.linkerFlags:
       [
           "-flto",
           "-mcpu=cortex-m4",
           "-mfloat-abi=hard",
           "-specs=nosys.specs",
           "-Wl,--start-group",
           "-Wl,--gc-sections",
           "-lnosys",
           "-lgcc",
           "-lc",
   //        "-mthumb",
   //        "-mfpu=fpv4-sp-d16",
       ]
       cpp.linkerScripts:
       [
           "tm4c123gh6.ld"
       ]
       cpp.includePaths:
       [
           workDirectory + "/sdk/"
       ]
 
       files:
       [
           "main.cpp"
       ]
 
       Group {
           qbs.install: true
           fileTagsFilter: ["application", "hex"]
       }
 
       Rule {
           id: hex
           inputs: ["application"]
           Artifact {
               fileTags: ['hex']
               filePath: product.name + '.hex'
           }
           prepare: {
               var args = [];
               args.push("-j")
               args.push(".text")
               args.push("-j")
               args.push(".data")
               args.push("-O")
               args.push("ihex")
               args.push(input.filePath);
               args.push(output.filePath);
               var extractorPath = product.hexExtractor;
               var cmd = new Command(extractorPath, args);
               return cmd;
           }
       }
   }
}
 

Такая конструкция включает полную поддержку со стороны редактора QtCreator в части работы с include файлами и т.д., что составляет немалую часть преимуществ использования QtCreator'а.
Записан
Страниц: 1 [2]   Вверх
  Печать  
 
Перейти в:  


Страница сгенерирована за 0.083 секунд. Запросов: 20.