Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How do you write libraries for ARM Cortex (STM32)?

Status
Not open for further replies.

Spoerle

Junior Member level 2
Joined
Mar 22, 2022
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
292
Apologize in advance for a perhaps somewhat philosophical question, but I've been scratching my head for a few days and I haven't found an answer to it
I'm a bit frozen in time, I started on 8-bit Intel 8052.
That's probably why I'm used to save on MCU memory and performance.
To the point.

I want to create a reusable library for the Precision Thermocouple to Digital Converter MAX31856, First, the circuit must be initialized, at least the CR0 and CR1 registers must be set.
My solution will be minimalistic, with the datasheet in hand I will create an init function
Code:
void initMAX31856 (void
(
CS_Low;
writetoSPI( 0x80, 0x01):    // CR0 onestot mode,, 50Hz filter
writetoSPI( 0x81, 0x03):    // CR1 1sample averaged , K type TC
CS_High;
)
It's minimalistic, but difficult to modify without a datasheet
possible modification
Code:
#define MAX31856_CR0 0x80
#define MAX31856_CR1 0x81
etc,

possible modification
for example, for the type of thermocouple (10 options) create an enumeration type ppus create a structure for all registries MAX31856 etc.
This will increase the consumption of MCU memory, we are not sure if this will improve clarity, etc.
I know this is somewhat of a philosophical question, but I would like to know what approach you take?
 

Hi,

basically:
If you need it you will need to spend the memory.
If you don´t need it you may save the memory.

But indeed it´s not exactly clear what
* you urgently need
* what´s "nice to have"

Are you talking about different functions, different pre-defined setups, different parameters....? code or data?
--> In most cases the compiler will optimize away "unused code and data".

****
If you want to control it on your own you have precompiler options like #ifdef, #ifndef and similar.

****

Or do you have basic questions about how to write .c files and .h files?

Klaus
 

OK how did it come about.
Inexplicably, I posted one of my projects..
People started writing to me with requests to add features, explaining where what and whether I could publish the source codes.
As a sample, I have published the source codes of the temperature and pressure measurement subsystem.
Yes, the drivers for the individual ICs are written by my minimalist system from the 8-bit era.
They started asking questions about what the code does, where I got the data, etc.
I started to make the code clearer for human reading, extensive use of #define, etc., I consistently used the syntax used in the datasheets for the given IC, sometimes one original line was replaced by several tens of lines in *.h and *.c.
The result doesn't seem more clear or flexible to me either.
So I started looking for something like the right way to write code intended for publication
When I mentioned the MAX31856, I was looking for inspiration from the manufacturer, who coincidentally also published instruction code for the STM32..
Both Analog Devices and the original Maxim appear to be sophisticated manufacturers from the USA, but their sample code has comments in Chinese or whatever (image font)I thought to myself, surely someone has written a book on this topic. Well, I didn't find any. So I asked here
 

Hi,

I didn´t expect your story...
Did you read my questions? Did you answer any of them?

I don´t know what you expect from us.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top