Made the cmake interactiv please run the ./run command with the filename that is unde /bsl/ EX : ./run nucleo_f042k6

interrupts
key 4 years ago
parent 8643e915f8
commit 69d64d5127

@ -1,38 +1,36 @@
cmake_minimum_required(VERSION 3.5)
####################################################################################################
#VARIABLES : CMAKE
####################################################################################################
#An exhaustive list can be found : https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
set(CMAKE_C_COMPILER "/usr/bin/arm-none-eabi-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/arm-none-eabi-g++")
set(CMAKE_ASM_COMPILER "/usr/bin/arm-none-eabi-gcc")
set(CMAKE_OBJCOPY "/usr/bin/arm-none-eabi-objcopy")
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs") #AS we provide our own linker nad not using the one from the curren OS (system)
include(cmakeProjectConfig.cmake)
set(BSL_DIR ${CMAKE_SOURCE_DIR}/bsl/${BSL_USED})
####################################################################################################
#PROJECT & LIBRARIES : defined by user and important that it comes after the VARIABLES otherwise the Set varibale will not be used.
####################################################################################################
project(refOvenTest ASM C CXX) # do this intead sf declaring languages in the beginning it will prevent loop errors.
set(CMAKE_VERBOSE_MAKEFILE off)#Shoul make print everythign ??
if(EXISTS ${BSL_DIR}) # Cheking if the directory exists
message("${BoldGreen}Compiling for ${BSL_USED} ${ColourReset}")
set(COMPILER_DEFS ${BSL_DIR}/bslCompiler.cmake)
set(PROJECT_DEFS ${BSL_DIR}/bslConfig.cmake)
####################################################################################################
#VARIABLES : defined by user
####################################################################################################
set(EXECUTABLE ${PROJECT_NAME}.out)
elseif(BSL_USED STREQUAL "raspberry")
message("${BoldGreen}Compiling for ${BSL_USED} ${ColourReset}")
else()
message( FATAL_ERROR "${BoldRed}Please Select a valid BSL, CMake will exit.${ColourReset}" )
endif()
include(${COMPILER_DEFS})
project(${BSL_USED} ASM C CXX) #do this intead sf declaring languages in the beginning it will prevent loop errors.
set(CMAKE_VERBOSE_MAKEFILE off) #Shoul make print everythign ??
set(EXECUTABLE ${PROJECT_NAME}) #Create the executable
####################################################################################################
#CONFIG FILE
####################################################################################################
set(INTERFACES_DIR ${CMAKE_SOURCE_DIR}/bsl/csl/interfaces)
include(${CMAKE_SOURCE_DIR}/bsl/nucleo_f042k6/bsl_nucleo_f042k6.cmake)
####################################################################################################
#SUBDIRECTORIES
####################################################################################################
include(${PROJECT_DEFS})
add_subdirectory(bsl)
#The order is important
@ -41,6 +39,13 @@ list(APPEND EXTRA_LIBS sub::translator)
list(APPEND EXTRA_LIBS sub::sources)
list(APPEND EXTRA_LIBS sub::gpio)
message("${BoldBlue}Project Info ${ColourReset}")
message("${Blue} |--> Exec Name \t: ${EXECUTABLE} ${ColourReset}")
message("${Blue} |--> Compiler Def\t: ${COMPILER_DEFS} ${ColourReset}")
message("${Blue} |--> Project Def\t: ${PROJECT_DEFS} ${ColourReset}")
message("${Blue} |--> Interfaces Dir\t: ${INTERFACES_DIR} ${ColourReset}")
message("${Blue} |--> Libs used\t\t: ${EXTRA_LIBS} ${ColourReset}")
####################################################################################################
#EXECUTABLE
####################################################################################################
@ -52,26 +57,32 @@ target_include_directories(${EXECUTABLE} PUBLIC ${CPP_INCLUDES})
####################################################################################################
#LINKING EXECUTEABLE
####################################################################################################
target_link_libraries(${EXECUTABLE} ${EXTRA_LIBS})
target_link_options(${EXECUTABLE} PRIVATE ${LINKER_FLAGS})
if(IS_NO_SYS)
message("${Cyan}Using specifier Linker script ${ColourReset}")
message("${Cyan} |--> ${LINKER} ${ColourReset}")
target_link_libraries(${EXECUTABLE} ${EXTRA_LIBS})
target_link_options(${EXECUTABLE} PRIVATE ${LINKER_FLAGS})
endif()
####################################################################################################
#CUSTOM COMMANDS
####################################################################################################
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${EXECUTABLE})
add_custom_command(TARGET ${EXECUTABLE}
if(NEED_OBJCOPY)
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin)
endif()
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND ${CMAKE_SIZE} ${EXECUTABLE})
####################################################################################################
#CUSTOM Comments from dev.
####################################################################################################
# Link For hheader dependency : https://stackoverflow.com/questions/11216408/cmake-dependencies-headers-between-apps-libraries-in-same-project
# Link For header dependency : https://stackoverflow.com/questions/11216408/cmake-dependencies-headers-between-apps-libraries-in-same-project
# This is one possible trick to handle the assenbly compiling.
# We can't use arm-non-eabi-as because it can onaly hande macros.
# So this bizzare Variable makes shure that whne the asembly compiling is called the -x assembler-with-cpp flag is passed

@ -1,2 +1,2 @@
add_subdirectory(csl)
add_subdirectory(nucleo_f042k6)
add_subdirectory(${BSL_USED})

@ -0,0 +1,8 @@
project(Csl_Stm32f0xx ASM C CXX) # do this intead sf declaring languages in the beginning it will prevent loop errors.
####################################################################################################
#SUBDIRECTORIES
####################################################################################################
add_subdirectory(Drivers)
add_subdirectory(startup)
add_subdirectory(Src)

@ -0,0 +1,14 @@
#ifndef _SYSTEMCALL_H_
#define _SYSTEMCALL_H_
#include <cstdio>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
#include <array>
// Ide from : https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po
std::string execBash(const char* cmd);
#endif // _SYSTEMCALL_H_

@ -0,0 +1,6 @@
add_library(rpiGpio gpio.cpp)
target_compile_options(rpiGpio PRIVATE ${C_FLAGS})
target_compile_definitions(rpiGpio PRIVATE ${C_DEFS})
target_include_directories(rpiGpio PUBLIC ${INTERFACES_DIR} ../Inc)
add_library(sub::gpio ALIAS rpiGpio)

@ -0,0 +1,143 @@
#include "pin.hpp"
#include "systemCall.hpp"
Pin::Pin()
{
char buffer[50];
uint8_t currentPin = 0;
int ck = 0;
std::ifstream bufFile;
}
Pin::~Pin()
{
}
void Pin::setMode(mode mode)
{
switch(mode)
{
case input:
sprintf(buffer, "echo \"in\" > /sys/class/gpio/gpio%d/direction",gpioNo);
pins[gpioNo].mode = mode;
system(buffer);
break;
case output:
sprintf(buffer, "echo \"out\" > /sys/class/gpio/gpio%d/direction",gpioNo);
pins[gpioNo].mode = mode;
system(buffer);
break;
case analog:
std::cout << "No analog pins are awailable for raspberry" << std::endl;
break;
case alternate:
std::cout << "No analog pins are awailable for raspberry" << std::endl;
break;
default :
throwError(__LINE__,notValidMode);
break;
}
}
void Pin::setOutputState(state state)
{
}
void Pin::setPullUpDonw(pullUpDown resistance)
{
}
void Pin::setSpeed(speed speed)
{
}
void Pin::config(mode mode, state state, pullUpDown resistance, speed speed)
{
}
bool Pin::read()
{
sprintf(buffer,"/sys/class/gpio/gpio%d/value",gpioNo);
bufFile.open(buffer,std::ios::in);
if(bufFile.is_open())
{
bufFile.read(buffer,1);
if(buffer[0] == '1')
{
bufFile.close();
return 1;
}
else if (buffer[0] == '0')
{
bufFile.close();
return 0;
}
}
}
bool Pin::toggle()
{
return 1;
}
void Pin::write(bool state)
{
if(state == 1)
{
sprintf(buffer, "echo \"%d\" > /sys/class/gpio/gpio%d/value",value,gpioNo);
system(buffer);
return;
}
sprintf(buffer, "echo \"%d\" > /sys/class/gpio/gpio%d/value",value,gpioNo);
system(buffer);
}
void Pin::init()
{
sprintf(buffer,"[ -d /sys/class/gpio/gpio%d ]",gpioNo); // retunrs null if directory exists
ck = system(buffer);
if( ck != 0)
{
sprintf(buffer, "echo \"%d\" > /sys/class/gpio/export",gpioNo);
ck = system(buffer);
}
else
{
std::cout << "Pin already initiated"<< std::endl;
}
}
void Pin::deInit()
{
sprintf(buffer,"[ -d /sys/class/gpio/gpio%d ]",gpioNo); // retunrs null if directory exists
ck = system(buffer);
if( ck == 0)
{
sprintf(buffer, "echo \"%d\" > /sys/class/gpio/unexport",gpioNo);
system(buffer);
}
else
{
throwError(__LINE__,pinNotDeclared);
}
}
void Pin::hardwareInfo()
{
}
void Pin::throwError(uint16_t line, errors errNo)
{
}

@ -0,0 +1,14 @@
#include "systemCall.hpp"
std::string execBash(const char* cmd) {
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}

@ -0,0 +1,18 @@
####################################################################################################
# bsl_nucleo_f042k6_compiler.cmake
####################################################################################################
set(CMAKE_C_COMPILER "/usr/bin/arm-none-eabi-gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/arm-none-eabi-g++")
set(CMAKE_ASM_COMPILER "/usr/bin/arm-none-eabi-gcc")
set(CMAKE_OBJCOPY "/usr/bin/arm-none-eabi-objcopy")
set(CMAKE_SIZE "/usr/bin/arm-none-eabi-size")
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs") #AS we provide our own linker nad not using the one from the curren OS (system)
option(IS_NO_SYS "Use a custom linker script" ON)
option(NEED_OBJCOPY "If objcopy is neede for cross compilation" ON)
####################################################################################################
#PROJECT & LIBRARIES : defined by user and important that it comes after the VARIABLES otherwise the Set varibale will not be used.
####################################################################################################
set(BSL_NAME nucleo_f042k6)

@ -4,9 +4,9 @@
set(CPU_MCU "-mcpu=cortex-m0")
set(IDIR_BIN "/home/key/Git/ked/bsl/nucleo_f042k6/bin")
set(IDIR_LIB "/home/key/Git/ked/bsl/nucleo_f042k6/lib")
set(IDIR_INC "/home/key/Git/ked/bsl/nucleo_f042k6/inc")
set(IDIR_BIN "${CMAKE_SOURCE_DIR}/bsl/nucleo_f042k6/bin")
set(IDIR_LIB "${CMAKE_SOURCE_DIR}/bsl/nucleo_f042k6/lib")
set(IDIR_INC "${CMAKE_SOURCE_DIR}/bsl/nucleo_f042k6/inc")
####################################################################################################
#PROJECT & LIBRARIES : defined by user and important that it comes after the VARIABLES otherwise the Set varibale will not be used.

@ -0,0 +1,20 @@
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()

@ -1,12 +1,16 @@
#!/bin/bash
#BSL_TO_USE="nucleo_f042k6"
BSL_TO_USE=$1
FILE=build/
if [ -d "$FILE" ];then
rm -r build
echo Cmake build directory exists
cmake -S . -B build/
#echo Cmake build directory exists
cmake -S . -B build/ -DBSL_USED=$BSL_TO_USE
else
cmake -S . -B build/
cmake -S . -B build/ -DBSL_USED=$BSL_TO_USE
fi
cd $FILE

Loading…
Cancel
Save