Programming With STM32: Getting Started With the Nucleo Board and C/C++ - eBook PDFpdf download
Programming With STM32: Getting Started With the Nucleo Board and C/C++ - eBook PDFpdf download
https://ebookluna.com/download/programming-with-stm32-getting-
started-with-the-nucleo-board-and-c-c-ebook-pdf/
https://ebookluna.com/download/programming-the-intel-galileo-getting-
started-with-the-arduino-compatible-development-board-ebook-pdf/
Programming Arduino: Getting Started with Sketches 2nd Edition - eBook PDF
https://ebookluna.com/download/programming-arduino-getting-started-with-
sketches-tab-ebook-pdf/
Programming the Photon: Getting Started with the Internet of Things 1st
edition - eBook PDF
https://ebookluna.com/download/programming-the-photon-getting-started-with-
the-internet-of-things-ebook-pdf/
Programming the Raspberry Pi, Third Edition: Getting Started with Python
Simon Monk - eBook PDF
https://ebookluna.com/download/programming-the-raspberry-pi-third-edition-
getting-started-with-python-ebook-pdf/
Programming Arduino: Getting Started with Sketches 3rd Edition Simon Monk -
eBook PDF
https://ebookluna.com/download/programming-arduino-getting-started-with-
sketches-ebook-pdf/
Programming the Photon: Getting Started with the Internet of Things (Tab)
1st Edition - eBook PDF
https://ebookluna.com/download/programming-the-photon-getting-started-with-
the-internet-of-things-tab-ebook-pdf/
https://ebookluna.com/product/ebook-pdf-programming-problem-solving-and-
abstraction-with-c/
Readings from Programming with C++ 1st Edition Kyla Mcmullen - eBook PDF
https://ebookluna.com/download/readings-from-programming-with-c-ebook-
pdf-2/
Readings from Programming with C++ 1st Edition Kyla Mcmullen - eBook PDF
https://ebookluna.com/download/readings-from-programming-with-c-ebook-pdf/
Copyright © 2018 by McGraw-Hill Education. All rights reserved. Except as
permitted under the United States Copyright Act of 1976, no part of this
publication may be reproduced or distributed in any form or by any means, or
stored in a database or retrieval system, without the prior written permission of
the publisher.
ISBN: 978-1-26-003132-4
MHID: 1-26-003132-2
The material in this eBook also appears in the print version of this title: ISBN:
978-1-26-003131-7, MHID: 1-26-003131-4.
All trademarks are trademarks of their respective owners. Rather than put a
trademark symbol after every occurrence of a trademarked name, we use names
in an editorial fashion only, and to the benefit of the trademark owner, with no
intention of infringement of the trademark. Where such designations appear in
this book, they have been printed with initial caps.
This is a copyrighted work and McGraw-Hill Education and its licensors reserve
all rights in and to the work. Use of this work is subject to these terms. Except as
permitted under the Copyright Act of 1976 and the right to store and retrieve one
copy of the work, you may not decompile, disassemble, reverse engineer,
reproduce, modify, create derivative works based upon, transmit, distribute,
disseminate, sell, publish or sublicense the work or any part of it without
McGraw-Hill Education’s prior consent. You may use the work for your own
noncommercial and personal use; any other use of the work is strictly prohibited.
Your right to use the work may be terminated if you fail to comply with these
terms.
Peter enjoys cooking, fine wine, traveling, and spending quality time with his
family. His wife is my daughter, Shauna, and their child is my two-year-old
granddaughter, Evangeline.
Peter and I have spent many hours discussing many topics ranging from ancient
Greek artifacts to the latest technologies impacting modern society. I always
look forward to those interesting and challenging discussions.
CONTENTS AT A GLANCE
3 STM32CubeMX Application
6 Interrupts
7 Timers
9 Analog-to-Digital Conversion
Index
CONTENTS
Preface
3 STM32CubeMX Application
Pinout Tab
MCU Alternative Functions
Integrated Peripheral (IP) Tree Pane
Creating an Example Project using CubeMX
The main.c Code Listing
ARM Cortex Microcontroller Software Interface Standard (CMSIS)
CubeMX-Generated C Code
Compiling and Downloading the Project
Downloading the Hex Code
Summary
6 Interrupts
Interrupts
NVIC Specifications
Interrupt Process
External Interrupts
Interrupt Demonstration
Summary
7 Timers
STM Timer Peripherals
STM Timer Configuration
Update Event Calculation
Polled or Non-interrupt Blink LED Timer Demonstration
Test Run
Interrupt-Driven Blink LED Timer Demonstration
Test Run
Multi-rate Interrupt-Driven Blink LED Timer Demonstration
Test Run
Modification to the Multi-rate Program
Test Run
Summary
9 Analog-to-Digital Conversion
ADC Functions
ADC Module with HAL
ADC Conversion Modes
Channels, Groups, and Ranks
ADC Demonstration
ADC Demonstration Software
Summary
Microcomputer vs Microcontroller
I believe at the start of this book that it must make very clear the differences
between a microcomputer and a MCU. The reason for this distinction is very
simple: STM is a company that designs and manufacturers MCUs, not
microcomputers. I think my following definition of a MCU is as good as any
that I have read:
Right away, you can see from the definition that a MCU contains a
microprocessor which is sometimes referred to as a microcomputer. There also
must be both dynamic or volatile memory as well as nonvolatile or static
memory, where the latter holds any programs or scripts necessary to run the
Discovering Diverse Content Through
Random Scribd Documents
General offered her his arm. She took it very graciously, and was led
away. But before leaving the room she halted, turned round, and
stared very significantly at the two elderly ladies who were still
seated on the sofa, overwhelmed in surprise, horror, and indignation.
Infantry, who was only a lieutenant in his regiment, observing that
the General had recognised the social right of his wife, which she
had derived solely from him, instantly rushed up to Lady Gallopaway,
and offered her an arm (which she took), led her away in triumph,
leaving his own Colonel (Damzè) and old Mr. Revenue Board gasping
and gaping at each other in mutual disgust and consternation. Had a
shell burst in the building, had the powder magazine exploded and
shattered all the windows, the commotion could scarcely have been
greater than it was at that moment. No one could account for this
extraordinary conduct, or caprice, as it was termed, on the part of
the old General. Damzè, who had just been flattering him concerning
his wonderful achievements, now declared that "the old fool had
become half-witted since eighteen hundred and forty-seven," while
Revenue Board, who a quarter of an hour previously had, to the
General's face, held forth on the unflinching independence which
had marked his character through life, now protested—openly
protested—that he had been a time-server throughout his entire
career, and had some object in thus truckling before the son of an
influential peer! The ladies on the sofa stared at each other; now
commiseratingly and in silence for at least two minutes, then
simultaneously ejaculated: "What can it mean!"
"I thought it would have been me," said Mrs. Revenue Board.
"You?" said Mrs. Damzè.
"Yes; why not? My husband is a civilian of twenty years' standing."
"Is not my husband a Lieutenant-Colonel and a C.B.? If he were only
a Major and a C.B. he would take precedence of Mr. Revenue
Board."
"You are quite mistaken."
"Indeed not. Do you suppose a C.B. goes for nothing?"
"No; but——"
Here Lieutenant-Colonel Damzè and Mr. Revenue Board, who had
been discussing the same question, but in a calmer spirit than their
wives, approached, and, making common cause against the upstart
enemy (Infantry and his wife), formed a quartette and went into the
supper room; where, to their intense mortification, they heard little
Mrs. Infantry talking loudly, on purpose to attract the notice of all
present. What was even more mortifying still, the old General was
paying her marked attention.
The red party, that is to say, the military, were in very high spirits;
the black, the civilians, correspondingly depressed. The quartette,
consisting of Damzè and Revenue Board, and their wives, ate
voraciously, but evidently without appetite. They sipped their wine
with an absent formality, which was very entertaining to lookers-on,
who were in no way interested in the momentous question which
was preying on their very souls.
"It shall not end here," said Damzè, moodily fixing his eyes on the
chandelier.
"Not, indeed!" said Mr. Revenue Board.
"I shall put my case to the Governor-General direct," said Damzè.
"His Lordship is a near connexion of mine."
"I am perfectly aware of that," said Mr. Revenue Board; "but it is my
intention to submit my case to his Lordship through Mr. Bommerson,
the Lieutenant-Governor of these provinces, officially; and, if his
Lordship's opinion should be adverse, I shall have my appeal to the
Court of Directors, amongst whom, thank Heaven! I have several
relations and warm friends."
"And you will write, I hope, my dear," said Mrs. Revenue Board, "to
Sir John Bobgrouse, who is the President of the Board of Control,
and whose secretary married your first cousin—recollect!"
"We can write, too," said Mrs. Lieutenant-Colonel Damzè.
"You may write to anybody you please," said Mrs. Revenue Board,
defiantly and contemptuously; "but you will remember that the point
between us is this—that even if your husband, in consequence of
having got, no matter how, a C.B.ship, has the right to precede my
husband, a civilian of twenty years' standing—whether you have the
right to precede me? That is the question; and I hope, Revenue
dear, you will not fail to raise it."
Reader, the question was submitted in all its bearings for the
consideration of the Most Noble the Governor-General of India, who,
declining to take upon himself so fearful a responsibility, referred the
matter to the Home Government. Leadenhall-street had something
to say to it, and so had the Board of Control. While the case was
pending, the newspapers in every part of India literally teemed with
letters on the subject, and their editors were invited to give their
opinions thereon. Only one of the number was weak enough to do
this, and bitterly did he repent of his rashness; for, having decided in
favour of the C.B. and of Mrs. C.B., he lost (so he confessed to me)
no less than six-and-twenty civilians (each of twenty years' standing)
in his subscription-list. For more than eighteen months this
precedence question formed a leading topic, not only in the public
prints, but in private circles. It became, in short, a perfect nuisance.
At length the decision of the Home Government came out to India;
but, alas! they had only half done their work. They had given C.B.
the precedence over the civilian of twenty years' standing, but had
been silent about their wives! So, the matter was "referred back." A
clerk in the Private Secretary's office told me that he was occupied
for three hours in copying only the Governor-General's minute on the
Court's despatch, which was a very lengthy one, and signed by the
chairman for himself and the other directors, whose names were
given in full. He further informed me that the whole of the
documents connected with this weighty affair would, if put into type,
form a volume five times as bulky as Sir William Napier's Conquest
of Scinde!
How the matter was settled eventually I do not know; for, when I
left India, the question had not been decided. On the great point,
when it was referred for a second time to the Home Authorities,
there was a difference of opinion between the Court of Directors and
the Board of Control, and a long correspondence ensued on the
subject, between each of these departments of the Indian
Government and the Governor-General, who was required to have
the case laid before the Advocates-General of the Supreme Courts at
the various Presidencies. These gentlemen differed one with the
other in their views of the case, each alleging that the point lay in a
nutshell, and was as clear as possible. For all I know to the contrary,
it may be in the nutshell at this moment. Both Lieutenant-Colonel
Damzè and Mr. Revenue Board laid "cases" before the Calcutta
barristers, who pocketed their fees, and laconically expressed their
opinions respectively, that the parties who consulted them were in
the right—"there could be no doubt on the point," they said. Damzè
sent a copy of his case, and the opinion of his barrister thereon, to
Revenue Board, who rather triumphantly returned the compliment. I
regret to say, that this contest engendered in Agra a great deal of
what is called bad blood, and induced many ladies to descend to
very unseemly personalities. For instance, Mrs. Damzè one evening,
at the band-stand, told Mrs. Revenue Board, that when she (Mrs. R.
B.) returned to England, she would have no rank at all, as her
husband was not an esquire even—but a "mister" in his own country.
To which Mrs. Revenue Board replied:—
"And you, pray? Is not your husband in the Company's service?"
"Yes," rejoined Mrs. Damzè; "but you forget the C.B.!"
Let us now return to the Honourable Lieutenant Infantry. When that
officer came up, and led away Lady Gallopaway to supper, Damzè
was overheard to say, "I'll take the shine out of that young
gentleman." And, if taking the shine meant constantly bullying the
subaltern, Damzè certainly kept his word. And when the next hot
weather came, and the Lieutenant wished to accompany his sick
wife to the Hills, Damzè, when he forwarded the application for six
months' leave of absence, wrote privately to the Assistant Adjutant-
General, and recommended that it should not be granted. The
honourable subaltern, however, was rather too strong for his colonel,
in the way of interest. Presuming on the acquaintance which existed
between his father and the Commander-in-Chief, he wrote a letter to
that functionary, and a few days afterwards found himself in general
orders. The wrath of Damzè may be easily imagined, especially as
he had boasted to several of his officers of having put a spoke in the
Lieutenant's wheel. And by way of throwing salt upon the Colonel's
wounds, the Lieutenant called upon him, and, in the politest manner
possible, inquired if there was anything he could do for him at head-
quarters.
While at Agra, a Bengalee Baboo called upon me. Judging from his
appearance, I should have guessed his age to be about fifty years;
but he was upwards of seventy. He spoke English with marvellous
fluency and accuracy, and could read and write the language as well
and as elegantly as any educated European. He was, perhaps, the
cleverest Hindoo whom I encountered during my sojourn in the East.
His manners were peculiarly courteous and winning, and there was
an air of penitence about the man, which, apart from his abilities,
induced me to treat him with kindness and consideration. His name
was—let us say—Nobinkissen.
The history of Nobinkissen was simply this. He was a Brahmin of the
highest caste, and, at the age of eighteen, was a writer in the
service of the government, on a salary of ten rupees per month. He
ingratiated himself with every civilian under whom he served, and
gradually rose, step by step, until he became the Sheristadar, or
head clerk, of a circuit-judge of a court of appeal. In this office he
acquired riches, and was still adding to his store, when his official
career was brought prematurely to a close.
I must here inform the reader that not one civilian in a hundred, no
matter what his rank or grade, can read and write Hindostanee or
Persian, although the majority of them have some colloquial
knowledge of both those languages. Yet, as a matter of course, they
append their signatures to every document of which, on hearing it
read aloud to them by their native officials, they approve. Their
orders they dictate orally; those orders are transcribed by the
Sheristadar, who gives them to a native writer to copy. This done,
they are read aloud for correction or approval, and then signed in
English by the covenanted civilian. Before leaving office every day,
such civilian may have to sign fifty, sixty, or a hundred documents;
for the rule is, not to sign each of them when read, but to sign them
in a mass at the breaking-up of the court. Here Nobinkissen invented
his means of money making. Whenever the judge gave a decree in
any case of importance, he made a counterpart of such decree, and
when the signing time came, obtained, without any sort of trouble or
inquiry, the signature of the Sahib and the seal of the Court to both
documents. He was thus, to all intents and purposes—or, at all
events, for his own—in possession of something tantamount to the
fee-simple of the lands in dispute. He could arm either the appellant
or the respondent with the final decree of the Court, under the hand
and official seal of the judge. The only question with him now was,
which of the litigants would give the most money, and to each, in
private, and in the Sahib's name, he exhibited the documents. The
highest bidder, of course, gained the day, whereupon Nobinkissen
took the coin, handed over one of the decrees, and burnt the other.
It fell out that Nobinkissen was attacked with fever, and, in a state
bordering on delirium, he parted with, that is to say, sold, to both
respondent and appellant, a decree, under the hand and seal of the
judge, such decree arming the holder with the power to take
possession of a very large estate in Bengal. Each party, fearful of a
disturbance, which often occurs when possession of an estate is
sought for, applied to the magistrate of a district, under a certain
regulation of government, for assistance, in order to enable him to
carry out the judge's decree, which each, as a matter of course,
produced. The magistrate was naturally much perplexed, and made
a reference to the judge, who could only say he had signed but one
decree. There was then a report made to the government by the
magistrate. An investigation ensued, and the judge was, meanwhile,
suspended, for great suspicion lurked in the minds of many that he
was not so innocent as he affected to be. When Nobinkissen
recovered from his sickness, and saw the dilemma in which his
superior, the judge, was placed, he made a clean breast of it, and
confessed that the guilt was his, and his alone. Nobinkissen was
tried, convicted, and sentenced to be imprisoned in irons for the
term of his natural life. For nine years he was in the gaol at Alipore,
near Calcutta. At the expiration of that period he was called upon to
furnish some information of which he was possessed, in relation to
certain public affairs. He was brought from the prison, confronted
with several officials, amongst whom was a member of the council.
His altered appearance, his emaciated form, his attitude of despair,
and the intelligence and readiness with which he responded to the
questions put to him, touched the hearts of those by whom he was
examined, and the member of council, who has been since a
director of the East India Company, spoke to the Governor-General,
and eventually obtained Nobinkissen's pardon and release. The
Hindoos and Mussulmans in India (like the Arabs) do not regard
being guilty of a fraud or theft as a disgrace. The degrading part of
the business is, being convicted, and Nobinkissen, on being set at
liberty, could not face his countrymen in Bengal, and therefore
retired to the Upper Provinces, where he lived in comparative
obscurity, and in easy circumstances, for he had not disgorged his ill-
gotten gains. His wife had taken care of them during his captivity.
At the time that Nobinkissen called upon me, the government of
India were in considerable difficulty in respect to finance. A new loan
had been opened, but it did not fill, and the government had very
wisely determined upon closing it. Nobinkissen made this a topic of
conversation, and his views—albeit they came from a man who had
been convicted of a fraud—are, at the present time especially,
entitled to the very gravest consideration.
"Ah, sir!" he remarked, "it is a pitiful thing that the government of a
great empire like this should ever be in pecuniary difficulties and put
to their wits' end for a few millions annually, in order to make the
receipts square with the expenditure."
"But how can it be helped?" I asked.
"Easily, sir," he replied. "Why not make it expedient to do away with
the perpetual settlement of Lord Cornwallis, and resettle the whole
of Bengal? That is by far the most fertile province in the East; but it
is taxed lighter than even these poor lands of the Upper Provinces.
Look at the Durbungah Rajah. Nearly the whole of Tirhoot, the
garden of India, belongs to him, and he does not pay into the
government treasury half a lac (five thousand pounds) per annum,
while his collections amount to upwards of twenty lacs. These are
the men who get hold of the money and bury it, and keep it from
circulating."
"But all zemindarees (lands) are not so profitable in Bengal?"
"No; many are not worth holding—especially the smaller ones,
although the land is just as good, and just as well cultivated."
"But how is that?"
"They are so heavily taxed. You must know, sir, that in those days—
the days of Lord Cornwallis—the greatest frauds were committed, in
respect to the perpetual settlement. The natives who were about,
and under, the settlement officers all made immense fortunes, and
the zemindars from whom they took their bribes, have profited ever
since to the cost of the poorer zemindars, who could not or would
not bribe, and to the cost of the British government. It is a great
mistake to suppose that the whole of the landholders in Bengal
would cry out against a resettlement of that province. Only men
holding vast tracts of country, at a comparatively nominal rent,
would cry out."
"And tax the British government with a breach of faith?"
"Yes. But what need the government care for that cry, especially
when its act is not only expedient, but would be just withal? In
Bengal, all the great zemindars are rich, very rich men. In these
provinces, with very, very few exceptions, they are poor, so that the
whole of Upper India would be glad to see the perpetual settlement
done away with, and the land resettled."
"Why so?"
"That is only human—and, certainly, Asiatic—nature. Few of us like
to behold our neighbours better off than ourselves; so that the cry of
faith-breaking would not meet with a response in this part of the
world."
"Yes; but in Europe the cry would be too powerful to contend
against. The Exeter Hall orators and the spouters at the Court of
Proprietors would—"
"Ah, sir! India should either be governed in India or in England. It is
the number of wheels in the government that clogs the movement
of the machine."
"Very true."
"But who are these men—these zemindars with whom you are
required to keep an implicit faith? Are they your friends? If so, why
do they never come forward to assist you in your difficulties? Did a
single zemindar, when, after the battle of Ferozeshah, the empire
was shaking in the balance, lift a finger to help the government of
India? And, to-morrow, if your rule were at stake, and dependent on
their assistance, think you they would render it? Think you they
would furnish money if your treasury was exhausted? Not one pice!
Think you they would furnish men to protect your stations denuded
of troops? No! Although hundreds of them can each turn out a
thousand or two of followers, armed with iron-bound bludgeons,
swords, and shields, when they desire to intimidate an European
indigo-planter, or to fight a battle between themselves about a
boundary question. These are the men who, in your greatest need,
would remain neutral until, if it so happened, you were brought to
your last gasp, when, as one man, they would not fail to rise and
give you the final blow."
"Do you believe that? I do not."
"Sir, I know my own countrymen better than you do."
"If such a state of affairs were to come about, and these zemindars
remained neutral, of course the cry of breaking faith would be
absurd in the extreme. Neutrality, in such a case, would be almost as
bad as hostility."
[Nobinkissen's prophecy has been fulfilled to the letter. Our rule has
been at stake, in imminent peril, and not one of these men has
offered to assist us with men or money. The Rajahs of Durbungah
and Burdwan alone, to say nothing of the Newab of Moorshedabad,
between them could have furnished an army of, at the very least,
five thousand stalwart fighting-men, whereas they have looked upon
our difficulties in perfect apathy. It is from the coffers of men of this
stamp that large sums should be extracted annually towards keeping
up a vast—an overwhelming—European force in India. Faith with
such men as these! What claim have they to our faintest
consideration! What right to expect that we shall any longer forego
the collection of several extra millions annually—several extra
millions which, to every intent and purpose, is our just due?]
"There is a line in Shakespeare, sir," Nobinkissen continued, "which
the government of India should adopt as its motto, and act up to
consistently—
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookluna.com