Skip to content

Commit 914dd37

Browse files
committed
Merge pull request #818 from ohagendorf/stm32l053_rtos
DISCO/NUCLEO_L053xx - adding to RTOS, corrections for all tests, [DISCO_L053] exporter to µVision
2 parents 47ac39b + b9bef6b commit 914dd37

File tree

17 files changed

+773
-29
lines changed

17 files changed

+773
-29
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/TOOLCHAIN_GCC_ARM/startup_stm32l053xx.s

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ LoopFillZerobss:
100100
/* Call the clock system intitialization function.*/
101101
bl SystemInit
102102
/* Call static constructors */
103-
bl __libc_init_array
103+
//bl __libc_init_array
104104
/* Call the application's entry point.*/
105-
bl main
105+
//bl main
106+
bl _start
106107

107108
LoopForever:
108109
b LoopForever

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/TOOLCHAIN_GCC_ARM/startup_stm32l053xx.s

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,13 @@ LoopFillZerobss:
100100
/* Call the clock system intitialization function.*/
101101
bl SystemInit
102102
/* Call static constructors */
103-
bl __libc_init_array
103+
//bl __libc_init_array
104104
/* Call the application's entry point.*/
105-
bl main
105+
//bl main
106+
bl _start
106107

107108
LoopForever:
108-
b LoopForever
109+
b LoopForever
109110

110111

111112
.size Reset_Handler, .-Reset_Handler

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_L053C8/PeripheralNames.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ typedef enum {
5050
LPUART_1 = (int)LPUART1_BASE
5151
} UARTName;
5252

53-
#define STDIO_UART_TX PA_2
54-
#define STDIO_UART_RX PA_3
55-
#define STDIO_UART UART_2
53+
#define STDIO_UART_TX PA_9
54+
#define STDIO_UART_RX PA_10
55+
#define STDIO_UART UART_1
5656

5757
typedef enum {
5858
SPI_1 = (int)SPI1_BASE,

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_L053C8/rtc_api.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
*/
3030
#include "rtc_api.h"
3131

32+
/* The mcu STM32L053C8 seems to have a problem in the RCC - LSE hardware block. The Disco_L053 don't have a 32kHz crystal connected to LSE port pins.
33+
* During initialization the HAL tests if it can start the LSE oscillator. The Flag LSERDY in RCC_CSR should be set to 1 by RCC clock control when
34+
* the oscillator runs stable. Without a crystal the flag shouldn't be set and the HAL trys to start the internal LSI oscillator.
35+
* But the flag is also set to 1 without a crystal. That's why the RTC doesn't start.
36+
*
37+
*/
38+
#define DONT_USE_LSE
39+
3240
#if DEVICE_RTC
3341

3442
#include "mbed_error.h"
@@ -61,12 +69,14 @@ void rtc_init(void)
6169
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
6270
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
6371
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
72+
#ifndef DONT_USE_LSE
6473
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
6574
// Connect LSE to RTC
6675
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
6776
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
6877
rtc_freq = LSE_VALUE;
6978
} else {
79+
#endif
7080
// Enable LSI clock
7181
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
7282
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
@@ -79,8 +89,10 @@ void rtc_init(void)
7989
__HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
8090
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
8191
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
82-
rtc_freq = 32000;
92+
rtc_freq = 37000;
93+
#ifndef DONT_USE_LSE
8394
}
95+
#endif
8496

8597
// Enable RTC
8698
__HAL_RCC_RTC_ENABLE();

libraries/rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL}
286286
#elif defined(TARGET_STM32F429ZI)
287287
#define INITIAL_SP (0x20030000UL)
288288

289+
#elif defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
290+
#define INITIAL_SP (0x20002000UL)
291+
289292
#else
290293
#error "no target defined"
291294

libraries/rtos/rtx/TARGET_CORTEX_M/RTX_Conf_CM.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# define OS_TASKCNT 14
5656
# elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO) || defined(TARGET_LPC1114) \
5757
|| defined(TARGET_LPC812) || defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8) \
58-
|| defined(TARGET_STM32F103RB) || defined(TARGET_LPC824) || defined(TARGET_STM32F302R8) || defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8)
58+
|| defined(TARGET_STM32F103RB) || defined(TARGET_LPC824) || defined(TARGET_STM32F302R8) || defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8) || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
5959
# define OS_TASKCNT 6
6060
# else
6161
# error "no target defined"
@@ -72,7 +72,7 @@
7272
|| defined(TARGET_LPC812) || defined(TARGET_KL25Z) || defined(TARGET_KL05Z) || defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8) \
7373
|| defined(TARGET_STM32F103RB) || defined(TARGET_LPC824) || defined(TARGET_STM32F302R8)
7474
# define OS_SCHEDULERSTKSIZE 128
75-
# elif defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8)
75+
# elif defined(TARGET_STM32F334R8) || defined(TARGET_STM32F334C8) || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
7676
# define OS_SCHEDULERSTKSIZE 112
7777
# else
7878
# error "no target defined"
@@ -160,6 +160,9 @@
160160
#elif defined(TARGET_STM32F302R8)
161161
# define OS_CLOCK 64000000
162162

163+
#elif defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
164+
# define OS_CLOCK 32000000
165+
163166
# else
164167
# error "no target defined"
165168
# endif

libraries/tests/rtos/mbed/basic/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
#include "mbed.h"
22
#include "rtos.h"
33

4+
/*
5+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
6+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
7+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
8+
*/
9+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
10+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
11+
#else
12+
#define STACK_SIZE DEFAULT_STACK_SIZE
13+
#endif
14+
415
void print_char(char c = '*')
516
{
617
printf("%c", c);
@@ -19,7 +30,7 @@ void led2_thread(void const *argument) {
1930
}
2031

2132
int main() {
22-
Thread thread(led2_thread);
33+
Thread thread(led2_thread, NULL, osPriorityNormal, STACK_SIZE);
2334

2435
while (true) {
2536
led1 = !led1;

libraries/tests/rtos/mbed/isr/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
#define QUEUE_PUT_ISR_VALUE 128
88
#define QUEUE_PUT_THREAD_VALUE 127
99

10+
/*
11+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
12+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
13+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
14+
*/
15+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
16+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
17+
#else
18+
#define STACK_SIZE DEFAULT_STACK_SIZE
19+
#endif
20+
1021
Queue<uint32_t, QUEUE_SIZE> queue;
1122

1223
DigitalOut myled(LED1);
@@ -25,7 +36,7 @@ void queue_thread(void const *argument) {
2536
}
2637

2738
int main (void) {
28-
Thread thread(queue_thread);
39+
Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE);
2940
Ticker ticker;
3041
ticker.attach(queue_isr, 1.0);
3142
int isr_puts_counter = 0;

libraries/tests/rtos/mbed/mail/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ typedef struct {
1313
#define QUEUE_SIZE 16
1414
#define QUEUE_PUT_DELAY 100
1515

16+
/*
17+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
18+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
19+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
20+
*/
21+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
22+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
23+
#else
24+
#define STACK_SIZE DEFAULT_STACK_SIZE
25+
#endif
26+
1627
Mail<mail_t, QUEUE_SIZE> mail_box;
1728

1829
void send_thread (void const *argument) {
@@ -29,7 +40,7 @@ void send_thread (void const *argument) {
2940
}
3041

3142
int main (void) {
32-
Thread thread(send_thread);
43+
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
3344
bool result = true;
3445
int result_counter = 0;
3546

libraries/tests/rtos/mbed/mutex/main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
#define THREAD_DELAY 50
66
#define SIGNALS_TO_EMIT 100
77

8+
/*
9+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
10+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
11+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
12+
*/
13+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
14+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
15+
#else
16+
#define STACK_SIZE DEFAULT_STACK_SIZE
17+
#endif
18+
819
void print_char(char c = '*')
920
{
1021
printf("%c", c);
@@ -52,8 +63,8 @@ int main() {
5263
const int t1_delay = THREAD_DELAY * 1;
5364
const int t2_delay = THREAD_DELAY * 2;
5465
const int t3_delay = THREAD_DELAY * 3;
55-
Thread t2(test_thread, (void *)t2_delay);
56-
Thread t3(test_thread, (void *)t3_delay);
66+
Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE);
67+
Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE);
5768

5869
while (true) {
5970
// Thread 1 action

libraries/tests/rtos/mbed/queue/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ typedef struct {
1313
#define QUEUE_SIZE 16
1414
#define QUEUE_PUT_DELAY 100
1515

16+
/*
17+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
18+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
19+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
20+
*/
21+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
22+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
23+
#else
24+
#define STACK_SIZE DEFAULT_STACK_SIZE
25+
#endif
26+
1627
MemoryPool<message_t, QUEUE_SIZE> mpool;
1728
Queue<message_t, QUEUE_SIZE> queue;
1829

@@ -31,7 +42,7 @@ void send_thread (void const *argument) {
3142
}
3243

3344
int main (void) {
34-
Thread thread(send_thread);
45+
Thread thread(send_thread, NULL, osPriorityNormal, STACK_SIZE);
3546
bool result = true;
3647
int result_counter = 0;
3748

libraries/tests/rtos/mbed/semaphore/main.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#define SEMAPHORE_SLOTS 2
77
#define SEM_CHANGES 100
88

9+
/*
10+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
11+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
12+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
13+
*/
14+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
15+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
16+
#else
17+
#define STACK_SIZE DEFAULT_STACK_SIZE
18+
#endif
19+
920
void print_char(char c = '*')
1021
{
1122
printf("%c", c);
@@ -41,9 +52,9 @@ int main (void) {
4152
const int t1_delay = THREAD_DELAY * 1;
4253
const int t2_delay = THREAD_DELAY * 2;
4354
const int t3_delay = THREAD_DELAY * 3;
44-
Thread t1(test_thread, (void *)t1_delay);
45-
Thread t2(test_thread, (void *)t2_delay);
46-
Thread t3(test_thread, (void *)t3_delay);
55+
Thread t1(test_thread, (void *)t1_delay, osPriorityNormal, STACK_SIZE);
56+
Thread t2(test_thread, (void *)t2_delay, osPriorityNormal, STACK_SIZE);
57+
Thread t3(test_thread, (void *)t3_delay, osPriorityNormal, STACK_SIZE);
4758

4859
while (true) {
4960
if (change_counter >= SEM_CHANGES or sem_defect == true) {

libraries/tests/rtos/mbed/signals/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
#define SIGNAL_HANDLE_DELEY 25
77
#define SIGNAL_SET_VALUE 0x01
88

9+
/*
10+
* The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
11+
* the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
12+
* and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
13+
*/
14+
#if defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
15+
#define STACK_SIZE DEFAULT_STACK_SIZE/4
16+
#else
17+
#define STACK_SIZE DEFAULT_STACK_SIZE
18+
#endif
19+
920
DigitalOut led(LED1);
1021
volatile int signal_counter = 0;
1122

@@ -19,7 +30,7 @@ void led_thread(void const *argument) {
1930
}
2031

2132
int main (void) {
22-
Thread thread(led_thread);
33+
Thread thread(led_thread, NULL, osPriorityNormal, STACK_SIZE);
2334
bool result = true;
2435

2536
while (true) {

workspace_tools/export/uvision4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Uvision4(Exporter):
5959
'ARCH_PRO',
6060
'ARCH_BLE',
6161
'DISCO_F407VG',
62+
'DISCO_L053C8',
6263
'MTS_GAMBIT',
6364
'ARCH_MAX',
6465
'MTS_MDOT_F405RG',

0 commit comments

Comments
 (0)