Skip to content

Commit f4d4df8

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 5efe069 + 4e5bafa commit f4d4df8

File tree

15 files changed

+179
-253
lines changed

15 files changed

+179
-253
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.orig
22
*.swp
3+
.DS_Store
4+
boards.local.txt
5+
platform.local.txt

cores/arduino/HardwareSerial.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ void serialEventRun(void)
138138
}
139139

140140
// Constructors ////////////////////////////////////////////////////////////////
141+
HardwareSerial::HardwareSerial(uint32_t _rx, uint32_t _tx)
142+
{
143+
_serial.pin_rx = digitalPinToPinName(_rx);
144+
_serial.pin_tx = digitalPinToPinName(_tx);
145+
init();
146+
}
147+
141148
HardwareSerial::HardwareSerial(PinName _rx, PinName _tx)
142149
{
143150
_serial.pin_rx = _rx;

cores/arduino/HardwareSerial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class HardwareSerial : public Stream
101101
serial_t _serial;
102102

103103
public:
104+
HardwareSerial(uint32_t _rx, uint32_t _tx);
104105
HardwareSerial(PinName _rx, PinName _tx);
105106
HardwareSerial(void* peripheral);
106107
void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }

cores/arduino/Tone.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ void noTone(uint8_t _pin)
4444
PinName p = digitalPinToPinName(_pin);
4545
if(p != NC) {
4646
TimerPinDeinit(&_timer);
47-
digitalWrite(_pin, 0);
4847
g_lastPin = NC;
4948
}
5049
}

cores/arduino/main.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ void initVariant() { }
2929
// Force init to be called *first*, i.e. before static object allocation.
3030
// Otherwise, statically allocated objects that need HAL may fail.
3131
__attribute__(( constructor (101))) void premain() {
32-
init();
32+
33+
// Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html
34+
#ifdef NVIC_PRIORITYGROUP_4
35+
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
36+
#endif
37+
38+
init();
3339
}
3440

3541
/*

cores/arduino/stm32/hw_config.c

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -35,71 +35,13 @@
3535
*
3636
******************************************************************************
3737
*/
38-
/** @addtogroup CMSIS
39-
* @{
40-
*/
41-
42-
/** @addtogroup stm32f4xx_system
43-
* @{
44-
*/
45-
46-
/** @addtogroup STM32F4xx_System_Private_Includes
47-
* @{
48-
*/
4938
#include "stm32_def.h"
5039
#include "hw_config.h"
5140

5241
#ifdef __cplusplus
5342
extern "C" {
5443
#endif
5544

56-
/**
57-
* @}
58-
*/
59-
60-
/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
61-
* @{
62-
*/
63-
64-
/**
65-
* @}
66-
*/
67-
68-
/** @addtogroup STM32F4xx_System_Private_Defines
69-
* @{
70-
*/
71-
/**
72-
* @}
73-
*/
74-
75-
/** @addtogroup STM32F4xx_System_Private_Macros
76-
* @{
77-
*/
78-
79-
/**
80-
* @}
81-
*/
82-
83-
/** @addtogroup STM32F4xx_System_Private_Variables
84-
* @{
85-
*/
86-
87-
/**
88-
* @}
89-
*/
90-
91-
/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
92-
* @{
93-
*/
94-
95-
/**
96-
* @}
97-
*/
98-
99-
/** @addtogroup STM32F4xx_System_Private_Functions
100-
* @{
101-
*/
102-
10345
/**
10446
* @brief This function performs the global init of the system (HAL, IOs...)
10547
* @param None
@@ -113,122 +55,6 @@ void hw_config_init(void)
11355
// Configure the system clock
11456
SystemClock_Config();
11557
}
116-
117-
/******************************************************************************/
118-
/* Cortex-M4 Processor Interruption and Exception Handlers */
119-
/******************************************************************************/
120-
121-
/**
122-
* @brief This function handles Non maskable interrupt.
123-
*/
124-
void NMI_Handler(void)
125-
{
126-
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
127-
128-
/* USER CODE END NonMaskableInt_IRQn 0 */
129-
130-
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
131-
132-
/* USER CODE END NonMaskableInt_IRQn 1 */
133-
134-
}
135-
136-
/**
137-
* @brief This function handles Hard fault interrupt.
138-
*/
139-
void HardFault_Handler(void)
140-
{
141-
/* USER CODE BEGIN HardFault_IRQn 0 */
142-
143-
/* USER CODE END HardFault_IRQn 0 */
144-
while (1)
145-
{
146-
}
147-
/* USER CODE BEGIN HardFault_IRQn 1 */
148-
149-
/* USER CODE END HardFault_IRQn 1 */
150-
}
151-
152-
/**
153-
* @brief This function handles Memory management fault.
154-
*/
155-
void MemManage_Handler(void)
156-
{
157-
158-
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
159-
160-
/* USER CODE END MemoryManagement_IRQn 0 */
161-
while (1)
162-
{
163-
}
164-
/* USER CODE BEGIN MemoryManagement_IRQn 1 */
165-
166-
/* USER CODE END MemoryManagement_IRQn 1 */
167-
}
168-
169-
/**
170-
* @brief This function handles Pre-fetch fault, memory access fault.
171-
*/
172-
void BusFault_Handler(void)
173-
{
174-
175-
/* USER CODE BEGIN BusFault_IRQn 0 */
176-
177-
/* USER CODE END BusFault_IRQn 0 */
178-
while (1)
179-
{
180-
}
181-
/* USER CODE BEGIN BusFault_IRQn 1 */
182-
183-
/* USER CODE END BusFault_IRQn 1 */
184-
}
185-
186-
/**
187-
* @brief This function handles Undefined instruction or illegal state.
188-
*/
189-
void UsageFault_Handler(void)
190-
{
191-
192-
/* USER CODE BEGIN UsageFault_IRQn 0 */
193-
194-
/* USER CODE END UsageFault_IRQn 0 */
195-
while (1)
196-
{
197-
}
198-
/* USER CODE BEGIN UsageFault_IRQn 1 */
199-
200-
/* USER CODE END UsageFault_IRQn 1 */
201-
}
202-
203-
/**
204-
* @brief This function handles Debug monitor.
205-
*/
206-
void DebugMon_Handler(void)
207-
{
208-
209-
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
210-
211-
/* USER CODE END DebugMonitor_IRQn 0 */
212-
while (1)
213-
{
214-
}
215-
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
216-
217-
/* USER CODE END DebugMonitor_IRQn 1 */
218-
}
219-
220-
221-
/**
222-
* @}
223-
*/
224-
225-
/**
226-
* @}
227-
*/
228-
229-
/**
230-
* @}
231-
*/
23258
#ifdef __cplusplus
23359
}
23460
#endif

cores/arduino/stm32/timer.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,10 @@ uint32_t getTimerIrq(TIM_TypeDef* tim)
558558
*/
559559
void TimerHandleDeinit(stimer_t *obj)
560560
{
561-
HAL_TIM_Base_DeInit(&(obj->handle));
562-
HAL_TIM_Base_Stop_IT(&(obj->handle));
561+
if(obj != NULL) {
562+
HAL_TIM_Base_DeInit(&(obj->handle));
563+
HAL_TIM_Base_Stop_IT(&(obj->handle));
564+
}
563565
}
564566

565567
/**
@@ -855,32 +857,16 @@ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
855857
*/
856858
void HAL_TIMx_PeriodElapsedCallback(stimer_t *obj)
857859
{
860+
GPIO_TypeDef* port = get_GPIO_Port(STM_PORT(obj->pin));
858861

859-
if(get_GPIO_Port(STM_PORT(obj->pin)) != NULL) {
860-
if(obj->pinInfo.count > 0){
861-
obj->pinInfo.count--;
862-
863-
if(obj->pinInfo.state == 0) {
864-
obj->pinInfo.state = 1;
865-
digital_io_write(get_GPIO_Port(STM_PORT(obj->pin)), STM_GPIO_PIN(obj->pin), 1);
866-
}
867-
else {
868-
obj->pinInfo.state = 0;
869-
digital_io_write(get_GPIO_Port(STM_PORT(obj->pin)), STM_GPIO_PIN(obj->pin), 0);
870-
}
871-
}
872-
else if(obj->pinInfo.count == -1) {
873-
if(obj->pinInfo.state == 0) {
874-
obj->pinInfo.state = 1;
875-
digital_io_write(get_GPIO_Port(STM_PORT(obj->pin)), STM_GPIO_PIN(obj->pin), 1);
876-
}
877-
else {
878-
obj->pinInfo.state = 0;
879-
digital_io_write(get_GPIO_Port(STM_PORT(obj->pin)), STM_GPIO_PIN(obj->pin), 0);
880-
}
862+
if(port != NULL) {
863+
if(obj->pinInfo.count != 0){
864+
if (obj->pinInfo.count > 0) obj->pinInfo.count--;
865+
obj->pinInfo.state = (obj->pinInfo.state == 0)? 1 : 0;
866+
digital_io_write(port, STM_GPIO_PIN(obj->pin), obj->pinInfo.state);
881867
}
882868
else {
883-
digital_io_write(get_GPIO_Port(STM_PORT(obj->pin)), STM_GPIO_PIN(obj->pin), 0);
869+
digital_io_write(port, STM_GPIO_PIN(obj->pin), 0);
884870
}
885871
}
886872
}
@@ -916,13 +902,19 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
916902
uint32_t timFreq = 2*frequency;
917903
uint32_t prescaler = 1;
918904
uint32_t period = 0;
905+
uint32_t scale = 0;
919906

920907
if(frequency > MAX_FREQ)
921908
return;
922909

923910
obj->timer = TIMER_TONE;
924911
obj->pinInfo.state = 0;
925912

913+
if(frequency == 0) {
914+
TimerPinDeinit(obj);
915+
return;
916+
}
917+
926918
//Calculate the toggle count
927919
if (duration > 0) {
928920
obj->pinInfo.count = ((timFreq * duration) / 1000);
@@ -934,8 +926,10 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
934926
digital_io_init(obj->pin, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL);
935927
timClkFreq = getTimerClkFreq(obj->timer);
936928

929+
// Do this once
930+
scale = timClkFreq / timFreq;
937931
while(end == 0) {
938-
period = ((uint32_t)( timClkFreq / timFreq / prescaler)) - 1;
932+
period = ((uint32_t)( scale / prescaler)) - 1;
939933

940934
if((period >= 0xFFFF) && (prescaler < 0xFFFF))
941935
prescaler++; //prescaler *= 2;
@@ -962,6 +956,7 @@ void TimerPinInit(stimer_t *obj, uint32_t frequency, uint32_t duration)
962956
void TimerPinDeinit(stimer_t *obj)
963957
{
964958
TimerHandleDeinit(obj);
959+
digital_io_init(obj->pin, GPIO_MODE_INPUT, GPIO_NOPULL);
965960
}
966961

967962
/**

0 commit comments

Comments
 (0)