Skip to content

Commit 2c01477

Browse files
committed
Minor tweaks in STM32 examples
Fix comments in newer mip initialization (main.c) Correct stack initialization (boot.c) Remove SCC clock enable when not needed (mcu.h)
1 parent 0b2712f commit 2c01477

File tree

7 files changed

+8
-14
lines changed

7 files changed

+8
-14
lines changed

examples/stm32/nucleo-f429zi-baremetal/boot.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
// Startup code
55
__attribute__((naked, noreturn)) void _reset(void) {
6-
// Init stack
7-
asm("ldr sp, = _estack");
8-
96
// Initialise memory
107
extern long _sbss, _ebss, _sdata, _edata, _sidata;
118
for (long *src = &_sbss; src < &_ebss; src++) *src = 0;
@@ -125,9 +122,10 @@ WEAK_ALIAS void LTDC_ER_IRQHandler(void);
125122
WEAK_ALIAS void DMA2D_IRQHandler(void);
126123

127124
// IRQ table
125+
extern void _estack();
128126
__attribute__((section(".vectors"))) void (*tab[16 + 91])(void) = {
129127
// Cortex interrupts
130-
0, _reset, NMI_Handler, HardFault_Handler, MemManage_Handler,
128+
_estack, _reset, NMI_Handler, HardFault_Handler, MemManage_Handler,
131129
BusFault_Handler, UsageFault_Handler, 0, 0, 0, 0, SVC_Handler,
132130
DebugMon_Handler, 0, PendSV_Handler, SysTick_Handler,
133131

examples/stm32/nucleo-f429zi-baremetal/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(void) {
6868
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
6969

7070
// Initialise Mongoose network stack
71-
// Specify MAC address, and use 0 for IP, mask, GW - i.e. use DHCP
71+
// Specify MAC address, either set use_dhcp or enter a static config.
7272
// For static configuration, specify IP/mask/GW in network byte order
7373
struct mip_driver_stm32 driver_data = {.mdc_cr = 4}; // See driver_stm32.h
7474
struct mip_if mif = {

examples/stm32/nucleo-f429zi-baremetal/mcu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static inline void systick_init(uint32_t ticks) {
6565
SYSTICK->LOAD = ticks - 1;
6666
SYSTICK->VAL = 0;
6767
SYSTICK->CTRL = BIT(0) | BIT(1) | BIT(2); // Enable systick
68-
RCC->APB2ENR |= BIT(14); // Enable SYSCFG
6968
}
7069

7170
struct flash {

examples/stm32/nucleo-f429zi-freertos-mip/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void ethernet_init(void) {
3131
}
3232

3333
NVIC_EnableIRQ(61); // Setup Ethernet IRQ handler
34+
RCC->APB2ENR |= BIT(14); // Enable SYSCFG
3435
SYSCFG->PMC |= BIT(23); // Use RMII. Goes first!
3536
RCC->AHB1ENR |= BIT(25) | BIT(26) | BIT(27); // Enable Ethernet clocks
3637
RCC->AHB1RSTR |= BIT(25); // ETHMAC force reset
@@ -43,7 +44,7 @@ static void server(void *args) {
4344
mg_log_set(MG_LL_DEBUG); // Set log level
4445

4546
// Initialise Mongoose network stack
46-
// Specify MAC address, and use 0 for IP, mask, GW - i.e. use DHCP
47+
// Specify MAC address, either set use_dhcp or enter a static config.
4748
// For static configuration, specify IP/mask/GW in network byte order
4849
MG_INFO(("Initializing Ethernet driver"));
4950
ethernet_init();
@@ -74,7 +75,6 @@ static void blinker(void *args) {
7475
}
7576

7677
int main(void) {
77-
RCC->APB2ENR |= BIT(14); // Enable SYSCFG: for systick & Ethernet
7878
clock_init(); // Set clock to max of 180 MHz
7979
systick_init(FREQ / 1000); // Tick every 1 ms
8080
uart_init(UART3, 115200); // Initialise UART

examples/stm32/nucleo-f746zg-baremetal/boot.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
// Startup code
55
__attribute__((naked, noreturn)) void _reset(void) {
6-
// Init stack
7-
asm("ldr sp, = _estack");
8-
96
// Initialise memory
107
extern long _sbss, _ebss, _sdata, _edata, _sidata;
118
for (long *src = &_sbss; src < &_ebss; src++) *src = 0;
@@ -132,9 +129,10 @@ WEAK_ALIAS void I2C4_ER_IRQHandler(void);
132129
WEAK_ALIAS void SPDIF_RX_IRQHandler(void);
133130

134131
// IRQ table
132+
extern void _estack();
135133
__attribute__((section(".vectors"))) void (*tab[16 + 98])(void) = {
136134
// Cortex interrupts
137-
0, _reset, NMI_Handler, HardFault_Handler, MemManage_Handler,
135+
_estack, _reset, NMI_Handler, HardFault_Handler, MemManage_Handler,
138136
BusFault_Handler, UsageFault_Handler, 0, 0, 0, 0, SVC_Handler,
139137
DebugMon_Handler, 0, PendSV_Handler, SysTick_Handler,
140138

examples/stm32/nucleo-f746zg-baremetal/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(void) {
6868
mg_timer_add(&mgr, 500, MG_TIMER_REPEAT, blink_cb, &mgr);
6969

7070
// Initialise Mongoose network stack
71-
// Specify MAC address, and use 0 for IP, mask, GW - i.e. use DHCP
71+
// Specify MAC address, either set use_dhcp or enter a static config.
7272
// For static configuration, specify IP/mask/GW in network byte order
7373
struct mip_driver_stm32 driver_data = {.mdc_cr = 4}; // See driver_stm32.h
7474
struct mip_if mif = {

examples/stm32/nucleo-f746zg-baremetal/mcu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ static inline void systick_init(uint32_t ticks) {
6666
SYSTICK->LOAD = ticks - 1;
6767
SYSTICK->VAL = 0;
6868
SYSTICK->CTRL = BIT(0) | BIT(1) | BIT(2); // Enable systick
69-
RCC->APB2ENR |= BIT(14); // Enable SYSCFG
7069
}
7170

7271
struct flash {

0 commit comments

Comments
 (0)