First coarse run to fix coding style in locm3.
Added --terse and --mailback options to the make stylecheck target. It also does continue even if it enounters a possible error. We decided on two exceptions from the linux kernel coding standard: - Empty wait while loops may end with ; on the same line. - All blocks after while, if, for have to be in brackets even if they only contain one statement. Otherwise it is easy to introduce an error. Checkpatch needs to be adapted to reflect those changes.
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/**@{*/
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief CRC Reset.
|
||||
|
||||
Reset the CRC unit and forces the data register to all 1s.
|
||||
@@ -39,7 +39,7 @@ void crc_reset(void)
|
||||
CRC_CR |= CRC_CR_RESET;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief CRC Calculate.
|
||||
|
||||
Writes a data word to the register, the write operation stalling until the
|
||||
@@ -52,11 +52,11 @@ computation is complete.
|
||||
u32 crc_calculate(u32 data)
|
||||
{
|
||||
CRC_DR = data;
|
||||
// Data sheet says this blocks until it's ready....
|
||||
/* Data sheet says this blocks until it's ready.... */
|
||||
return CRC_DR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief CRC Calculate of a Block of Data.
|
||||
|
||||
Writes data words consecutively to the register, the write operation stalling
|
||||
@@ -70,9 +70,11 @@ until the computation of each word is complete.
|
||||
u32 crc_calculate_block(u32 *datap, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
CRC_DR = datap[i];
|
||||
}
|
||||
|
||||
return CRC_DR;
|
||||
}
|
||||
/**@}*/
|
||||
|
||||
@@ -120,12 +120,12 @@ LGPL License Terms @ref lgpl_license
|
||||
#define MASK8 0xFF
|
||||
#define MASK12 0xFFF
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Enable.
|
||||
|
||||
Enable a digital to analog converter channel. After setting this enable, the DAC
|
||||
requires a t<sub>wakeup</sub> time typically around 10 microseconds before it
|
||||
actually wakes up.
|
||||
Enable a digital to analog converter channel. After setting this enable, the
|
||||
DAC requires a t<sub>wakeup</sub> time typically around 10 microseconds before
|
||||
it actually wakes up.
|
||||
|
||||
@param[in] dac_channel enum ::data_channel.
|
||||
*/
|
||||
@@ -145,7 +145,7 @@ void dac_enable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Disable.
|
||||
|
||||
Disable a digital to analog converter channel.
|
||||
@@ -168,13 +168,13 @@ void dac_disable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Output Buffer Enable.
|
||||
|
||||
Enable a digital to analog converter channel output drive buffer. This is an optional
|
||||
amplifying buffer that provides additional drive for the output signal. The
|
||||
buffer is enabled by default after a reset and needs to be explicitly disabled
|
||||
if required.
|
||||
Enable a digital to analog converter channel output drive buffer. This is an
|
||||
optional amplifying buffer that provides additional drive for the output
|
||||
signal. The buffer is enabled by default after a reset and needs to be
|
||||
explicitly disabled if required.
|
||||
|
||||
@param[in] dac_channel enum ::data_channel.
|
||||
*/
|
||||
@@ -193,12 +193,12 @@ void dac_buffer_enable(data_channel dac_channel)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Output Buffer Disable.
|
||||
|
||||
Disable a digital to analog converter channel output drive buffer. Disabling this will
|
||||
reduce power consumption slightly and will increase the output impedance of the DAC.
|
||||
The buffers are enabled by default after a reset.
|
||||
Disable a digital to analog converter channel output drive buffer. Disabling
|
||||
this will reduce power consumption slightly and will increase the output
|
||||
impedance of the DAC. The buffers are enabled by default after a reset.
|
||||
|
||||
@param[in] dac_channel enum ::data_channel.
|
||||
*/
|
||||
@@ -217,7 +217,7 @@ void dac_buffer_disable(data_channel dac_channel)
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel DMA Enable.
|
||||
|
||||
Enable a digital to analog converter channel DMA mode (connected to DMA2 channel
|
||||
@@ -242,7 +242,7 @@ void dac_dma_enable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel DMA Disable.
|
||||
|
||||
Disable a digital to analog converter channel DMA mode.
|
||||
@@ -265,13 +265,13 @@ void dac_dma_disable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Trigger Enable.
|
||||
|
||||
Enable a digital to analog converter channel external trigger mode. This allows an
|
||||
external trigger to initiate register transfers from the buffer register to the DAC
|
||||
output register, followed by a DMA transfer to the buffer register if DMA is enabled.
|
||||
The trigger source must also be selected.
|
||||
Enable a digital to analog converter channel external trigger mode. This allows
|
||||
an external trigger to initiate register transfers from the buffer register to
|
||||
the DAC output register, followed by a DMA transfer to the buffer register if
|
||||
DMA is enabled. The trigger source must also be selected.
|
||||
|
||||
@param[in] dac_channel enum ::data_channel.
|
||||
*/
|
||||
@@ -291,7 +291,7 @@ void dac_trigger_enable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DAC Channel Trigger Disable.
|
||||
|
||||
Disable a digital to analog converter channel external trigger.
|
||||
@@ -314,14 +314,15 @@ void dac_trigger_disable(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set DAC Channel Trigger Source.
|
||||
|
||||
Sets the digital to analog converter trigger source, which can be taken from various
|
||||
timers, an external trigger or a software trigger.
|
||||
Sets the digital to analog converter trigger source, which can be taken from
|
||||
various timers, an external trigger or a software trigger.
|
||||
|
||||
@param[in] dac_trig_src u32. Taken from @ref dac_trig2_sel or @ref dac_trig1_sel or
|
||||
a logical OR of one of each of these to set both channels simultaneously.
|
||||
@param[in] dac_trig_src u32. Taken from @ref dac_trig2_sel or @ref
|
||||
dac_trig1_sel or a logical OR of one of each of these to set both channels
|
||||
simultaneously.
|
||||
*/
|
||||
|
||||
void dac_set_trigger_source(u32 dac_trig_src)
|
||||
@@ -329,17 +330,17 @@ void dac_set_trigger_source(u32 dac_trig_src)
|
||||
DAC_CR |= dac_trig_src;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Enable and Set DAC Channel Waveform Generation.
|
||||
|
||||
Enable the digital to analog converter waveform generation as either pseudo-random
|
||||
noise or triangular wave. These signals are superimposed on existing output values
|
||||
in the DAC output registers.
|
||||
Enable the digital to analog converter waveform generation as either
|
||||
pseudo-random noise or triangular wave. These signals are superimposed on
|
||||
existing output values in the DAC output registers.
|
||||
|
||||
@note The DAC trigger must be enabled for this to work.
|
||||
|
||||
@param[in] dac_wave_ens u32. Taken from @ref dac_wave1_en or @ref dac_wave2_en or
|
||||
a logical OR of one of each of these to set both channels simultaneously.
|
||||
@param[in] dac_wave_ens u32. Taken from @ref dac_wave1_en or @ref dac_wave2_en
|
||||
or a logical OR of one of each of these to set both channels simultaneously.
|
||||
*/
|
||||
|
||||
void dac_set_waveform_generation(u32 dac_wave_ens)
|
||||
@@ -347,7 +348,7 @@ void dac_set_waveform_generation(u32 dac_wave_ens)
|
||||
DAC_CR |= dac_wave_ens;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Disable DAC Channel Waveform Generation.
|
||||
|
||||
Disable a digital to analog converter channel superimposed waveform generation.
|
||||
@@ -370,22 +371,24 @@ void dac_disable_waveform_generation(data_channel dac_channel)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set DAC Channel LFSR Mask or Triangle Wave Amplitude.
|
||||
|
||||
Sets the digital to analog converter superimposed waveform generation characteristics.
|
||||
@li If the noise generation mode is set, this sets the length of the PRBS sequence and
|
||||
hence the amplitude of the output noise signal. Default setting is length 1.
|
||||
@li If the triangle wave generation mode is set, this sets the amplitude of the
|
||||
output signal as 2^(n)-1 where n is the parameter value. Default setting is 1.
|
||||
Sets the digital to analog converter superimposed waveform generation
|
||||
characteristics. @li If the noise generation mode is set, this sets the length
|
||||
of the PRBS sequence and hence the amplitude of the output noise signal.
|
||||
Default setting is length 1. @li If the triangle wave generation mode is set,
|
||||
this sets the amplitude of the output signal as 2^(n)-1 where n is the
|
||||
parameter value. Default setting is 1.
|
||||
|
||||
@note High amplitude levels of these waveforms can overload the DAC and distort the
|
||||
signal output.
|
||||
@note This must be called before enabling the DAC as the settings will then become read-only.
|
||||
@note High amplitude levels of these waveforms can overload the DAC and distort
|
||||
the signal output.
|
||||
@note This must be called before enabling the DAC as the settings will then
|
||||
become read-only.
|
||||
@note The DAC trigger must be enabled for this to work.
|
||||
|
||||
@param[in] dac_mamp u32. Taken from @ref dac_mamp2 or @ref dac_mamp1 or a logical OR
|
||||
of one of each of these to set both channels simultaneously.
|
||||
@param[in] dac_mamp u32. Taken from @ref dac_mamp2 or @ref dac_mamp1 or a
|
||||
logical OR of one of each of these to set both channels simultaneously.
|
||||
*/
|
||||
|
||||
void dac_set_waveform_characteristics(u32 dac_mamp)
|
||||
@@ -393,7 +396,7 @@ void dac_set_waveform_characteristics(u32 dac_mamp)
|
||||
DAC_CR |= dac_mamp;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Load DAC Data Register.
|
||||
|
||||
Loads the appropriate digital to analog converter data register with 12 or 8 bit
|
||||
@@ -407,10 +410,10 @@ data to be converted on a channel. The data can be aligned as follows:
|
||||
@param[in] dac_channel enum ::data_channel.
|
||||
*/
|
||||
|
||||
void dac_load_data_buffer_single(u16 dac_data, data_align dac_data_format, data_channel dac_channel)
|
||||
void dac_load_data_buffer_single(u16 dac_data, data_align dac_data_format,
|
||||
data_channel dac_channel)
|
||||
{
|
||||
if (dac_channel == CHANNEL_1)
|
||||
{
|
||||
if (dac_channel == CHANNEL_1) {
|
||||
switch (dac_data_format) {
|
||||
case RIGHT8:
|
||||
DAC_DHR8R1 = dac_data;
|
||||
@@ -422,9 +425,7 @@ void dac_load_data_buffer_single(u16 dac_data, data_align dac_data_format, data_
|
||||
DAC_DHR12L1 = dac_data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (dac_channel == CHANNEL_2)
|
||||
{
|
||||
} else if (dac_channel == CHANNEL_2) {
|
||||
switch (dac_data_format) {
|
||||
case RIGHT8:
|
||||
DAC_DHR8R2 = dac_data;
|
||||
@@ -439,7 +440,7 @@ void dac_load_data_buffer_single(u16 dac_data, data_align dac_data_format, data_
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Load DAC Dual Data Register.
|
||||
|
||||
Loads the appropriate digital to analog converter dual data register with 12 or
|
||||
@@ -449,25 +450,29 @@ identically.
|
||||
|
||||
@param[in] dac_data1 u16 for channel 1 with appropriate alignment.
|
||||
@param[in] dac_data2 u16 for channel 2 with appropriate alignment.
|
||||
@param[in] dac_data_format enum ::data_align. Right or left aligned, and 8 or 12 bit.
|
||||
@param[in] dac_data_format enum ::data_align. Right or left aligned, and 8 or
|
||||
12 bit.
|
||||
*/
|
||||
|
||||
void dac_load_data_buffer_dual(u16 dac_data1, u16 dac_data2, data_align dac_data_format)
|
||||
void dac_load_data_buffer_dual(u16 dac_data1, u16 dac_data2,
|
||||
data_align dac_data_format)
|
||||
{
|
||||
switch (dac_data_format) {
|
||||
case RIGHT8:
|
||||
DAC_DHR8RD = ((dac_data1 & MASK8) | ((dac_data2 & MASK8) << 8));
|
||||
break;
|
||||
case RIGHT12:
|
||||
DAC_DHR12RD = ((dac_data1 & MASK12) | ((dac_data2 & MASK12) << 16));
|
||||
DAC_DHR12RD = ((dac_data1 & MASK12) |
|
||||
((dac_data2 & MASK12) << 16));
|
||||
break;
|
||||
case LEFT12:
|
||||
DAC_DHR12LD = ((dac_data1 & MASK12) | ((dac_data2 & MASK12) << 16));
|
||||
DAC_DHR12LD = ((dac_data1 & MASK12) |
|
||||
((dac_data2 & MASK12) << 16));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Trigger the DAC by a Software Trigger.
|
||||
|
||||
If the trigger source is set to be a software trigger, cause a trigger to occur.
|
||||
|
||||
@@ -40,7 +40,7 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
#include <libopencm3/stm32/dma.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Reset
|
||||
|
||||
The channel is disabled and configuration registers are cleared.
|
||||
@@ -63,7 +63,7 @@ void dma_channel_reset(u32 dma, u8 channel)
|
||||
DMA_IFCR(dma) |= DMA_IFCR_CIF(channel);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Clear Interrupt Flag
|
||||
|
||||
The interrupt flag for the channel is cleared. More than one interrupt for the
|
||||
@@ -71,7 +71,8 @@ same channel may be cleared by using the logical OR of the interrupt flags.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: @ref dma_ch
|
||||
@param[in] interrupts unsigned int32. Logical OR of interrupt numbers: @ref dma_if_offset
|
||||
@param[in] interrupts unsigned int32. Logical OR of interrupt numbers: @ref
|
||||
dma_if_offset
|
||||
*/
|
||||
|
||||
void dma_clear_interrupt_flags(u32 dma, u8 channel, u32 interrupts)
|
||||
@@ -81,7 +82,7 @@ void dma_clear_interrupt_flags(u32 dma, u8 channel, u32 interrupts)
|
||||
DMA_IFCR(dma) = flags;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Read Interrupt Flag
|
||||
|
||||
The interrupt flag for the channel is returned.
|
||||
@@ -99,7 +100,7 @@ bool dma_get_interrupt_flag(u32 dma, u8 channel, u32 interrupt)
|
||||
return ((DMA_ISR(dma) & flag) > 0);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Memory to Memory Transfers
|
||||
|
||||
Memory to memory transfers do not require a trigger to activate each transfer.
|
||||
@@ -116,7 +117,7 @@ void dma_enable_mem2mem_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_CIRC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set Priority
|
||||
|
||||
Channel Priority has four levels: low to very high. This has precedence over the
|
||||
@@ -133,7 +134,7 @@ void dma_set_priority(u32 dma, u8 channel, u32 prio)
|
||||
DMA_CCR(dma, channel) |= prio;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set Memory Word Width
|
||||
|
||||
Set the memory word width 8 bits, 16 bits, or 32 bits. Refer to datasheet for
|
||||
@@ -151,16 +152,17 @@ void dma_set_memory_size(u32 dma, u8 channel, u32 mem_size)
|
||||
DMA_CCR(dma, channel) |= mem_size;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set Peripheral Word Width
|
||||
|
||||
Set the peripheral word width 8 bits, 16 bits, or 32 bits. Refer to datasheet for
|
||||
alignment information if the source and destination widths do not match, or
|
||||
Set the peripheral word width 8 bits, 16 bits, or 32 bits. Refer to datasheet
|
||||
for alignment information if the source and destination widths do not match, or
|
||||
if the peripheral does not support byte or half-word writes.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: 1-7 for DMA1 or 1-5 for DMA2
|
||||
@param[in] peripheral_size unsigned int32. Peripheral word width @ref dma_ch_perwidth.
|
||||
@param[in] peripheral_size unsigned int32. Peripheral word width @ref
|
||||
dma_ch_perwidth.
|
||||
*/
|
||||
|
||||
void dma_set_peripheral_size(u32 dma, u8 channel, u32 peripheral_size)
|
||||
@@ -169,7 +171,7 @@ void dma_set_peripheral_size(u32 dma, u8 channel, u32 peripheral_size)
|
||||
DMA_CCR(dma, channel) |= peripheral_size;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Memory Increment after Transfer
|
||||
|
||||
Following each transfer the current memory address is incremented by
|
||||
@@ -185,7 +187,7 @@ void dma_enable_memory_increment_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_MINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Memory Increment after Transfer
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -197,7 +199,7 @@ void dma_disable_memory_increment_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_MINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Peripheral Increment after Transfer
|
||||
|
||||
Following each transfer the current peripheral address is incremented by
|
||||
@@ -213,7 +215,7 @@ void dma_enable_peripheral_increment_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_PINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Peripheral Increment after Transfer
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -225,7 +227,7 @@ void dma_disable_peripheral_increment_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_PINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Memory Circular Mode
|
||||
|
||||
After the number of bytes/words to be transferred has been completed, the
|
||||
@@ -245,7 +247,7 @@ void dma_enable_circular_mode(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_MEM2MEM;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Transfers from a Peripheral
|
||||
|
||||
The data direction is set to read from a peripheral.
|
||||
@@ -259,7 +261,7 @@ void dma_set_read_from_peripheral(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_DIR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Transfers from Memory
|
||||
|
||||
The data direction is set to read from memory.
|
||||
@@ -273,7 +275,7 @@ void dma_set_read_from_memory(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_DIR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Interrupt on Transfer Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -285,7 +287,7 @@ void dma_enable_transfer_error_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_TEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Interrupt on Transfer Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -297,7 +299,7 @@ void dma_disable_transfer_error_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_TEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Interrupt on Transfer Half Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -309,7 +311,7 @@ void dma_enable_half_transfer_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_HTIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Interrupt on Transfer Half Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -321,7 +323,7 @@ void dma_disable_half_transfer_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_HTIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Interrupt on Transfer Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -333,7 +335,7 @@ void dma_enable_transfer_complete_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_TCIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Interrupt on Transfer Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -345,7 +347,7 @@ void dma_disable_transfer_complete_interrupt(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_TCIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -357,10 +359,11 @@ void dma_enable_channel(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) |= DMA_CCR_EN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable
|
||||
|
||||
@note The DMA channel registers retain their values when the channel is disabled.
|
||||
@note The DMA channel registers retain their values when the channel is
|
||||
disabled.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: 1-7 for DMA1 or 1-5 for DMA2
|
||||
@@ -371,14 +374,14 @@ void dma_disable_channel(u32 dma, u8 channel)
|
||||
DMA_CCR(dma, channel) &= ~DMA_CCR_EN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set the Peripheral Address
|
||||
|
||||
Set the address of the peripheral register to or from which data is to be transferred.
|
||||
Refer to the documentation for the specific peripheral.
|
||||
Set the address of the peripheral register to or from which data is to be
|
||||
transferred. Refer to the documentation for the specific peripheral.
|
||||
|
||||
@note The DMA channel must be disabled before setting this address. This function
|
||||
has no effect if the channel is enabled.
|
||||
@note The DMA channel must be disabled before setting this address. This
|
||||
function has no effect if the channel is enabled.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: 1-7 for DMA1 or 1-5 for DMA2
|
||||
@@ -387,15 +390,16 @@ has no effect if the channel is enabled.
|
||||
|
||||
void dma_set_peripheral_address(u32 dma, u8 channel, u32 address)
|
||||
{
|
||||
if (!(DMA_CCR(dma, channel) & DMA_CCR_EN))
|
||||
if (!(DMA_CCR(dma, channel) & DMA_CCR_EN)) {
|
||||
DMA_CPAR(dma, channel) = (u32) address;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set the Base Memory Address
|
||||
|
||||
@note The DMA channel must be disabled before setting this address. This function
|
||||
has no effect if the channel is enabled.
|
||||
@note The DMA channel must be disabled before setting this address. This
|
||||
function has no effect if the channel is enabled.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: 1-7 for DMA1 or 1-5 for DMA2
|
||||
@@ -404,19 +408,21 @@ has no effect if the channel is enabled.
|
||||
|
||||
void dma_set_memory_address(u32 dma, u8 channel, u32 address)
|
||||
{
|
||||
if (!(DMA_CCR(dma, channel) & DMA_CCR_EN))
|
||||
if (!(DMA_CCR(dma, channel) & DMA_CCR_EN)) {
|
||||
DMA_CMAR(dma, channel) = (u32) address;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Set the Transfer Block Size
|
||||
|
||||
@note The DMA channel must be disabled before setting this count value. The count
|
||||
is not changed if the channel is enabled.
|
||||
@note The DMA channel must be disabled before setting this count value. The
|
||||
count is not changed if the channel is enabled.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] channel unsigned int8. Channel number: 1-7 for DMA1 or 1-5 for DMA2
|
||||
@param[in] number unsigned int16. Number of data words to transfer (65535 maximum).
|
||||
@param[in] number unsigned int16. Number of data words to transfer (65535
|
||||
maximum).
|
||||
*/
|
||||
|
||||
void dma_set_number_of_data(u32 dma, u8 channel, u16 number)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** @addtogroup dma_file
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2012 Ken Sarkies <ksarkies@internode.on.net>
|
||||
@author @htmlonly © @endhtmlonly 2012
|
||||
Ken Sarkies <ksarkies@internode.on.net>
|
||||
|
||||
This library supports the DMA Control System in the STM32F2 and STM32F4
|
||||
series of ARM Cortex Microcontrollers by ST Microelectronics.
|
||||
@@ -47,7 +48,7 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
#include <libopencm3/stm32/dma.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Reset
|
||||
|
||||
The specified stream is disabled and configuration registers are cleared.
|
||||
@@ -72,17 +73,14 @@ void dma_stream_reset(u32 dma, u8 stream)
|
||||
DMA_SFCR(dma, stream) = 0x21;
|
||||
/* Reset all stream interrupt flags using the interrupt flag clear register. */
|
||||
u32 mask = DMA_ISR_MASK(stream);
|
||||
if (stream < 4)
|
||||
{
|
||||
if (stream < 4) {
|
||||
DMA_LIFCR(dma) |= mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DMA_HIFCR(dma) |= mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Clear Interrupt Flag
|
||||
|
||||
The interrupt flag for the stream is cleared. More than one interrupt for the
|
||||
@@ -90,25 +88,25 @@ same stream may be cleared by using the bitwise OR of the interrupt flags.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] stream unsigned int8. Stream number: @ref dma_st_number
|
||||
@param[in] interrupts unsigned int32. Bitwise OR of interrupt numbers: @ref dma_if_offset
|
||||
@param[in] interrupts unsigned int32. Bitwise OR of interrupt numbers: @ref
|
||||
dma_if_offset
|
||||
*/
|
||||
|
||||
void dma_clear_interrupt_flags(u32 dma, u8 stream, u32 interrupts)
|
||||
{
|
||||
/* Get offset to interrupt flag location in stream field */
|
||||
/* Get offset to interrupt flag location in stream field */
|
||||
u32 flags = (interrupts << DMA_ISR_OFFSET(stream));
|
||||
/* First four streams are in low register. Flag clear must be set then reset. */
|
||||
if (stream < 4)
|
||||
{
|
||||
/* First four streams are in low register. Flag clear must be set then
|
||||
* reset.
|
||||
*/
|
||||
if (stream < 4) {
|
||||
DMA_LIFCR(dma) = flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DMA_HIFCR(dma) = flags;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Read Interrupt Flag
|
||||
|
||||
The interrupt flag for the stream is returned.
|
||||
@@ -121,15 +119,19 @@ The interrupt flag for the stream is returned.
|
||||
|
||||
bool dma_get_interrupt_flag(u32 dma, u8 stream, u32 interrupt)
|
||||
{
|
||||
/* get offset to interrupt flag location in stream field.
|
||||
Assumes stream and interrupt parameters are integers */
|
||||
/* get offset to interrupt flag location in stream field. Assumes
|
||||
* stream and interrupt parameters are integers.
|
||||
*/
|
||||
u32 flag = (interrupt << DMA_ISR_OFFSET(stream));
|
||||
/* First four streams are in low register */
|
||||
if (stream < 4) return ((DMA_LISR(dma) & flag) > 0);
|
||||
else return ((DMA_HISR(dma) & flag) > 0);
|
||||
/* First four streams are in low register */
|
||||
if (stream < 4) {
|
||||
return ((DMA_LISR(dma) & flag) > 0);
|
||||
} else {
|
||||
return ((DMA_HISR(dma) & flag) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Transfer Direction
|
||||
|
||||
Set peripheral to memory, memory to peripheral or memory to memory. If memory
|
||||
@@ -146,16 +148,18 @@ Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
void dma_set_transfer_mode(u32 dma, u8 stream, u32 direction)
|
||||
{
|
||||
u32 reg32 = (DMA_SCR(dma, stream) & ~DMA_SxCR_DIR_MASK);
|
||||
/* Disable circular and double buffer modes if memory to memory transfers
|
||||
are in effect (Direct Mode is automatically disabled by hardware) */
|
||||
if (direction == DMA_SxCR_DIR_MEM_TO_MEM)
|
||||
{
|
||||
/* Disable circular and double buffer modes if memory to memory
|
||||
* transfers are in effect. (Direct Mode is automatically disabled by
|
||||
* hardware)
|
||||
*/
|
||||
if (direction == DMA_SxCR_DIR_MEM_TO_MEM) {
|
||||
reg32 &= ~(DMA_SxCR_CIRC | DMA_SxCR_DBM);
|
||||
}
|
||||
|
||||
DMA_SCR(dma, stream) = (reg32 | direction);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Priority
|
||||
|
||||
Stream Priority has four levels: low to very high. This has precedence over the
|
||||
@@ -175,7 +179,7 @@ void dma_set_priority(u32 dma, u8 stream, u32 prio)
|
||||
DMA_SCR(dma, stream) |= prio;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Memory Word Width
|
||||
|
||||
Set the memory word width 8 bits, 16 bits, or 32 bits. Refer to datasheet for
|
||||
@@ -190,23 +194,23 @@ Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
|
||||
void dma_set_memory_size(u32 dma, u8 stream, u32 mem_size)
|
||||
{
|
||||
|
||||
DMA_SCR(dma, stream) &= ~(DMA_SxCR_MSIZE_MASK);
|
||||
DMA_SCR(dma, stream) |= mem_size;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Peripheral Word Width
|
||||
|
||||
Set the peripheral word width 8 bits, 16 bits, or 32 bits. Refer to datasheet for
|
||||
alignment information if the source and destination widths do not match, or
|
||||
Set the peripheral word width 8 bits, 16 bits, or 32 bits. Refer to datasheet
|
||||
for alignment information if the source and destination widths do not match, or
|
||||
if the peripheral does not support byte or half-word writes.
|
||||
|
||||
Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] stream unsigned int8. Stream number: @ref dma_st_number
|
||||
@param[in] peripheral_size unsigned int32. Peripheral word width @ref dma_st_perwidth.
|
||||
@param[in] peripheral_size unsigned int32. Peripheral word width @ref
|
||||
dma_st_perwidth.
|
||||
*/
|
||||
|
||||
void dma_set_peripheral_size(u32 dma, u8 stream, u32 peripheral_size)
|
||||
@@ -215,7 +219,7 @@ void dma_set_peripheral_size(u32 dma, u8 stream, u32 peripheral_size)
|
||||
DMA_SCR(dma, stream) |= peripheral_size;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Memory Increment after Transfer
|
||||
|
||||
Following each transfer the current memory address is incremented by
|
||||
@@ -233,7 +237,7 @@ void dma_enable_memory_increment_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_MINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Memory Increment after Transfer
|
||||
|
||||
Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
@@ -247,7 +251,7 @@ void dma_disable_memory_increment_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_MINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Variable Sized Peripheral Increment after Transfer
|
||||
|
||||
Following each transfer the current peripheral address is incremented by
|
||||
@@ -266,7 +270,7 @@ void dma_enable_peripheral_increment_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) = (reg32 & ~DMA_SxCR_PINCOS);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Disable Peripheral Increment after Transfer
|
||||
|
||||
Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
@@ -280,7 +284,7 @@ void dma_disable_peripheral_increment_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_PINC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Channel Enable Fixed Sized Peripheral Increment after Transfer
|
||||
|
||||
Following each transfer the current peripheral address is incremented by
|
||||
@@ -298,7 +302,7 @@ void dma_enable_fixed_peripheral_increment_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= (DMA_SxCR_PINC | DMA_SxCR_PINCOS);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Memory Circular Mode
|
||||
|
||||
After the number of bytes/words to be transferred has been completed, the
|
||||
@@ -320,7 +324,7 @@ void dma_enable_circular_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_CIRC;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Channel Select
|
||||
|
||||
Associate an input channel to the stream. Not every channel is allocated to a
|
||||
@@ -339,7 +343,7 @@ void dma_channel_select(u32 dma, u8 stream, u32 channel)
|
||||
DMA_SCR(dma, stream) |= channel;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Memory Burst Configuration
|
||||
|
||||
Set the memory burst type to none, 4 8 or 16 word length. This is forced to none
|
||||
@@ -358,7 +362,7 @@ void dma_set_memory_burst(u32 dma, u8 stream, u32 burst)
|
||||
DMA_SCR(dma, stream) = (reg32 | burst);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Peripheral Burst Configuration
|
||||
|
||||
Set the memory burst type to none, 4 8 or 16 word length. This is forced to none
|
||||
@@ -377,11 +381,11 @@ void dma_set_peripheral_burst(u32 dma, u8 stream, u32 burst)
|
||||
DMA_SCR(dma, stream) = (reg32 | burst);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Initial Target Memory
|
||||
|
||||
In double buffered mode, set the target memory (M0 or M1) to be used for the first
|
||||
transfer.
|
||||
In double buffered mode, set the target memory (M0 or M1) to be used for the
|
||||
first transfer.
|
||||
|
||||
Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
|
||||
@@ -393,17 +397,20 @@ Ensure that the stream is disabled otherwise the setting will not be changed.
|
||||
void dma_set_initial_target(u32 dma, u8 stream, u8 memory)
|
||||
{
|
||||
u32 reg32 = (DMA_SCR(dma, stream) & ~DMA_SxCR_CT);
|
||||
if (memory == 1) reg32 |= DMA_SxCR_CT;
|
||||
if (memory == 1) {
|
||||
reg32 |= DMA_SxCR_CT;
|
||||
}
|
||||
|
||||
DMA_SCR(dma, stream) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Read Current Memory Target
|
||||
|
||||
In double buffer mode, return the current memory target (M0 or M1). It is possible
|
||||
to update the memory pointer in the register that is <b> not </b> currently in
|
||||
use. An attempt to change the register currently in use will cause the stream
|
||||
to be disabled and the transfer error flag to be set.
|
||||
In double buffer mode, return the current memory target (M0 or M1). It is
|
||||
possible to update the memory pointer in the register that is <b> not </b>
|
||||
currently in use. An attempt to change the register currently in use will cause
|
||||
the stream to be disabled and the transfer error flag to be set.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] stream unsigned int8. Stream number: @ref dma_st_number
|
||||
@@ -412,11 +419,14 @@ to be disabled and the transfer error flag to be set.
|
||||
|
||||
u8 dma_get_target(u32 dma, u8 stream)
|
||||
{
|
||||
if (DMA_SCR(dma, stream) & DMA_SxCR_CT) return 1;
|
||||
if (DMA_SCR(dma, stream) & DMA_SxCR_CT) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Double Buffer Mode
|
||||
|
||||
Double buffer mode is used for memory to/from peripheral transfers only, and in
|
||||
@@ -436,7 +446,7 @@ void dma_enable_double_buffer_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_DBM;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable Double Buffer Mode
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -448,7 +458,7 @@ void dma_disable_double_buffer_mode(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_DBM;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set Peripheral Flow Control
|
||||
|
||||
Set the peripheral to control DMA flow. Useful when the number of transfers is
|
||||
@@ -465,7 +475,7 @@ void dma_set_peripheral_flow_control(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_PFCTRL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set DMA Flow Control
|
||||
|
||||
Set the DMA controller to control DMA flow. This is the default.
|
||||
@@ -481,7 +491,7 @@ void dma_set_dma_flow_control(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_PFCTRL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Interrupt on Transfer Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -494,7 +504,7 @@ void dma_enable_transfer_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_TEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable Interrupt on Transfer Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -506,7 +516,7 @@ void dma_disable_transfer_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_TEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Interrupt on Transfer Half Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -519,7 +529,7 @@ void dma_enable_half_transfer_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_HTIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable Interrupt on Transfer Half Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -531,7 +541,7 @@ void dma_disable_half_transfer_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_HTIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Interrupt on Transfer Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -544,7 +554,7 @@ void dma_enable_transfer_complete_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_TCIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable Interrupt on Transfer Complete
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -556,7 +566,7 @@ void dma_disable_transfer_complete_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_TCIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable Interrupt on Direct Mode Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -569,7 +579,7 @@ void dma_enable_direct_mode_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_DMEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable Interrupt on Direct Mode Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -581,7 +591,7 @@ void dma_disable_direct_mode_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_DMEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Enable Interrupt on FIFO Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -594,7 +604,7 @@ void dma_enable_fifo_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SFCR(dma, stream) |= DMA_SxFCR_FEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Disable Interrupt on FIFO Error
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -606,7 +616,7 @@ void dma_disable_fifo_error_interrupt(u32 dma, u8 stream)
|
||||
DMA_SFCR(dma, stream) &= ~DMA_SxFCR_FEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Get FIFO Status
|
||||
|
||||
Status of FIFO (empty. full or partial filled states) is returned. This has no
|
||||
@@ -619,10 +629,10 @@ meaning if direct mode is enabled (as the FIFO is not used).
|
||||
|
||||
u32 dma_fifo_status(u32 dma, u8 stream)
|
||||
{
|
||||
return (DMA_SFCR(dma, stream) & DMA_SxFCR_FS_MASK);
|
||||
return DMA_SFCR(dma, stream) & DMA_SxFCR_FS_MASK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Enable Direct Mode
|
||||
|
||||
Direct mode is the default. Data is transferred as soon as a DMA request is
|
||||
@@ -638,7 +648,7 @@ void dma_enable_direct_mode(u32 dma, u8 stream)
|
||||
DMA_SFCR(dma, stream) &= ~DMA_SxFCR_DMDIS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Enable FIFO Mode
|
||||
|
||||
Data is transferred via a FIFO.
|
||||
@@ -652,7 +662,7 @@ void dma_enable_fifo_mode(u32 dma, u8 stream)
|
||||
DMA_SFCR(dma, stream) |= DMA_SxFCR_DMDIS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Set FIFO Threshold
|
||||
|
||||
This is the filled level at which data is transferred out of the FIFO to the
|
||||
@@ -669,7 +679,7 @@ void dma_set_fifo_threshold(u32 dma, u8 stream, u32 threshold)
|
||||
DMA_SFCR(dma, stream) = (reg32 | threshold);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Enable
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@@ -681,7 +691,7 @@ void dma_enable_stream(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) |= DMA_SxCR_EN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Disable
|
||||
|
||||
@note The DMA stream registers retain their values when the stream is disabled.
|
||||
@@ -695,11 +705,11 @@ void dma_disable_stream(u32 dma, u8 stream)
|
||||
DMA_SCR(dma, stream) &= ~DMA_SxCR_EN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set the Peripheral Address
|
||||
|
||||
Set the address of the peripheral register to or from which data is to be transferred.
|
||||
Refer to the documentation for the specific peripheral.
|
||||
Set the address of the peripheral register to or from which data is to be
|
||||
transferred. Refer to the documentation for the specific peripheral.
|
||||
|
||||
@note The DMA stream must be disabled before setting this address. This function
|
||||
has no effect if the stream is enabled.
|
||||
@@ -711,11 +721,12 @@ has no effect if the stream is enabled.
|
||||
|
||||
void dma_set_peripheral_address(u32 dma, u8 stream, u32 address)
|
||||
{
|
||||
if (!(DMA_SCR(dma, stream) & DMA_SxCR_EN))
|
||||
if (!(DMA_SCR(dma, stream) & DMA_SxCR_EN)) {
|
||||
DMA_SPAR(dma, stream) = (u32 *) address;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set the Base Memory Address 0
|
||||
|
||||
Set the address pointer to the memory location for DMA transfers. The DMA stream
|
||||
@@ -733,11 +744,13 @@ This is the default base memory address used in direct mode.
|
||||
void dma_set_memory_address(u32 dma, u8 stream, u32 address)
|
||||
{
|
||||
u32 reg32 = DMA_SCR(dma, stream);
|
||||
if ( !(reg32 & DMA_SxCR_EN) || ((reg32 & DMA_SxCR_CT) && (reg32 & DMA_SxCR_DBM)) )
|
||||
if (!(reg32 & DMA_SxCR_EN) ||
|
||||
((reg32 & DMA_SxCR_CT) && (reg32 & DMA_SxCR_DBM))) {
|
||||
DMA_SM0AR(dma, stream) = (u32 *) address;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set the Base Memory Address 1
|
||||
|
||||
Set the address pointer to the memory location for DMA transfers. The DMA stream
|
||||
@@ -753,11 +766,13 @@ to change this in double buffer mode when the current target is memory area 0
|
||||
void dma_set_memory_address_1(u32 dma, u8 stream, u32 address)
|
||||
{
|
||||
u32 reg32 = DMA_SCR(dma, stream);
|
||||
if ( !(reg32 & DMA_SxCR_EN) || (!(reg32 & DMA_SxCR_CT) && (reg32 & DMA_SxCR_DBM)) )
|
||||
if (!(reg32 & DMA_SxCR_EN) ||
|
||||
(!(reg32 & DMA_SxCR_CT) && (reg32 & DMA_SxCR_DBM))) {
|
||||
DMA_SM1AR(dma, stream) = (u32 *) address;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief DMA Stream Set the Transfer Block Size
|
||||
|
||||
@note The DMA stream must be disabled before setting this count value. The count
|
||||
@@ -765,7 +780,8 @@ is not changed if the stream is enabled.
|
||||
|
||||
@param[in] dma unsigned int32. DMA controller base address: DMA1 or DMA2
|
||||
@param[in] stream unsigned int8. Stream number: @ref dma_st_number
|
||||
@param[in] number unsigned int16. Number of data words to transfer (65535 maximum).
|
||||
@param[in] number unsigned int16. Number of data words to transfer (65535
|
||||
maximum).
|
||||
*/
|
||||
|
||||
void dma_set_number_of_data(u32 dma, u8 stream, u16 number)
|
||||
|
||||
@@ -148,8 +148,7 @@ void flash_lock_option_bytes(void)
|
||||
|
||||
void flash_wait_for_last_operation(void)
|
||||
{
|
||||
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY)
|
||||
;
|
||||
while ((FLASH_SR & FLASH_SR_BSY) == FLASH_SR_BSY);
|
||||
}
|
||||
|
||||
void flash_program_double_word(u32 address, u64 data)
|
||||
@@ -218,13 +217,15 @@ void flash_program_byte(u32 address, u8 data)
|
||||
FLASH_CR &= ~FLASH_CR_PG; /* Disable the PG bit. */
|
||||
}
|
||||
|
||||
void flash_program(u32 address, u8* data, u32 len)
|
||||
void flash_program(u32 address, u8 *data, u32 len)
|
||||
{
|
||||
/* TODO: Use dword and word size program operations where possible for turbo
|
||||
* speed. */
|
||||
u32 i;
|
||||
for (i=0; i<len; i++)
|
||||
flash_program_byte(address+i, data[i]);
|
||||
/* TODO: Use dword and word size program operations where possible for
|
||||
* turbo speed.
|
||||
*/
|
||||
u32 i;
|
||||
for (i = 0; i < len; i++) {
|
||||
flash_program_byte(address+i, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void flash_erase_sector(u8 sector, u32 program_size)
|
||||
@@ -258,10 +259,11 @@ void flash_program_option_bytes(u32 data)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
|
||||
if (FLASH_OPTCR & FLASH_OPTCR_OPTLOCK)
|
||||
if (FLASH_OPTCR & FLASH_OPTCR_OPTLOCK) {
|
||||
flash_unlock_option_bytes();
|
||||
}
|
||||
|
||||
FLASH_OPTCR = data & ~0x3;
|
||||
FLASH_OPTCR |= FLASH_OPTCR_OPTSTRT; /* Enable option byte programming. */
|
||||
FLASH_OPTCR |= FLASH_OPTCR_OPTSTRT; /* Enable option byte prog. */
|
||||
flash_wait_for_last_operation();
|
||||
}
|
||||
|
||||
@@ -23,69 +23,73 @@
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define WEAK __attribute__ ((weak))
|
||||
#define WEAK __attribute__((weak))
|
||||
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/**@{*/
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set a Group of Pins Atomic
|
||||
|
||||
Set one or more pins of the given GPIO port to 1 in an atomic operation.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be changed, use logical OR '|' to separate them.
|
||||
If multiple pins are to be changed, use logical OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_set(u32 gpioport, u16 gpios)
|
||||
{
|
||||
GPIO_BSRR(gpioport) = gpios;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Clear a Group of Pins Atomic
|
||||
|
||||
Clear one or more pins of the given GPIO port to 0 in an atomic operation.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be changed, use logical OR '|' to separate them.
|
||||
If multiple pins are to be changed, use logical OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_clear(u32 gpioport, u16 gpios)
|
||||
{
|
||||
GPIO_BSRR(gpioport) = (gpios << 16);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Read a Group of Pins.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be read, use logical OR '|' to separate them.
|
||||
@return Unsigned int16 value of the pin values. The bit position of the pin value
|
||||
returned corresponds to the pin number.
|
||||
If multiple pins are to be read, use logical OR '|' to separate
|
||||
them.
|
||||
@return Unsigned int16 value of the pin values. The bit position of the pin
|
||||
value returned corresponds to the pin number.
|
||||
*/
|
||||
u16 gpio_get(u32 gpioport, u16 gpios)
|
||||
{
|
||||
return gpio_port_read(gpioport) & gpios;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Toggle a Group of Pins
|
||||
|
||||
Toggle one or more pins of the given GPIO port. This is not an atomic operation.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be changed, use logical OR '|' to separate them.
|
||||
If multiple pins are to be changed, use logical OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_toggle(u32 gpioport, u16 gpios)
|
||||
{
|
||||
GPIO_ODR(gpioport) ^= gpios;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Read from a Port
|
||||
|
||||
Read the current value of the given GPIO port. Only the lower 16 bits contain
|
||||
@@ -99,7 +103,7 @@ u16 gpio_port_read(u32 gpioport)
|
||||
return (u16)GPIO_IDR(gpioport);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Write to a Port
|
||||
|
||||
Write a value to the given GPIO port.
|
||||
@@ -112,15 +116,17 @@ void gpio_port_write(u32 gpioport, u16 data)
|
||||
GPIO_ODR(gpioport) = data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Lock the Configuration of a Group of Pins
|
||||
|
||||
The configuration of one or more pins of the given GPIO port is locked. There is
|
||||
no mechanism to unlock these via software. Unlocking occurs at the next reset.
|
||||
The configuration of one or more pins of the given GPIO port is locked. There
|
||||
is no mechanism to unlock these via software. Unlocking occurs at the next
|
||||
reset.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be locked, use logical OR '|' to separate them.
|
||||
If multiple pins are to be locked, use logical OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_port_config_lock(u32 gpioport, u16 gpios)
|
||||
{
|
||||
@@ -133,8 +139,10 @@ void gpio_port_config_lock(u32 gpioport, u16 gpios)
|
||||
reg32 = GPIO_LCKR(gpioport); /* Read LCKK. */
|
||||
reg32 = GPIO_LCKR(gpioport); /* Read LCKK again. */
|
||||
|
||||
/* Tell the compiler the variable is actually used. It will get optimized out anyways. */
|
||||
reg32 = reg32;
|
||||
/* Tell the compiler the variable is actually used. It will get
|
||||
* optimized out anyways.
|
||||
*/
|
||||
reg32 = reg32;
|
||||
|
||||
/* If (reg32 & GPIO_LCKK) is true, the lock is now active. */
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/** @addtogroup gpio_file
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
@author @htmlonly © @endhtmlonly 2012 Ken Sarkies <ksarkies@internode.on.net>
|
||||
@author @htmlonly © @endhtmlonly 2009
|
||||
Uwe Hermann <uwe@hermann-uwe.de>
|
||||
@author @htmlonly © @endhtmlonly 2012
|
||||
Ken Sarkies <ksarkies@internode.on.net>
|
||||
|
||||
Each I/O port has 16 individually configurable bits. Many I/O pins share GPIO
|
||||
functionality with a number of alternate functions and must be configured to the
|
||||
alternate function mode if these are to be accessed. A feature is available to
|
||||
remap alternative functions to a limited set of alternative pins in the event
|
||||
of a clash of requirements.
|
||||
functionality with a number of alternate functions and must be configured to
|
||||
the alternate function mode if these are to be accessed. A feature is available
|
||||
to remap alternative functions to a limited set of alternative pins in the
|
||||
event of a clash of requirements.
|
||||
|
||||
The data registers associated with each port for input and output are 32 bit with
|
||||
the upper 16 bits unused. The output buffer must be written as a 32 bit word, but
|
||||
individual bits may be set or reset separately in atomic operations to avoid race
|
||||
conditions during interrupts. Bits may also be individually locked to prevent
|
||||
accidental configuration changes. Once locked the configuration cannot be changed
|
||||
until after the next reset.
|
||||
The data registers associated with each port for input and output are 32 bit
|
||||
with the upper 16 bits unused. The output buffer must be written as a 32 bit
|
||||
word, but individual bits may be set or reset separately in atomic operations
|
||||
to avoid race conditions during interrupts. Bits may also be individually
|
||||
locked to prevent accidental configuration changes. Once locked the
|
||||
configuration cannot be changed until after the next reset.
|
||||
|
||||
Each port bit can be configured as analog or digital input, the latter can be
|
||||
floating or pulled up or down. As outputs they can be configured as either
|
||||
@@ -29,9 +31,9 @@ Example 1: Push-pull digital output actions with pullup on ports C2 and C9
|
||||
|
||||
@code
|
||||
gpio_mode_setup(GPIOC, GPIO_MODE_OUTPUT,
|
||||
GPIO_PUPD_PULLUP, GPIO2 | GPIO9);
|
||||
GPIO_PUPD_PULLUP, GPIO2 | GPIO9);
|
||||
gpio_output_options(GPIOC, GPIO_OTYPE_PP,
|
||||
GPIO_OSPEED_25MHZ, GPIO2 | GPIO9);
|
||||
GPIO_OSPEED_25MHZ, GPIO2 | GPIO9);
|
||||
gpio_set(GPIOC, GPIO2 | GPIO9);
|
||||
gpio_clear(GPIOC, GPIO2);
|
||||
gpio_toggle(GPIOC, GPIO2 | GPIO9);
|
||||
@@ -42,7 +44,7 @@ Example 2: Digital input on port C12 with pullup
|
||||
|
||||
@code
|
||||
gpio_mode_setup(GPIOC, GPIO_MODE_INPUT,
|
||||
GPIO_PUPD_PULLUP, GPIO12);
|
||||
GPIO_PUPD_PULLUP, GPIO12);
|
||||
reg16 = gpio_port_read(GPIOC);
|
||||
@endcode
|
||||
|
||||
@@ -70,7 +72,7 @@ Example 2: Digital input on port C12 with pullup
|
||||
|
||||
#include <libopencm3/stm32/gpio.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set GPIO Pin Mode
|
||||
|
||||
Sets the Pin Direction and Analog/Digital Mode, and Output Pin Pullup,
|
||||
@@ -78,9 +80,11 @@ for a set of GPIO pins on a given GPIO port.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] mode Unsigned int8. Pin mode @ref gpio_mode
|
||||
@param[in] pull_up_down Unsigned int8. Pin pullup/pulldown configuration @ref gpio_pup
|
||||
@param[in] pull_up_down Unsigned int8. Pin pullup/pulldown configuration @ref
|
||||
gpio_pup
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate them.
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_mode_setup(u32 gpioport, u8 mode, u8 pull_up_down, u16 gpios)
|
||||
{
|
||||
@@ -95,8 +99,9 @@ void gpio_mode_setup(u32 gpioport, u8 mode, u8 pull_up_down, u16 gpios)
|
||||
pupd = GPIO_PUPDR(gpioport);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
moder &= ~GPIO_MODE_MASK(i);
|
||||
moder |= GPIO_MODE(i, mode);
|
||||
@@ -109,33 +114,37 @@ void gpio_mode_setup(u32 gpioport, u8 mode, u8 pull_up_down, u16 gpios)
|
||||
GPIO_PUPDR(gpioport) = pupd;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set GPIO Output Options
|
||||
|
||||
When the pin is set to output mode, this sets the configuration (analog/digital and
|
||||
open drain/push pull) and speed, for a set of GPIO pins on a given GPIO port.
|
||||
When the pin is set to output mode, this sets the configuration (analog/digital
|
||||
and open drain/push pull) and speed, for a set of GPIO pins on a given GPIO
|
||||
port.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] otype Unsigned int8. Pin output type @ref gpio_output_type
|
||||
@param[in] speed Unsigned int8. Pin speed @ref gpio_speed
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate them.
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_set_output_options(u32 gpioport, u8 otype, u8 speed, u16 gpios)
|
||||
{
|
||||
u16 i;
|
||||
u32 ospeedr;
|
||||
|
||||
if (otype == 0x1)
|
||||
if (otype == 0x1) {
|
||||
GPIO_OTYPER(gpioport) |= gpios;
|
||||
}
|
||||
else
|
||||
GPIO_OTYPER(gpioport) &= ~gpios;
|
||||
|
||||
ospeedr = GPIO_OSPEEDR(gpioport);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
ospeedr &= ~GPIO_OSPEED_MASK(i);
|
||||
ospeedr |= GPIO_OSPEED(i, speed);
|
||||
}
|
||||
@@ -143,22 +152,26 @@ void gpio_set_output_options(u32 gpioport, u8 otype, u8 speed, u16 gpios)
|
||||
GPIO_OSPEEDR(gpioport) = ospeedr;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Set GPIO Alternate Function Selection
|
||||
|
||||
Set the alternate function mapping number for each pin. Most pins have alternate
|
||||
functions associated with them. When set to AF mode, a pin may be used for one of
|
||||
its allocated alternate functions selected by the number given here. To determine
|
||||
the number to be used for the desired function refer to the individual datasheet
|
||||
for the particular device. A table is given under the Pin Selection chapter.
|
||||
Set the alternate function mapping number for each pin. Most pins have
|
||||
alternate functions associated with them. When set to AF mode, a pin may be
|
||||
used for one of its allocated alternate functions selected by the number given
|
||||
here. To determine the number to be used for the desired function refer to the
|
||||
individual datasheet for the particular device. A table is given under the Pin
|
||||
Selection chapter.
|
||||
|
||||
Note that a number of pins may be set but only with a single AF number. In practice
|
||||
this would rarely be useful as each pin is likely to require a different number.
|
||||
Note that a number of pins may be set but only with a single AF number. In
|
||||
practice this would rarely be useful as each pin is likely to require a
|
||||
different number.
|
||||
|
||||
@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
|
||||
@param[in] alt_func_num Unsigned int8. Pin alternate function number @ref gpio_af_num
|
||||
@param[in] alt_func_num Unsigned int8. Pin alternate function number @ref
|
||||
gpio_af_num
|
||||
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate them.
|
||||
If multiple pins are to be set, use bitwise OR '|' to separate
|
||||
them.
|
||||
*/
|
||||
void gpio_set_af(u32 gpioport, u8 alt_func_num, u16 gpios)
|
||||
{
|
||||
@@ -169,15 +182,17 @@ void gpio_set_af(u32 gpioport, u8 alt_func_num, u16 gpios)
|
||||
afrh = GPIO_AFRH(gpioport);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
afrl &= ~GPIO_AFR_MASK(i);
|
||||
afrl |= GPIO_AFR(i, alt_func_num);
|
||||
}
|
||||
|
||||
for (i = 8; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
afrh &= ~GPIO_AFR_MASK(i - 8);
|
||||
afrh |= GPIO_AFR(i - 8, alt_func_num);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** @addtogroup hash_file
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2013 Mikhail Avkhimenia <mikhail@avkhimenia.net>
|
||||
@author @htmlonly © @endhtmlonly 2013
|
||||
Mikhail Avkhimenia <mikhail@avkhimenia.net>
|
||||
|
||||
This library supports the HASH processor in the STM32F2 and STM32F4
|
||||
series of ARM Cortex Microcontrollers by ST Microelectronics.
|
||||
@@ -31,7 +32,7 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
#include <libopencm3/stm32/hash.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Set Mode
|
||||
|
||||
Sets up the specified mode - either HASH or HMAC.
|
||||
@@ -45,7 +46,7 @@ void hash_set_mode(u8 mode)
|
||||
HASH_CR |= mode;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Set Algorithm
|
||||
|
||||
Sets up the specified algorithm - either MD5 or SHA1.
|
||||
@@ -59,7 +60,7 @@ void hash_set_algorithm(u8 algorithm)
|
||||
HASH_CR |= algorithm;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Set Data Type
|
||||
|
||||
Sets up the specified data type: 32Bit, 16Bit, 8Bit, Bitstring.
|
||||
@@ -70,10 +71,10 @@ Sets up the specified data type: 32Bit, 16Bit, 8Bit, Bitstring.
|
||||
void hash_set_data_type(u8 datatype)
|
||||
{
|
||||
HASH_CR &= ~HASH_CR_DATATYPE;
|
||||
HASH_CR |= datatype;
|
||||
HASH_CR |= datatype;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Set Key Length
|
||||
|
||||
Sets up the specified key length: Long, Short.
|
||||
@@ -84,10 +85,10 @@ Sets up the specified key length: Long, Short.
|
||||
void hash_set_key_length(u8 keylength)
|
||||
{
|
||||
HASH_CR &= ~HASH_CR_LKEY;
|
||||
HASH_CR |= keylength;
|
||||
HASH_CR |= keylength;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Set Last Word Valid Bits
|
||||
|
||||
Specifies the number of valid bits in the last word.
|
||||
@@ -101,7 +102,7 @@ void hash_set_last_word_valid_bits(u8 validbits)
|
||||
HASH_STR |= 32 - validbits;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Init
|
||||
|
||||
Initializes the HASH processor.
|
||||
@@ -113,7 +114,7 @@ void hash_init()
|
||||
HASH_CR |= HASH_CR_INIT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Add data
|
||||
|
||||
Puts data into the HASH processor's queue.
|
||||
@@ -126,7 +127,7 @@ void hash_add_data(u32 data)
|
||||
HASH_DIN = data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Digest
|
||||
|
||||
Starts the processing of the last data block.
|
||||
@@ -138,7 +139,7 @@ void hash_digest()
|
||||
HASH_STR |= HASH_STR_DCAL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief HASH Get Hash Result
|
||||
|
||||
Makes a copy of the resulting hash.
|
||||
@@ -154,6 +155,7 @@ void hash_get_result(u32 *data)
|
||||
data[2] = HASH_HR[2];
|
||||
data[3] = HASH_HR[3];
|
||||
|
||||
if ((HASH_CR & HASH_CR_ALGO) == HASH_ALGO_SHA1)
|
||||
if ((HASH_CR & HASH_CR_ALGO) == HASH_ALGO_SHA1) {
|
||||
data[4] = HASH_HR[4];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/** @addtogroup i2c_file
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2010 Thomas Otto <tommi@viadmin.org>
|
||||
@author @htmlonly © @endhtmlonly 2012 Ken Sarkies <ksarkies@internode.on.net>
|
||||
@author @htmlonly © @endhtmlonly 2010
|
||||
Thomas Otto <tommi@viadmin.org>
|
||||
@author @htmlonly © @endhtmlonly 2012
|
||||
Ken Sarkies <ksarkies@internode.on.net>
|
||||
|
||||
Devices can have up to two I2C peripherals. The peripherals support SMBus and
|
||||
PMBus variants.
|
||||
@@ -38,11 +40,11 @@ register access, Error conditions
|
||||
|
||||
/**@{*/
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Reset.
|
||||
|
||||
The I2C peripheral and all its associated configuration registers are placed in the
|
||||
reset condition. The reset is effected via the RCC peripheral reset system.
|
||||
The I2C peripheral and all its associated configuration registers are placed in
|
||||
the reset condition. The reset is effected via the RCC peripheral reset system.
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C peripheral identifier @ref i2c_reg_base.
|
||||
*/
|
||||
@@ -61,7 +63,7 @@ void i2c_reset(u32 i2c)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Peripheral Enable.
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -72,7 +74,7 @@ void i2c_peripheral_enable(u32 i2c)
|
||||
I2C_CR1(i2c) |= I2C_CR1_PE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Peripheral Disable.
|
||||
|
||||
This must not be reset while in Master mode until a communication has finished.
|
||||
@@ -86,7 +88,7 @@ void i2c_peripheral_disable(u32 i2c)
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_PE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Send Start Condition.
|
||||
|
||||
If in Master mode this will cause a restart condition to occur at the end of the
|
||||
@@ -101,7 +103,7 @@ void i2c_send_start(u32 i2c)
|
||||
I2C_CR1(i2c) |= I2C_CR1_START;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Send Stop Condition.
|
||||
|
||||
After the current byte transfer this will initiate a stop condition if in Master
|
||||
@@ -115,7 +117,7 @@ void i2c_send_stop(u32 i2c)
|
||||
I2C_CR1(i2c) |= I2C_CR1_STOP;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Clear Stop Flag.
|
||||
|
||||
Clear the "Send Stop" flag in the I2C config register
|
||||
@@ -127,7 +129,7 @@ void i2c_clear_stop(u32 i2c)
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_STOP;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set the 7 bit Slave Address for the Peripheral.
|
||||
|
||||
This sets an address for Slave mode operation, in 7 bit form.
|
||||
@@ -143,7 +145,7 @@ void i2c_set_own_7bit_slave_address(u32 i2c, u8 slave)
|
||||
I2C_OAR1(i2c) |= (1 << 14); /* Datasheet: always keep 1 by software. */
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set the 10 bit Slave Address for the Peripheral.
|
||||
|
||||
This sets an address for Slave mode operation, in 10 bit form.
|
||||
@@ -159,7 +161,7 @@ void i2c_set_own_10bit_slave_address(u32 i2c, u16 slave)
|
||||
I2C_OAR1(i2c) = (u16)(I2C_OAR1_ADDMODE | slave);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set Fast Mode.
|
||||
|
||||
Set the clock frequency to the high clock rate mode (up to 400kHz). The actual
|
||||
@@ -173,11 +175,11 @@ void i2c_set_fast_mode(u32 i2c)
|
||||
I2C_CCR(i2c) |= I2C_CCR_FS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set Standard Mode.
|
||||
|
||||
Set the clock frequency to the standard clock rate mode (up to 100kHz). The actual
|
||||
clock frequency must be set with @ref i2c_set_clock_frequency
|
||||
Set the clock frequency to the standard clock rate mode (up to 100kHz). The
|
||||
actual clock frequency must be set with @ref i2c_set_clock_frequency
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
*/
|
||||
@@ -187,12 +189,13 @@ void i2c_set_standard_mode(u32 i2c)
|
||||
I2C_CCR(i2c) &= ~I2C_CCR_FS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set Peripheral Clock Frequency.
|
||||
|
||||
Set the peripheral clock frequency: 2MHz to 36MHz (the APB frequency). Note that
|
||||
this is <b> not </b> the I2C bus clock. This is set in conjunction with the Clock
|
||||
Control register to generate the Master bus clock, see @ref i2c_set_ccr
|
||||
Set the peripheral clock frequency: 2MHz to 36MHz (the APB frequency). Note
|
||||
that this is <b> not </b> the I2C bus clock. This is set in conjunction with
|
||||
the Clock Control register to generate the Master bus clock, see @ref
|
||||
i2c_set_ccr
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@param[in] freq Unsigned int8. Clock Frequency Setting @ref i2c_clock.
|
||||
@@ -206,7 +209,7 @@ void i2c_set_clock_frequency(u32 i2c, u8 freq)
|
||||
I2C_CR2(i2c) = reg16;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set Bus Clock Frequency.
|
||||
|
||||
Set the bus clock frequency. This is a 12 bit number (0...4095) calculated
|
||||
@@ -229,7 +232,7 @@ void i2c_set_ccr(u32 i2c, u16 freq)
|
||||
I2C_CCR(i2c) = reg16;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set the Rise Time.
|
||||
|
||||
Set the maximum rise time on the bus according to the I2C specification, as 1
|
||||
@@ -247,12 +250,13 @@ void i2c_set_trise(u32 i2c, u16 trise)
|
||||
I2C_TRISE(i2c) = trise;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Send the 7-bit Slave Address.
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@param[in] slave Unsigned int16. Slave address 0...1023.
|
||||
@param[in] readwrite Unsigned int8. Single bit to instruct slave to receive or send @ref i2c_rw.
|
||||
@param[in] readwrite Unsigned int8. Single bit to instruct slave to receive or
|
||||
send @ref i2c_rw.
|
||||
*/
|
||||
|
||||
void i2c_send_7bit_address(u32 i2c, u8 slave, u8 readwrite)
|
||||
@@ -260,7 +264,7 @@ void i2c_send_7bit_address(u32 i2c, u8 slave, u8 readwrite)
|
||||
I2C_DR(i2c) = (u8)((slave << 1) | readwrite);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Send Data.
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -272,7 +276,7 @@ void i2c_send_data(u32 i2c, u8 data)
|
||||
I2C_DR(i2c) = data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Get Data.
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -282,7 +286,7 @@ uint8_t i2c_get_data(u32 i2c)
|
||||
return I2C_DR(i2c) & 0xff;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Enable Interrupt
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -293,7 +297,7 @@ void i2c_enable_interrupt(u32 i2c, u32 interrupt)
|
||||
I2C_CR2(i2c) |= interrupt;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Disable Interrupt
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -304,7 +308,7 @@ void i2c_disable_interrupt(u32 i2c, u32 interrupt)
|
||||
I2C_CR2(i2c) &= ~interrupt;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Enable ACK
|
||||
|
||||
Enables acking of own 7/10 bit address
|
||||
@@ -315,7 +319,7 @@ void i2c_enable_ack(u32 i2c)
|
||||
I2C_CR1(i2c) |= I2C_CR1_ACK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Disable ACK
|
||||
|
||||
Disables acking of own 7/10 bit address
|
||||
@@ -326,7 +330,7 @@ void i2c_disable_ack(u32 i2c)
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_ACK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C NACK Next Byte
|
||||
|
||||
Causes the I2C controller to NACK the reception of the next byte
|
||||
@@ -337,7 +341,7 @@ void i2c_nack_next(u32 i2c)
|
||||
I2C_CR1(i2c) |= I2C_CR1_POS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C NACK Next Byte
|
||||
|
||||
Causes the I2C controller to NACK the reception of the current byte
|
||||
@@ -349,7 +353,7 @@ void i2c_nack_current(u32 i2c)
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_POS;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set clock duty cycle
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -357,13 +361,14 @@ void i2c_nack_current(u32 i2c)
|
||||
*/
|
||||
void i2c_set_dutycycle(u32 i2c, u32 dutycycle)
|
||||
{
|
||||
if (dutycycle == I2C_CCR_DUTY_DIV2)
|
||||
if (dutycycle == I2C_CCR_DUTY_DIV2) {
|
||||
I2C_CCR(i2c) &= ~I2C_CCR_DUTY;
|
||||
else
|
||||
} else {
|
||||
I2C_CCR(i2c) |= I2C_CCR_DUTY;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Enable DMA
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -373,7 +378,7 @@ void i2c_enable_dma(u32 i2c)
|
||||
I2C_CR2(i2c) |= I2C_CR2_DMAEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Disable DMA
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -383,7 +388,7 @@ void i2c_disable_dma(u32 i2c)
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_DMAEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Set DMA last transfer
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
@@ -393,7 +398,7 @@ void i2c_set_dma_last_transfer(u32 i2c)
|
||||
I2C_CR2(i2c) |= I2C_CR2_LAST;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief I2C Clear DMA last transfer
|
||||
|
||||
@param[in] i2c Unsigned int32. I2C register base address @ref i2c_reg_base.
|
||||
|
||||
@@ -42,7 +42,7 @@ relevant bit is not set, the IWDG timer must be enabled by software.
|
||||
#define COUNT_LENGTH 12
|
||||
#define COUNT_MASK ((1 << COUNT_LENGTH)-1)
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief IWDG Enable Watchdog Timer
|
||||
|
||||
The watchdog timer is started. The timeout period defaults to 512 milliseconds
|
||||
@@ -55,7 +55,7 @@ void iwdg_start(void)
|
||||
IWDG_KR = IWDG_KR_START;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief IWDG Set Period in Milliseconds
|
||||
|
||||
The countdown period is converted into count and prescale values. The maximum
|
||||
@@ -66,27 +66,41 @@ A delay of up to 5 clock cycles of the LSI clock (about 156 microseconds)
|
||||
can occasionally occur if the prescale or preload registers are currently busy
|
||||
loading a previous value.
|
||||
|
||||
@param[in] period u32 Period in milliseconds (< 32760) from a watchdog reset until
|
||||
a system reset is issued.
|
||||
@param[in] period u32 Period in milliseconds (< 32760) from a watchdog reset
|
||||
until a system reset is issued.
|
||||
*/
|
||||
|
||||
void iwdg_set_period_ms(u32 period)
|
||||
{
|
||||
u32 count, prescale, reload, exponent;
|
||||
/* Set the count to represent ticks of the 32kHz LSI clock */
|
||||
u32 count, prescale, reload, exponent;
|
||||
|
||||
/* Set the count to represent ticks of the 32kHz LSI clock */
|
||||
count = (period << 5);
|
||||
/* Strip off the first 12 bits to get the prescale value required */
|
||||
|
||||
/* Strip off the first 12 bits to get the prescale value required */
|
||||
prescale = (count >> 12);
|
||||
if (prescale > 256) {exponent = IWDG_PR_DIV256; reload = COUNT_MASK;}
|
||||
else if (prescale > 128) {exponent = IWDG_PR_DIV256; reload = (count >> 8);}
|
||||
else if (prescale > 64) {exponent = IWDG_PR_DIV128; reload = (count >> 7);}
|
||||
else if (prescale > 32) {exponent = IWDG_PR_DIV64; reload = (count >> 6);}
|
||||
else if (prescale > 16) {exponent = IWDG_PR_DIV32; reload = (count >> 5);}
|
||||
else if (prescale > 8) {exponent = IWDG_PR_DIV16; reload = (count >> 4);}
|
||||
else if (prescale > 4) {exponent = IWDG_PR_DIV8; reload = (count >> 3);}
|
||||
else {exponent = IWDG_PR_DIV4; reload = (count >> 2);}
|
||||
/* Avoid the undefined situation of a zero count */
|
||||
if (count == 0) count = 1;
|
||||
if (prescale > 256) {
|
||||
exponent = IWDG_PR_DIV256; reload = COUNT_MASK;
|
||||
} else if (prescale > 128) {
|
||||
exponent = IWDG_PR_DIV256; reload = (count >> 8);
|
||||
} else if (prescale > 64) {
|
||||
exponent = IWDG_PR_DIV128; reload = (count >> 7);
|
||||
} else if (prescale > 32) {
|
||||
exponent = IWDG_PR_DIV64; reload = (count >> 6);
|
||||
} else if (prescale > 16) {
|
||||
exponent = IWDG_PR_DIV32; reload = (count >> 5);
|
||||
} else if (prescale > 8) {
|
||||
exponent = IWDG_PR_DIV16; reload = (count >> 4);
|
||||
} else if (prescale > 4) {
|
||||
exponent = IWDG_PR_DIV8; reload = (count >> 3);
|
||||
} else {
|
||||
exponent = IWDG_PR_DIV4; reload = (count >> 2);
|
||||
}
|
||||
|
||||
/* Avoid the undefined situation of a zero count */
|
||||
if (count == 0) {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
while (iwdg_prescaler_busy());
|
||||
IWDG_KR = IWDG_KR_UNLOCK;
|
||||
@@ -96,31 +110,31 @@ u32 count, prescale, reload, exponent;
|
||||
IWDG_RLR = (reload & COUNT_MASK);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief IWDG Get Reload Register Status
|
||||
|
||||
@returns boolean: TRUE if the reload register is busy and unavailable for loading
|
||||
a new count value.
|
||||
@returns boolean: TRUE if the reload register is busy and unavailable for
|
||||
loading a new count value.
|
||||
*/
|
||||
|
||||
bool iwdg_reload_busy(void)
|
||||
{
|
||||
return (IWDG_SR & IWDG_SR_RVU);
|
||||
return IWDG_SR & IWDG_SR_RVU;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief IWDG Get Prescaler Register Status
|
||||
|
||||
@returns boolean: TRUE if the prescaler register is busy and unavailable for loading
|
||||
a new period value.
|
||||
@returns boolean: TRUE if the prescaler register is busy and unavailable for
|
||||
loading a new period value.
|
||||
*/
|
||||
|
||||
bool iwdg_prescaler_busy(void)
|
||||
{
|
||||
return (IWDG_SR & IWDG_SR_PVU);
|
||||
return IWDG_SR & IWDG_SR_PVU;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief IWDG reset Watchdog Timer
|
||||
|
||||
The watchdog timer is reset. The counter restarts from the value in the reload
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** @addtogroup pwr-file PWR
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2012 Ken Sarkies <ksarkies@internode.on.net>
|
||||
@author @htmlonly © @endhtmlonly 2012
|
||||
Ken Sarkies <ksarkies@internode.on.net>
|
||||
|
||||
*/
|
||||
/*
|
||||
@@ -199,7 +200,7 @@ cleared by software (see @ref pwr_clear_wakeup_flag).
|
||||
|
||||
bool pwr_get_wakeup_flag(void)
|
||||
{
|
||||
return (PWR_CSR & PWR_CSR_WUF);
|
||||
return PWR_CSR & PWR_CSR_WUF;
|
||||
}
|
||||
/**@}*/
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
This sets the RTC synchronous and asynchronous prescalars.
|
||||
*/
|
||||
|
||||
void rtc_set_prescaler(u32 sync, u32 async) {
|
||||
void rtc_set_prescaler(u32 sync, u32 async)
|
||||
{
|
||||
/*
|
||||
* Even if only one of the two fields needs to be changed,
|
||||
* 2 separate write accesses must be performed to the RTC_PRER register.
|
||||
@@ -48,16 +49,16 @@ void rtc_set_prescaler(u32 sync, u32 async) {
|
||||
Time and Date are accessed through shadow registers which must be synchronized
|
||||
*/
|
||||
|
||||
void rtc_wait_for_synchro(void) {
|
||||
void rtc_wait_for_synchro(void)
|
||||
{
|
||||
/* Unlock RTC registers */
|
||||
RTC_WPR = 0xca;
|
||||
RTC_WPR = 0x53;
|
||||
|
||||
RTC_ISR &= ~(RTC_ISR_RSF);
|
||||
|
||||
while (!(RTC_ISR & RTC_ISR_RSF)) {
|
||||
;
|
||||
}
|
||||
while (!(RTC_ISR & RTC_ISR_RSF));
|
||||
|
||||
/* disable write protection again */
|
||||
RTC_WPR = 0xff;
|
||||
}
|
||||
@@ -66,7 +67,8 @@ void rtc_wait_for_synchro(void) {
|
||||
/** @brief Unlock write access to the RTC registers
|
||||
|
||||
*/
|
||||
void rtc_unlock(void) {
|
||||
void rtc_unlock(void)
|
||||
{
|
||||
RTC_WPR = 0xca;
|
||||
RTC_WPR = 0x53;
|
||||
}
|
||||
@@ -75,7 +77,8 @@ void rtc_unlock(void) {
|
||||
/** @brief Lock write access to the RTC registers
|
||||
|
||||
*/
|
||||
void rtc_lock(void) {
|
||||
void rtc_lock(void)
|
||||
{
|
||||
RTC_WPR = 0xff;
|
||||
}
|
||||
|
||||
@@ -83,31 +86,38 @@ void rtc_lock(void) {
|
||||
/** @brief Sets the wakeup time auto-reload value
|
||||
|
||||
*/
|
||||
void rtc_set_wakeup_time(u16 wkup_time, u8 rtc_cr_wucksel) {
|
||||
// FTFM:
|
||||
// The following sequence is required to configure or change the wakeup timer
|
||||
// auto-reload value (WUT[15:0] in RTC_WUTR):
|
||||
// 1. Clear WUTE in RTC_CR to disable the wakeup timer.
|
||||
RTC_CR &= ~RTC_CR_WUTE;
|
||||
// 2. Poll WUTWF until it is set in RTC_ISR to make sure the access to wakeup
|
||||
// auto-reload counter and to WUCKSEL[2:0] bits is allowed. It takes around 2
|
||||
// RTCCLK clock cycles (due to clock synchronization).
|
||||
while (!((RTC_ISR) & (RTC_ISR_WUTWF))) { }
|
||||
// 3. Program the wakeup auto-reload value WUT[15:0], and the wakeup clock
|
||||
// selection (WUCKSEL[2:0] bits in RTC_CR).Set WUTE in RTC_CR to enable the
|
||||
// timer again. The wakeup timer restarts down-counting.
|
||||
RTC_WUTR = wkup_time;
|
||||
RTC_CR |= (rtc_cr_wucksel << RTC_CR_WUCLKSEL_SHIFT);
|
||||
RTC_CR |= RTC_CR_WUTE;
|
||||
void rtc_set_wakeup_time(u16 wkup_time, u8 rtc_cr_wucksel)
|
||||
{
|
||||
/* FTFM:
|
||||
* The following sequence is required to configure or change the wakeup
|
||||
* timer auto-reload value (WUT[15:0] in RTC_WUTR):
|
||||
* 1. Clear WUTE in RTC_CR to disable the wakeup timer.
|
||||
*/
|
||||
RTC_CR &= ~RTC_CR_WUTE;
|
||||
/* 2. Poll WUTWF until it is set in RTC_ISR to make sure the access to
|
||||
* wakeup auto-reload counter and to WUCKSEL[2:0] bits is allowed.
|
||||
* It takes around 2 RTCCLK clock cycles (due to clock
|
||||
* synchronization).
|
||||
*/
|
||||
while (!((RTC_ISR) & (RTC_ISR_WUTWF)));
|
||||
/* 3. Program the wakeup auto-reload value WUT[15:0], and the wakeup
|
||||
* clock selection (WUCKSEL[2:0] bits in RTC_CR).Set WUTE in RTC_CR
|
||||
* to enable the timer again. The wakeup timer restarts
|
||||
* down-counting.
|
||||
*/
|
||||
RTC_WUTR = wkup_time;
|
||||
RTC_CR |= (rtc_cr_wucksel << RTC_CR_WUCLKSEL_SHIFT);
|
||||
RTC_CR |= RTC_CR_WUTE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Clears the wakeup flag
|
||||
|
||||
@details This function should be called first in the rtc_wkup_isr()
|
||||
@details This function should be called first in the rtc_wkup_isr()
|
||||
*/
|
||||
void rtc_clear_wakeup_flag(void) {
|
||||
RTC_ISR &= ~RTC_ISR_WUTF;
|
||||
void rtc_clear_wakeup_flag(void)
|
||||
{
|
||||
RTC_ISR &= ~RTC_ISR_WUTF;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/** @addtogroup spi_file
|
||||
|
||||
@author @htmlonly © @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
|
||||
@author @htmlonly © @endhtmlonly 2012 Ken Sarkies <ksarkies@internode.on.net>
|
||||
@author @htmlonly © @endhtmlonly 2009
|
||||
Uwe Hermann <uwe@hermann-uwe.de>
|
||||
@author @htmlonly © @endhtmlonly 2012
|
||||
Ken Sarkies <ksarkies@internode.on.net>
|
||||
|
||||
Devices can have up to three SPI peripherals. The common 4-wire full-duplex
|
||||
mode of operation is supported, along with 3-wire variants using unidirectional
|
||||
@@ -18,8 +20,8 @@ Example: 1Mbps, positive clock polarity, leading edge trigger, 8-bit words,
|
||||
LSB first.
|
||||
@code
|
||||
spi_init_master(SPI1, 1000000, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE,
|
||||
SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_8BIT,
|
||||
SPI_CR1_LSBFIRST);
|
||||
SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_8BIT,
|
||||
SPI_CR1_LSBFIRST);
|
||||
spi_write(SPI1, 0x55); // 8-bit write
|
||||
spi_write(SPI1, 0xaa88); // 16-bit write
|
||||
reg8 = spi_read(SPI1); // 8-bit read
|
||||
@@ -67,13 +69,14 @@ LSB first.
|
||||
|
||||
/**@{*/
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Reset.
|
||||
|
||||
The SPI peripheral and all its associated configuration registers are placed in the
|
||||
reset condition. The reset is effected via the RCC peripheral reset system.
|
||||
The SPI peripheral and all its associated configuration registers are placed in
|
||||
the reset condition. The reset is effected via the RCC peripheral reset system.
|
||||
|
||||
@param[in] spi_peripheral Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@param[in] spi_peripheral Unsigned int32. SPI peripheral identifier @ref
|
||||
spi_reg_base.
|
||||
*/
|
||||
|
||||
void spi_reset(u32 spi_peripheral)
|
||||
@@ -96,7 +99,7 @@ void spi_reset(u32 spi_peripheral)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Configure the SPI as Master.
|
||||
|
||||
The SPI peripheral is configured as a master with communication parameters
|
||||
@@ -111,7 +114,8 @@ These must be controlled separately.
|
||||
@param[in] cpol Unsigned int32. Clock polarity @ref spi_cpol.
|
||||
@param[in] cpha Unsigned int32. Clock Phase @ref spi_cpha.
|
||||
@param[in] dff Unsigned int32. Data frame format 8/16 bits @ref spi_dff.
|
||||
@param[in] lsbfirst Unsigned int32. Frame format lsb/msb first @ref spi_lsbfirst.
|
||||
@param[in] lsbfirst Unsigned int32. Frame format lsb/msb first @ref
|
||||
spi_lsbfirst.
|
||||
@returns int. Error code.
|
||||
*/
|
||||
|
||||
@@ -138,7 +142,7 @@ int spi_init_master(u32 spi, u32 br, u32 cpol, u32 cpha, u32 dff, u32 lsbfirst)
|
||||
}
|
||||
|
||||
/* TODO: Error handling? */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable.
|
||||
|
||||
The SPI peripheral is enabled.
|
||||
@@ -154,7 +158,7 @@ void spi_enable(u32 spi)
|
||||
}
|
||||
|
||||
/* TODO: Error handling? */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable.
|
||||
|
||||
The SPI peripheral is disabled.
|
||||
@@ -171,7 +175,7 @@ void spi_disable(u32 spi)
|
||||
SPI_CR1(spi) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Clean Disable.
|
||||
|
||||
Disable the SPI peripheral according to the procedure in section 23.3.8 of the
|
||||
@@ -185,25 +189,22 @@ prevents the BSY flag from becoming unreliable.
|
||||
u16 spi_clean_disable(u32 spi)
|
||||
{
|
||||
/* Wait to receive last data */
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE))
|
||||
;
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE));
|
||||
|
||||
u16 data = SPI_DR(spi);
|
||||
|
||||
/* Wait to transmit last data */
|
||||
while (!(SPI_SR(spi) & SPI_SR_TXE))
|
||||
;
|
||||
while (!(SPI_SR(spi) & SPI_SR_TXE));
|
||||
|
||||
/* Wait until not busy */
|
||||
while (SPI_SR(spi) & SPI_SR_BSY)
|
||||
;
|
||||
while (SPI_SR(spi) & SPI_SR_BSY);
|
||||
|
||||
SPI_CR1(spi) &= ~SPI_CR1_SPE;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Data Write.
|
||||
|
||||
Data is written to the SPI interface.
|
||||
@@ -218,10 +219,11 @@ void spi_write(u32 spi, u16 data)
|
||||
SPI_DR(spi) = data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Data Write with Blocking.
|
||||
|
||||
Data is written to the SPI interface after the previous write transfer has finished.
|
||||
Data is written to the SPI interface after the previous write transfer has
|
||||
finished.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@param[in] data Unsigned int16. 8 or 16 bit data to be written.
|
||||
@@ -230,14 +232,13 @@ Data is written to the SPI interface after the previous write transfer has finis
|
||||
void spi_send(u32 spi, u16 data)
|
||||
{
|
||||
/* Wait for transfer finished. */
|
||||
while (!(SPI_SR(spi) & SPI_SR_TXE))
|
||||
;
|
||||
while (!(SPI_SR(spi) & SPI_SR_TXE));
|
||||
|
||||
/* Write data (8 or 16 bits, depending on DFF) into DR. */
|
||||
SPI_DR(spi) = data;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Data Read.
|
||||
|
||||
Data is read from the SPI interface after the incoming transfer has finished.
|
||||
@@ -249,18 +250,17 @@ Data is read from the SPI interface after the incoming transfer has finished.
|
||||
u16 spi_read(u32 spi)
|
||||
{
|
||||
/* Wait for transfer finished. */
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE))
|
||||
;
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE));
|
||||
|
||||
/* Read the data (8 or 16 bits, depending on DFF bit) from DR. */
|
||||
return SPI_DR(spi);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Data Write and Read Exchange.
|
||||
|
||||
Data is written to the SPI interface, then a read is done after the incoming transfer
|
||||
has finished.
|
||||
Data is written to the SPI interface, then a read is done after the incoming
|
||||
transfer has finished.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@param[in] data Unsigned int16. 8 or 16 bit data to be written.
|
||||
@@ -272,14 +272,13 @@ u16 spi_xfer(u32 spi, u16 data)
|
||||
spi_write(spi, data);
|
||||
|
||||
/* Wait for transfer finished. */
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE))
|
||||
;
|
||||
while (!(SPI_SR(spi) & SPI_SR_RXNE));
|
||||
|
||||
/* Read the data (8 or 16 bits, depending on DFF bit) from DR. */
|
||||
return SPI_DR(spi);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Bidirectional Simplex Mode.
|
||||
|
||||
The SPI peripheral is set for bidirectional transfers in two-wire simplex mode
|
||||
@@ -293,12 +292,12 @@ void spi_set_bidirectional_mode(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_BIDIMODE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Unidirectional Mode.
|
||||
|
||||
The SPI peripheral is set for unidirectional transfers. This is used in full duplex
|
||||
mode or when the SPI is placed in two-wire simplex mode that uses a clock wire and a
|
||||
unidirectional data wire.
|
||||
The SPI peripheral is set for unidirectional transfers. This is used in full
|
||||
duplex mode or when the SPI is placed in two-wire simplex mode that uses a
|
||||
clock wire and a unidirectional data wire.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -308,11 +307,12 @@ void spi_set_unidirectional_mode(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_BIDIMODE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Bidirectional Simplex Receive Only Mode.
|
||||
|
||||
The SPI peripheral is set for bidirectional transfers in two-wire simplex mode
|
||||
(using a clock wire and a bidirectional data wire), and is placed in a receive state.
|
||||
(using a clock wire and a bidirectional data wire), and is placed in a receive
|
||||
state.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -323,11 +323,12 @@ void spi_set_bidirectional_receive_only_mode(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_BIDIOE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Bidirectional Simplex Receive Only Mode.
|
||||
|
||||
The SPI peripheral is set for bidirectional transfers in two-wire simplex mode
|
||||
(using a clock wire and a bidirectional data wire), and is placed in a transmit state.
|
||||
(using a clock wire and a bidirectional data wire), and is placed in a transmit
|
||||
state.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -338,7 +339,7 @@ void spi_set_bidirectional_transmit_only_mode(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_BIDIOE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable the CRC.
|
||||
|
||||
The SPI peripheral is set to use a CRC field for transmit and receive.
|
||||
@@ -351,7 +352,7 @@ void spi_enable_crc(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_CRCEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable the CRC.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -362,7 +363,7 @@ void spi_disable_crc(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_CRCEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Next Transmit is a Data Word
|
||||
|
||||
The next transmission to take place is a data word from the transmit buffer.
|
||||
@@ -377,7 +378,7 @@ void spi_set_next_tx_from_buffer(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_CRCNEXT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Next Transmit is a CRC Word
|
||||
|
||||
The next transmission to take place is a crc word from the hardware crc unit.
|
||||
@@ -392,7 +393,7 @@ void spi_set_next_tx_from_crc(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_CRCNEXT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Data Frame Format to 8 bits
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -403,7 +404,7 @@ void spi_set_dff_8bit(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_DFF;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Data Frame Format to 16 bits
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -414,7 +415,7 @@ void spi_set_dff_16bit(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_DFF;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Full Duplex (3-wire) Mode
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -425,8 +426,9 @@ void spi_set_full_duplex_mode(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_RXONLY;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Receive Only Mode for Simplex (2-wire) Unidirectional Transfers
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set Receive Only Mode for Simplex (2-wire) Unidirectional
|
||||
Transfers
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -436,7 +438,7 @@ void spi_set_receive_only_mode(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_RXONLY;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable Slave Management by Hardware
|
||||
|
||||
In slave mode the NSS hardware input is used as a select enable for the slave.
|
||||
@@ -449,7 +451,7 @@ void spi_disable_software_slave_management(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_SSM;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable Slave Management by Software
|
||||
|
||||
In slave mode the NSS hardware input is replaced by an internal software
|
||||
@@ -463,13 +465,14 @@ void spi_enable_software_slave_management(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_SSM;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Software NSS Signal High
|
||||
|
||||
In slave mode, and only when software slave management is used, this replaces
|
||||
the NSS signal with a slave select enable signal.
|
||||
|
||||
@todo these should perhaps be combined with an SSM enable as it is meaningless otherwise
|
||||
@todo these should perhaps be combined with an SSM enable as it is meaningless
|
||||
otherwise
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -479,7 +482,7 @@ void spi_set_nss_high(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_SSI;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Software NSS Signal Low
|
||||
|
||||
In slave mode, and only when software slave management is used, this replaces
|
||||
@@ -493,7 +496,7 @@ void spi_set_nss_low(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_SSI;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set to Send LSB First
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -504,7 +507,7 @@ void spi_send_lsb_first(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_LSBFIRST;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set to Send MSB First
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -515,10 +518,11 @@ void spi_send_msb_first(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_LSBFIRST;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Baudrate Prescaler
|
||||
|
||||
@todo Why is this specification different to the spi_init_master baudrate values?
|
||||
@todo Why is this specification different to the spi_init_master baudrate
|
||||
values?
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@param[in] baudrate Unsigned int8. Baudrate prescale value @ref spi_br_pre.
|
||||
@@ -528,15 +532,16 @@ void spi_set_baudrate_prescaler(u32 spi, u8 baudrate)
|
||||
{
|
||||
u32 reg32;
|
||||
|
||||
if (baudrate > 7)
|
||||
if (baudrate > 7) {
|
||||
return;
|
||||
}
|
||||
|
||||
reg32 = (SPI_CR1(spi) & 0xffc7); /* Clear bits [5:3]. */
|
||||
reg32 |= (baudrate << 3);
|
||||
SPI_CR1(spi) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set to Master Mode
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -547,7 +552,7 @@ void spi_set_master_mode(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_MSTR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set to Slave Mode
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -558,7 +563,7 @@ void spi_set_slave_mode(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_MSTR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Clock Polarity to High when Idle
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -569,7 +574,7 @@ void spi_set_clock_polarity_1(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_CPOL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Clock Polarity to Low when Idle
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -580,7 +585,7 @@ void spi_set_clock_polarity_0(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_CPOL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Clock Phase to Capture on Trailing Edge
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -591,7 +596,7 @@ void spi_set_clock_phase_1(u32 spi)
|
||||
SPI_CR1(spi) |= SPI_CR1_CPHA;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the Clock Phase to Capture on Leading Edge
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -602,7 +607,7 @@ void spi_set_clock_phase_0(u32 spi)
|
||||
SPI_CR1(spi) &= ~SPI_CR1_CPHA;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable the Transmit Buffer Empty Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -613,7 +618,7 @@ void spi_enable_tx_buffer_empty_interrupt(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_TXEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable the Transmit Buffer Empty Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -624,7 +629,7 @@ void spi_disable_tx_buffer_empty_interrupt(u32 spi)
|
||||
SPI_CR2(spi) &= ~SPI_CR2_TXEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable the Receive Buffer Ready Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -635,7 +640,7 @@ void spi_enable_rx_buffer_not_empty_interrupt(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_RXNEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable the Receive Buffer Ready Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -646,7 +651,7 @@ void spi_disable_rx_buffer_not_empty_interrupt(u32 spi)
|
||||
SPI_CR2(spi) &= ~SPI_CR2_RXNEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable the Error Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -657,7 +662,7 @@ void spi_enable_error_interrupt(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_ERRIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable the Error Interrupt
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -668,7 +673,7 @@ void spi_disable_error_interrupt(u32 spi)
|
||||
SPI_CR2(spi) &= ~SPI_CR2_ERRIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the NSS Pin as an Output
|
||||
|
||||
Normally used in master mode to allows the master to place all devices on the
|
||||
@@ -682,7 +687,7 @@ void spi_enable_ss_output(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_SSOE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Set the NSS Pin as an Input
|
||||
|
||||
In master mode this allows the master to sense the presence of other masters. If
|
||||
@@ -697,7 +702,7 @@ void spi_disable_ss_output(u32 spi)
|
||||
SPI_CR2(spi) &= ~SPI_CR2_SSOE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable Transmit Transfers via DMA
|
||||
|
||||
This allows transmissions to proceed unattended using DMA to move data to the
|
||||
@@ -712,7 +717,7 @@ void spi_enable_tx_dma(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_TXDMAEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable Transmit Transfers via DMA
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
@@ -723,12 +728,12 @@ void spi_disable_tx_dma(u32 spi)
|
||||
SPI_CR2(spi) &= ~SPI_CR2_TXDMAEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Enable Receive Transfers via DMA
|
||||
|
||||
This allows received data streams to proceed unattended using DMA to move data from
|
||||
the receive buffer as data becomes available. The DMA channels provided for each
|
||||
SPI peripheral are given in the Technical Manual DMA section.
|
||||
This allows received data streams to proceed unattended using DMA to move data
|
||||
from the receive buffer as data becomes available. The DMA channels provided
|
||||
for each SPI peripheral are given in the Technical Manual DMA section.
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
*/
|
||||
@@ -738,7 +743,7 @@ void spi_enable_rx_dma(u32 spi)
|
||||
SPI_CR2(spi) |= SPI_CR2_RXDMAEN;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief SPI Disable Receive Transfers via DMA
|
||||
|
||||
@param[in] spi Unsigned int32. SPI peripheral identifier @ref spi_reg_base.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -33,7 +33,8 @@ Set timer options register on TIM2 or TIM5, used for trigger remapping on TIM2,
|
||||
and similarly for TIM5 for oscillator calibration purposes.
|
||||
|
||||
@param[in] timer_peripheral Unsigned int32. Timer register address base
|
||||
@returns Unsigned int32. Option flags TIM2: @ref tim2_opt_trigger_remap, TIM5: @ref tim5_opt_trigger_remap.
|
||||
@returns Unsigned int32. Option flags TIM2: @ref tim2_opt_trigger_remap, TIM5:
|
||||
@ref tim5_opt_trigger_remap.
|
||||
*/
|
||||
|
||||
void timer_set_option(u32 timer_peripheral, u32 option)
|
||||
@@ -57,20 +58,22 @@ The timer channel must be set to input capture mode.
|
||||
@param[in] pol ::tim_ic_pol. Input Capture polarity control.
|
||||
*/
|
||||
|
||||
void timer_ic_set_polarity(u32 timer_peripheral, enum tim_ic_id ic, enum tim_ic_pol pol)
|
||||
void timer_ic_set_polarity(u32 timer_peripheral, enum tim_ic_id ic,
|
||||
enum tim_ic_pol pol)
|
||||
{
|
||||
/* Clear CCxP and CCxNP to zero. For both edge trigger both fields are set. Case 10 is invalid. */
|
||||
TIM_CCER(timer_peripheral) &= ~(0x6 << (ic * 4));
|
||||
switch (pol)
|
||||
{
|
||||
case TIM_IC_RISING: /* 00 */
|
||||
break;
|
||||
case TIM_IC_BOTH: /* 11 */
|
||||
TIM_CCER(timer_peripheral) |= (0x6 << (ic * 4));
|
||||
break;
|
||||
case TIM_IC_FALLING: /* 01 */
|
||||
TIM_CCER(timer_peripheral) |= (0x2 << (ic * 4));
|
||||
}
|
||||
/* Clear CCxP and CCxNP to zero. For both edge trigger both fields are
|
||||
* set. Case 10 is invalid.
|
||||
*/
|
||||
TIM_CCER(timer_peripheral) &= ~(0x6 << (ic * 4));
|
||||
switch (pol) {
|
||||
case TIM_IC_RISING: /* 00 */
|
||||
break;
|
||||
case TIM_IC_BOTH: /* 11 */
|
||||
TIM_CCER(timer_peripheral) |= (0x6 << (ic * 4));
|
||||
break;
|
||||
case TIM_IC_FALLING: /* 01 */
|
||||
TIM_CCER(timer_peripheral) |= (0x2 << (ic * 4));
|
||||
}
|
||||
}
|
||||
/**@}*/
|
||||
|
||||
|
||||
@@ -33,15 +33,16 @@ Devices can have up to 3 USARTs and 2 UARTs.
|
||||
#include <libopencm3/stm32/usart.h>
|
||||
#include <libopencm3/stm32/rcc.h>
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Baudrate.
|
||||
|
||||
The baud rate is computed from the APB high-speed prescaler clock (for USART1/6)
|
||||
or the APB low-speed prescaler clock (for other USARTs). These values must
|
||||
be correctly set before calling this function (refer to the rcc_clock_setup-*
|
||||
functions in RCC).
|
||||
The baud rate is computed from the APB high-speed prescaler clock (for
|
||||
USART1/6) or the APB low-speed prescaler clock (for other USARTs). These values
|
||||
must be correctly set before calling this function (refer to the
|
||||
rcc_clock_setup-* functions in RCC).
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] baud unsigned 32 bit. Baud rate specified in Hz.
|
||||
*/
|
||||
|
||||
@@ -72,30 +73,34 @@ void usart_set_baudrate(u32 usart, u32 baud)
|
||||
USART_BRR(usart) = ((2 * clock) + baud) / (2 * baud);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Word Length.
|
||||
|
||||
The word length is set to 8 or 9 bits. Note that the last bit will be a parity bit
|
||||
if parity is enabled, in which case the data length will be 7 or 8 bits respectively.
|
||||
The word length is set to 8 or 9 bits. Note that the last bit will be a parity
|
||||
bit if parity is enabled, in which case the data length will be 7 or 8 bits
|
||||
respectively.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] bits unsigned 32 bit. Word length in bits 8 or 9.
|
||||
*/
|
||||
|
||||
void usart_set_databits(u32 usart, u32 bits)
|
||||
{
|
||||
if (bits == 8)
|
||||
if (bits == 8) {
|
||||
USART_CR1(usart) &= ~USART_CR1_M; /* 8 data bits */
|
||||
else
|
||||
} else {
|
||||
USART_CR1(usart) |= USART_CR1_M; /* 9 data bits */
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Stop Bit(s).
|
||||
|
||||
The stop bits are specified as 0.5, 1, 1.5 or 2.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] stopbits unsigned 32 bit. Stop bits @ref usart_cr2_stopbits.
|
||||
*/
|
||||
|
||||
@@ -108,12 +113,13 @@ void usart_set_stopbits(u32 usart, u32 stopbits)
|
||||
USART_CR2(usart) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Parity.
|
||||
|
||||
The parity bit can be selected as none, even or odd.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] parity unsigned 32 bit. Parity @ref usart_cr1_parity.
|
||||
*/
|
||||
|
||||
@@ -126,12 +132,13 @@ void usart_set_parity(u32 usart, u32 parity)
|
||||
USART_CR1(usart) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Rx/Tx Mode.
|
||||
|
||||
The mode can be selected as Rx only, Tx only or Rx+Tx.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] mode unsigned 32 bit. Mode @ref usart_cr1_mode.
|
||||
*/
|
||||
|
||||
@@ -144,12 +151,13 @@ void usart_set_mode(u32 usart, u32 mode)
|
||||
USART_CR1(usart) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Set Hardware Flow Control.
|
||||
|
||||
The flow control bit can be selected as none, RTS, CTS or RTS+CTS.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] flowcontrol unsigned 32 bit. Flowcontrol @ref usart_cr3_flowcontrol.
|
||||
*/
|
||||
|
||||
@@ -162,10 +170,11 @@ void usart_set_flow_control(u32 usart, u32 flowcontrol)
|
||||
USART_CR3(usart) = reg32;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Enable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable(u32 usart)
|
||||
@@ -173,12 +182,13 @@ void usart_enable(u32 usart)
|
||||
USART_CR1(usart) |= USART_CR1_UE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Disable.
|
||||
|
||||
At the end of the current frame, the USART is disabled to reduce power.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable(u32 usart)
|
||||
@@ -186,10 +196,11 @@ void usart_disable(u32 usart)
|
||||
USART_CR1(usart) &= ~USART_CR1_UE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Send a Data Word.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] data unsigned 16 bit.
|
||||
*/
|
||||
|
||||
@@ -199,12 +210,14 @@ void usart_send(u32 usart, u16 data)
|
||||
USART_DR(usart) = (data & USART_DR_MASK);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Read a Received Data Word.
|
||||
|
||||
If parity is enabled the MSB (bit 7 or 8 depending on the word length) is the parity bit.
|
||||
If parity is enabled the MSB (bit 7 or 8 depending on the word length) is the
|
||||
parity bit.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@returns unsigned 16 bit data word.
|
||||
*/
|
||||
|
||||
@@ -214,13 +227,14 @@ u16 usart_recv(u32 usart)
|
||||
return USART_DR(usart) & USART_DR_MASK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Wait for Transmit Data Buffer Empty
|
||||
|
||||
Blocks until the transmit data buffer becomes empty and is ready to accept the
|
||||
next data word.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_wait_send_ready(u32 usart)
|
||||
@@ -229,12 +243,13 @@ void usart_wait_send_ready(u32 usart)
|
||||
while ((USART_SR(usart) & USART_SR_TXE) == 0);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Wait for Received Data Available
|
||||
|
||||
Blocks until the receive data buffer holds a valid received data word.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_wait_recv_ready(u32 usart)
|
||||
@@ -243,13 +258,14 @@ void usart_wait_recv_ready(u32 usart)
|
||||
while ((USART_SR(usart) & USART_SR_RXNE) == 0);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Send Data Word with Blocking
|
||||
|
||||
Blocks until the transmit data buffer becomes empty then writes the next data word
|
||||
for transmission.
|
||||
Blocks until the transmit data buffer becomes empty then writes the next data
|
||||
word for transmission.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] data unsigned 16 bit.
|
||||
*/
|
||||
|
||||
@@ -259,12 +275,13 @@ void usart_send_blocking(u32 usart, u16 data)
|
||||
usart_send(usart, data);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Read a Received Data Word with Blocking.
|
||||
|
||||
Wait until a data word has been received then return the word.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@returns unsigned 16 bit data word.
|
||||
*/
|
||||
|
||||
@@ -275,7 +292,7 @@ u16 usart_recv_blocking(u32 usart)
|
||||
return usart_recv(usart);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Receiver DMA Enable.
|
||||
|
||||
DMA is available on:
|
||||
@@ -284,7 +301,8 @@ DMA is available on:
|
||||
@li USART3 Rx DMA1 channel 3.
|
||||
@li UART4 Rx DMA2 channel 3.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable_rx_dma(u32 usart)
|
||||
@@ -292,10 +310,11 @@ void usart_enable_rx_dma(u32 usart)
|
||||
USART_CR3(usart) |= USART_CR3_DMAR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Receiver DMA Disable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable_rx_dma(u32 usart)
|
||||
@@ -303,7 +322,7 @@ void usart_disable_rx_dma(u32 usart)
|
||||
USART_CR3(usart) &= ~USART_CR3_DMAR;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Transmitter DMA Enable.
|
||||
|
||||
DMA is available on:
|
||||
@@ -312,7 +331,8 @@ DMA is available on:
|
||||
@li USART3 Tx DMA1 channel 2.
|
||||
@li UART4 Tx DMA2 channel 5.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable_tx_dma(u32 usart)
|
||||
@@ -320,10 +340,11 @@ void usart_enable_tx_dma(u32 usart)
|
||||
USART_CR3(usart) |= USART_CR3_DMAT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Transmitter DMA Disable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable_tx_dma(u32 usart)
|
||||
@@ -331,10 +352,11 @@ void usart_disable_tx_dma(u32 usart)
|
||||
USART_CR3(usart) &= ~USART_CR3_DMAT;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Receiver Interrupt Enable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable_rx_interrupt(u32 usart)
|
||||
@@ -343,10 +365,11 @@ void usart_enable_rx_interrupt(u32 usart)
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Receiver Interrupt Disable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable_rx_interrupt(u32 usart)
|
||||
@@ -354,10 +377,11 @@ void usart_disable_rx_interrupt(u32 usart)
|
||||
USART_CR1(usart) &= ~USART_CR1_RXNEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Transmitter Interrupt Enable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable_tx_interrupt(u32 usart)
|
||||
@@ -365,10 +389,11 @@ void usart_enable_tx_interrupt(u32 usart)
|
||||
USART_CR1(usart) |= USART_CR1_TXEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Transmitter Interrupt Disable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable_tx_interrupt(u32 usart)
|
||||
@@ -376,10 +401,11 @@ void usart_disable_tx_interrupt(u32 usart)
|
||||
USART_CR1(usart) &= ~USART_CR1_TXEIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Error Interrupt Enable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_enable_error_interrupt(u32 usart)
|
||||
@@ -387,10 +413,11 @@ void usart_enable_error_interrupt(u32 usart)
|
||||
USART_CR3(usart) |= USART_CR3_EIE;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Error Interrupt Disable.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
*/
|
||||
|
||||
void usart_disable_error_interrupt(u32 usart)
|
||||
@@ -401,7 +428,8 @@ void usart_disable_error_interrupt(u32 usart)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief USART Read a Status Flag.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] flag Unsigned int32. Status register flag @ref usart_sr_flags.
|
||||
@returns boolean: flag set.
|
||||
*/
|
||||
@@ -422,7 +450,8 @@ flag, the function returns false.
|
||||
relating to LIN break, and error conditions in multibuffer communication, need
|
||||
to be added for completeness.
|
||||
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref usart_reg_base
|
||||
@param[in] usart unsigned 32 bit. USART block register address base @ref
|
||||
usart_reg_base
|
||||
@param[in] flag Unsigned int32. Status register flag @ref usart_sr_flags.
|
||||
@returns boolean: flag and interrupt enable both set.
|
||||
*/
|
||||
@@ -430,13 +459,15 @@ to be added for completeness.
|
||||
bool usart_get_interrupt_source(u32 usart, u32 flag)
|
||||
{
|
||||
u32 flag_set = (USART_SR(usart) & flag);
|
||||
/* IDLE, RXNE, TC, TXE interrupts */
|
||||
if ((flag >= USART_SR_IDLE) && (flag <= USART_SR_TXE))
|
||||
/* IDLE, RXNE, TC, TXE interrupts */
|
||||
if ((flag >= USART_SR_IDLE) && (flag <= USART_SR_TXE)) {
|
||||
return ((flag_set & USART_CR1(usart)) != 0);
|
||||
/* Overrun error */
|
||||
else if (flag == USART_SR_ORE)
|
||||
return (flag_set && (USART_CR3(usart) & USART_CR3_CTSIE));
|
||||
return (false);
|
||||
/* Overrun error */
|
||||
} else if (flag == USART_SR_ORE) {
|
||||
return flag_set && (USART_CR3(usart) & USART_CR3_CTSIE);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
Reference in New Issue
Block a user