I want To do Bare Metal Programming on STM32 using STM32CubeIDE.
have (STM32WB55 and STM32F103).
what all header files and source files are required to use peripheral registers and make own Device driver. For E.g: in AVR 8 bit MCU for doing bare metal we simply have to add iom328.h or iom2560.h header file that will include all the peripheral registers of the MCU and we can easily make LL.
Same way out what are the Header files required for doing it with STM32
CMSIS: is like Initialize our processor and includes its registers.
So what all header files to be included for programming STM32F103 and STM32WB55
You have to define a part number macro on the command line (eg: STM32F103xB) and then you just #include "stm32f1xx.h".
The particular device header ("stm32f103xb.h") and the CMSIS headers are included by that one.
If you want to use the HAL library then you also will need to #include "stm32f1xx_hal.h". This includes "stm32f1xx_hal_conf.h" which includes all the HAL units drivers you have enabled in the IDE.
I haven't useed the WB parts, but I'm sure the pattern is similar.
Related
I have one small question about proper module design for embedded device (different manufacturer, cortex M0 - M7).
Lets say we have c sensor module for reading accelerometer data from I2C device acc.c and corresponding headerfile acc.h.
Module needs external functions for I2C communication. And I am thinking about correct implementation of module.
Until now I have in my mind these 3 versions:
Include I2C.h driver (This option is last option, because it will fix module usage to one platform)
Weak definition of externaly provided functions (But again weak definition of function is pretty fixed on platform - NXP has different implementation than STM etc)
Function pointers in process structure, so every device would have assigned external function for I2C communication (It seems to be little bit overkill for this kind of device and debugging of such implementation can be little bit tricky, but overall implementation seems to be clean).
Do you have any ideas for better solution which would be more readable/debuggable than function pointers and still portable?
I writes some C-program code for Altera/Nios II microprocessor (uP). This code will be different with Altera Arm 9 microprocessor. So I need to write 2 different code pieces for different uP-s. How can I check in execution time which uP is present. Or more simple, current uP is Nios or not.
As the two processors are from different architectures, you will not be able to check which processor is running at run-time. You could do it at compile time, as you will have a specific define flag set by your toolchain (see https://sourceforge.net/p/predef/wiki/Architectures/). For Arm it should be __arm__ or similar, depending on the toolchain you are using for the HPS.
#ifdef __arm__
<specific code for HPS>
#else
<specific code for NIOS>
#endif /* __arm__ */
You can also look at the toolchain's defines using the c pre-processor command (cpp):
<toolchain>-cpp -dM /dev/null
Note: for Arm processor, the MIDR register could be used to know which type you are running and this one could be accessed at runtime. But when building for NIOS II, you would have a compilation error. So you need to use the preprocessor to call specific Arm register name and to remove the code when building for NiosII.
Presumably it will be compiled with a different compiler? These compilers will (very likely) have a #define of some sort which you can use to build different code for each one.
You can make the compiler dump all its default preprocessor defines using:
echo | ./nios2-elf-gcc.exe -dM -E -
This will in particular emit:
#define nios2 1
I am very new in Blackfin processors and I suppose to write a tester program for Blackfin, BF527. This tester program should test the connection of the board and 2 peripheral RAMs.
So far I have downloaded and installed VisualDSP++ (90-day trial version).
Can anyone help me to know how can I write a simple program to write in port G and read From port H, including initialization (preferably in C).
I have looked for sample code on internet but unfortunately all the codes are very advance.
I went through the data sheet, but it was on assembly not C, still I couldn't find any solid sample program for my purpose.
Look in the VisualDSP installation folder (under Program Files). There is lots of sample C and C++ code in Analog Devices\VisualDSP 5.0\Blackfin\Examples
To program the hardware peripherals from C/C++ you need the header files which contain the pointer definitions for the memory-mapped registers. These will be found in Analog Devices\VisualDSP 5.0\Blackfin\include
In your code you can automatically select the correct include file for the project's processor using:
#include <blackfin.h>
Unit testing embedded C for a TI MSP430. Unit tests are to run on a Linux host compiled with GCC. The project is rather big and primarily legacy code.
There are reads and writes to registers such as PCIN_L, PCOUT_L, and PCDIR_L among others that when compiled will generate errors saying they are undeclared. This is true because when running on the host no such registers exist.
Earlier I learned to intercept calls to functions (symbols) that would not be available and redirect thos calls to fake functions, only returning a predefined value. This I did using the linker option -Wl --wrap,someSymbol.
Makefile:
LDFLAGS=-Wl --wrap,AbsentFunction
SOURCES=WrappedFunctions.c
WrappedFunctions.c:
int __wrap_AbsentFunction(int val_a)
{
return val_a;
}
This would redirect any calls to AbsentFunction to __wrap_AbsentFunction.
I did however try this on my registers as well withou any luck.
Makefile:
LDFLAGS=-Wl --wrap,PCDIR_L
SOURCES=WrappedSymbols.c
WrappedSymbols.c:
char __wrap_PCDIR_L;
Is it possible to something similar to the registers as I did to the functions? I prefer not introducing changes into the projects code.
You could simply declare memory mapped processor peripheral registers as volatile data by creating a "fake" processor header containing declarations such as:
extern volatile uint16_t PCDIR_L ;
They will not of course behave like peripheral registers but it will allow the code to be built.
A better approach is to have built a hardware abstraction layer so that peripheral access is via an function API rather than direct to the hardware, then you can create a "fake" API that emulates the hardware behaviour.
The register names for the MSP430 device are all declared in a device specific header file. While you will not necessarily be able to mimic easily the behaviour of these registers, you can write your own equivalent file that will map the registers on to memory locations accessible to your program.
Mimicking the bitwise functionality of port registers, serial port status registers and the rest will be quite an undertaking.
I'm busy with a massive project where I need write software for a control system for an automotive vehicle. Here's what I am using:
I'm using an STM32F4 for the micro
I am writing the Application (Control app) in Matlab Simulink. I then generate Cortex M4 optimised code from Matlab which I simply Include in my Keil uVision Project. (Works like a charm)
I manually write software for the driver layer and to interface to the Hardware abstraction Layer.
I would like to maintain separation between my Simulink Generated Code and my 'firmware' hand written code. Essentially, I want to be able to change the firmware without affecting my control application.
I would like to use a configuration file to map the variables that Matlab Simulink generates with my Hardware Registers (for GPIO, for instance). I would like to do this via a configuration file (e.g. via an xml file).
Has anyone ever done something like this and is it even possible. I'm looking for an elegant solution that does not consume a lot of RAM.
Thanks so much!
PS: Is it possible to declare variables in your code based on variables names that are stored in say an .xml or .txt file.
So if in the .txt file I have "Pressure_Sensor = 0", is it possible, perhaps using a Macro Definition, to declare a variable in the code: Pressure_Sensor = 0;
If you want to include variables into your c project build from syntax in another type of file whether it be .xml or .txt files there's a couple ways to do it. If you are going to be keeping variables in c compatible declaration style like:
int Pressure_Sensor = 0;
and no other invalid semantics will be in that file you can always just include that file into one of your compilation units. The extensions of the file do not matter. The #include directive literally just inserts that file into place.
If you are going to be doing something along the lines of a non c compatible language such as XML, a standard way to generate and include those variables into your build is to have a script that runs are a pre-build action that parses that .xml file and then generates a c compatible include file that you include into one of your compilation units. One of the most common things to use this for that you could find many examples of is for generating version/build info into the build.
You can do this:
Simplified Problem Statement is:
You want to modify a CPU port register through your code, but you don't know the address of that port register(Port address may change externally).
Solution is:
I)In your code:
Let your program assume that the address of the port register is at at fix location say 0x1000.
Someone/something will letter put address of port register at 0x1000(Your program don't care how)
So to change pin K1 you have to change value of address present at 0x1000.
But Wait ,
You want to only change a single port pin and you don't know which so,
Assume pin bit pattern is at 0x1004
To make pin ON write:
Value of the address present at 0x1000 |= Value at 0x1002
To make pin OFF write:
Value of the address present at 0x1000 &= ~Value at 0x1002
Most Imp:
Reserve these locations in your program somehow so that compiler dont write code there.
II)Outside the code:
Assumptions for explanation: Port1 address : 0xF000
Port2 address : 0xF001
Now have a Excel macro or something to do following:
Suppose you wants port2's 8th pin for contactor K1 then that macro should generate a simple text file as: "F00180".
Now use bin2hex or bin2mot (based) on your compilers output format and convert this notepad file into .hex or .mot(S-record) format.
You have to specify address location as 0x1000 as one of the input to these utilities.
Now remove header ,footer lines from generated .hex file and merge remaining data to your program.hex file.
You are done here,burn the .hex file into target by suitable flash programmer.