Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1,946 changed files
with
338,123 additions
and
456,827 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
598 changes: 598 additions & 0 deletions
598
Discovery-F4/contents/module10/Code/SerialDemoI2C/I2CDemo.uvoptx
Large diffs are not rendered by default.
Oops, something went wrong.
608 changes: 608 additions & 0 deletions
608
Discovery-F4/contents/module10/Code/SerialDemoI2C/I2CDemo.uvprojx
Large diffs are not rendered by default.
Oops, something went wrong.
3,524 changes: 3,524 additions & 0 deletions
3,524
Discovery-F4/contents/module10/Code/SerialDemoI2C/RTE/Device/STM32F407VG/RTE_Device.h
Large diffs are not rendered by default.
Oops, something went wrong.
434 changes: 434 additions & 0 deletions
434
...y-F4/contents/module10/Code/SerialDemoI2C/RTE/Device/STM32F407VG/startup_stm32f40_41xxx.s
Large diffs are not rendered by default.
Oops, something went wrong.
936 changes: 936 additions & 0 deletions
936
Discovery-F4/contents/module10/Code/SerialDemoI2C/RTE/Device/STM32F407VG/system_stm32f4xx.c
Large diffs are not rendered by default.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
Discovery-F4/contents/module10/Code/SerialDemoI2C/RTE/RTE_Components.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
/* | ||
* Auto generated Run-Time-Environment Component Configuration File | ||
* *** Do not modify ! *** | ||
* | ||
* Project: 'Test' | ||
* Target: 'Target 1' | ||
*/ | ||
|
||
#ifndef RTE_COMPONENTS_H | ||
#define RTE_COMPONENTS_H | ||
|
||
#define RTE_DEVICE_STARTUP_STM32F4xx /* Device Startup for STM32F4 */ | ||
|
||
#endif /* RTE_COMPONENTS_H */ |
44 changes: 44 additions & 0 deletions
44
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/adc.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <platform.h> | ||
#include <adc.h> | ||
|
||
void adc_init(void) { | ||
|
||
//Enable the clock for ADC module and GPIO Port A | ||
RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN; | ||
RCC->APB2ENR|=RCC_APB2ENR_ADC1EN; | ||
|
||
//Configure the Port A pin 1 to be the Analogue Mode | ||
GPIOA->MODER|=GPIO_MODER_MODER1; | ||
GPIOA->PUPDR&=~(GPIO_PUPDR_PUPDR1); | ||
|
||
//Set the prescaler for the clock | ||
RCC->CFGR|=RCC_CFGR_PPRE2_DIV2; | ||
|
||
//Set ADC prescaler, divided by 2 | ||
ADC->CCR|=ADC_CCR_ADCPRE_0; | ||
|
||
//Power up the ADC module | ||
ADC1->CR2|=ADC_CR2_ADON; | ||
|
||
//480 cycles, better accuracy than 3 cycles | ||
ADC1->SMPR2|=ADC_SMPR2_SMP1; | ||
|
||
//Select channel 1 as input | ||
MODIFY_REG(ADC1->SQR3, ADC_SQR3_SQ1, ADC_SQR3_SQ1_0); | ||
|
||
} | ||
|
||
int adc_read(void) { | ||
|
||
//Software trigger the conversion | ||
ADC1->CR2|=ADC_CR2_SWSTART; | ||
|
||
//Wait for the completion of the conversion | ||
while(!(ADC1->SR&(1UL<<1))){} | ||
|
||
//Return the reading value | ||
return (ADC1->DR)*3; | ||
|
||
} | ||
|
||
// *******************************ARM University Program Copyright © ARM Ltd 2014************************************* |
19 changes: 19 additions & 0 deletions
19
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/adc.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*! | ||
* \file adc.h | ||
* \brief Internal analogue to digital converter (ADC) controller. | ||
* \copyright ARM University Program © ARM Ltd 2014. | ||
*/ | ||
#ifndef ADC_H | ||
#define ADC_H | ||
|
||
/*! \brief Initializes the analogue to digital converter, and configures | ||
* the appropriate GPIO pin. | ||
*/ | ||
void adc_init(void); | ||
|
||
/*! \brief Reads the current value of the ADC. | ||
* \return Potential of the pin, relative to ground. | ||
*/ | ||
int adc_read(void); | ||
|
||
#endif // ADC_H |
107 changes: 107 additions & 0 deletions
107
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/comparator.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include <platform.h> | ||
#include <comparator.h> | ||
#include <stdlib.h> | ||
|
||
static void (*CMP_callback)(int status); | ||
|
||
//Note: the interrupt can be only triggered once! | ||
void comparator_init(void) { | ||
// Initialise and enable the internal comparator, with | ||
// two external inputs. | ||
|
||
//Enable the clock for ADC module and GPIO Port A | ||
RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN; | ||
RCC->APB2ENR|=RCC_APB2ENR_ADC2EN; | ||
|
||
//Configure the Port A pin 2 to be the Analogue Mode | ||
GPIOA->MODER|=GPIO_MODER_MODER2; | ||
GPIOA->PUPDR&=~(GPIO_PUPDR_PUPDR2); | ||
|
||
//Set the prescaler for the clock | ||
RCC->CFGR|=RCC_CFGR_PPRE2_DIV2; | ||
|
||
//Set ADC prescaler, divided by 2 | ||
ADC->CCR|=ADC_CCR_ADCPRE_0; | ||
|
||
//Power up the ADC module, continous mode | ||
ADC2->CR2|=ADC_CR2_ADON | ADC_CR2_CONT; | ||
|
||
//480 cycles, better accuracy than 3 cycles | ||
ADC2->SMPR2|=ADC_SMPR2_SMP2; | ||
|
||
//Enable analog Watchdog Interrupt | ||
//AWCD watching channel 2 | ||
ADC2->CR1=ADC_CR1_AWDSGL|ADC_CR1_AWDEN|ADC_CR1_AWDCH_1; | ||
ADC2->CR1 |= ADC_CR1_AWDIE; | ||
|
||
//Set up the threshold | ||
//These threshold values may differe from one board to anothr! | ||
ADC2->LTR=(uint16_t)0x0000; | ||
|
||
//HTR should be larger than LTR | ||
ADC2->HTR=(uint16_t)0x0FFF/2; | ||
|
||
//Select channel 2 as input | ||
MODIFY_REG(ADC2->SQR3, ADC_SQR3_SQ1, ADC_SQR3_SQ1_1); | ||
|
||
ADC2->CR2|=ADC_CR2_SWSTART; | ||
|
||
} | ||
|
||
void comparator_set_callback(void (*callback)(int state)) { | ||
// Set up and enable the interrupt. | ||
|
||
// The callback function should be stored in an internal | ||
// static function pointer. | ||
|
||
// When the comparator ISR is fired, the callback function | ||
// should be executed. The state parameter should equal | ||
// comparator_read(). | ||
|
||
CMP_callback = callback; | ||
|
||
//NVIC configuration | ||
__enable_irq(); | ||
NVIC_SetPriority(ADC_IRQn,0); | ||
NVIC_ClearPendingIRQ(ADC_IRQn); | ||
NVIC_EnableIRQ(ADC_IRQn); | ||
} | ||
|
||
int comparator_read(void) { | ||
// Read the value outputted by the comparator. | ||
// Returns 1 for V+>V- and 0 for V+<V-. | ||
uint32_t count = 0x1FFFF; | ||
while(count--) | ||
{ | ||
__NOP(); | ||
} | ||
|
||
return (ADC2->SR&1); | ||
} | ||
|
||
void comparator_set_trigger(ComparatorTriggerMode trig) { | ||
// Set the interrupt trigger type of the comparator to either | ||
// disabled, rising edge, falling edge, or both edges. | ||
|
||
ADC2->SR&=~(ADC_SR_AWD); | ||
} | ||
|
||
void ADC_IRQHandler(void){ | ||
|
||
int CMP_IRQ_status = (ADC2->SR&1); | ||
|
||
NVIC_ClearPendingIRQ(ADC_IRQn); | ||
|
||
if(CMP_callback == NULL){ | ||
if((ADC2->SR&1<<0)==1){ | ||
ADC2->SR&=~(ADC_SR_AWD); | ||
} | ||
} | ||
else{ | ||
if((ADC2->SR&1<<0)==1){ | ||
CMP_callback(comparator_read()); | ||
ADC2->SR&=~(ADC_SR_AWD); | ||
NVIC_DisableIRQ(ADC_IRQn); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/comparator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*! | ||
* \file comparator.h | ||
* \brief Exposes functions of an internal comparator. | ||
* \copyright ARM University Program © ARM Ltd 2014. | ||
*/ | ||
#ifndef COMPARATOR_H | ||
#define COMPARATOR_H | ||
/*! Defines the triggering mode of the comparator's interrupt. */ | ||
typedef enum { | ||
CompNone, //!< Disables the interrupt. | ||
CompRising, //!< Enables an interrupt on the falling edge. | ||
CompFalling, //!< Enables an interrupt on the rising edge. | ||
CompBoth //!< Enables an interrupt on both the rising and falling edges. | ||
} ComparatorTriggerMode; | ||
|
||
/*! \brief Initializes the internal comparator. */ | ||
void comparator_init(void); | ||
|
||
/*! \brief Reads the current value of the comparator. | ||
* \return Output value of the comparator. | ||
*/ | ||
int comparator_read(void); | ||
|
||
/*! \brief Configures the event which will cause an interrupt. | ||
* \param trig New triggering mode. | ||
*/ | ||
void comparator_set_trigger(ComparatorTriggerMode trig); | ||
|
||
/*! \brief Pass a callback to the API, which is executed during the | ||
* interrupt handler. | ||
* | ||
* \sa comparator_set_trigger to configure and enable the interrupt. | ||
* | ||
* \param callback Callback function. | ||
*/ | ||
void comparator_set_callback(void (*callback)(int state)); | ||
|
||
#endif // COMPARATOR_H |
30 changes: 30 additions & 0 deletions
30
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/dac.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <dac.h> | ||
#include <platform.h> | ||
|
||
void dac_init(void) { | ||
// Enable the internal DAC targeting an external pin, | ||
// and any clock sources required to start the DAC. | ||
|
||
//Enable the clock for DAC module and GPIO Port A | ||
RCC->AHB1ENR|=RCC_AHB1ENR_GPIOAEN; | ||
RCC->APB1ENR|=RCC_APB1ENR_DACEN; | ||
|
||
//Configure the PoRT A pin 5 to be the Analogue | ||
GPIOA->MODER|=GPIO_MODER_MODER5; | ||
GPIOA->PUPDR&=~(GPIO_PUPDR_PUPDR5); | ||
|
||
//Enable the DAC | ||
DAC->CR|=DAC_CR_EN2; | ||
|
||
//Write to the DAC channel1 12-bit right-aligned data holding register | ||
DAC->DHR12R2=0; | ||
} | ||
|
||
void dac_set(int value) { | ||
// Sets the output value of the DAC. This function does | ||
// not need to wait until the DAC output has settled. | ||
|
||
DAC->DHR12R2 = value; | ||
} | ||
|
||
// *******************************ARM University Program Copyright © ARM Ltd 2014************************************* |
21 changes: 21 additions & 0 deletions
21
Discovery-F4/contents/module10/Code/SerialDemoI2C/drivers/dac.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*! | ||
* \file dac.h | ||
* \brief Internal digital to analogue converter (DAC) controller. | ||
* \copyright ARM University Program © ARM Ltd 2014. | ||
*/ | ||
#ifndef DAC_H | ||
#define DAC_H | ||
|
||
/*! \brief Initializes the digital to analogue converter, and configures | ||
* the appropriate GPIO pin. | ||
*/ | ||
void dac_init(void); | ||
|
||
/*! \brief Sets the DAC to a specified code. | ||
* \param value Code to set the DAC output to. | ||
*/ | ||
void dac_set(int value); | ||
|
||
#endif | ||
|
||
// *******************************ARM University Program Copyright © ARM Ltd 2014************************************* |
Oops, something went wrong.