-
Notifications
You must be signed in to change notification settings - Fork 997
Support for STM32L0 MCUs and Dragino LGT92 device #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- lgt92.json now inherits stm32l0x2.json
aykevl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks good to me! I have a number of code cleanliness issues but nothing major.
src/machine/board_lgt92.go
Outdated
| stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_IOPAEN) | ||
| stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_IOPBEN) | ||
| stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_IOPCEN) | ||
|
|
||
| // Enable NVM (eeprom) | ||
| stm32.RCC.AHBENR.SetBits(stm32.RCC_AHBENR_MIFEN) | ||
|
|
||
| // Enable Leds GPIO output | ||
| LED_RED.Configure(PinConfig{Mode: PinOutput}) | ||
| LED_GREEN.Configure(PinConfig{Mode: PinOutput}) | ||
| LED_BLUE.Configure(PinConfig{Mode: PinOutput}) | ||
|
|
||
| LED_RED.Low() | ||
| LED_GREEN.Low() | ||
| LED_BLUE.Low() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you doing this in the board file?
- Configuring outputs needs to be done by the program, unless it's really necessary they should be configured by a program that wants to use these LEDs.
- Is there any support for EEPROM? If not, I would suggest leaving it disabled (enabling unused peripherals may cost power).
- If you need to enable the GPIO peripheral (
stm32.RCC.IOPENR.SetBits(stm32.RCC_IOPENR_IOPAEN)), this should be done inPin.Configure. It looks like this is already done, so these lines are unnecessary.
src/machine/machine_stm32l0.go
Outdated
| // case 5: | ||
| // return stm32.GPIOF | ||
| // case 6: | ||
| // return stm32.GPIOG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If GPIOF etc. don't exist, you don't need to include them here. If you want to explain why you left them out, you could add a comment saying "GPIOF etc. do not exist on this chip".
src/machine/machine_stm32l0.go
Outdated
| // case unsafe.Pointer(stm32.TIM8): // TIM8 clock enable | ||
| // stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB2ENR_TIM8EN) | ||
| // case unsafe.Pointer(stm32.TIM1): // TIM1 clock enable | ||
| // stm32.RCC.APB2ENR.SetBits(stm32.RCC_APB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is again code that should be removed: TIM1 and TIM8 do not seem to exist on this chip.
src/machine/machine_stm32l0x2.go
Outdated
|
|
||
| // These are based on APB2 clock frquency (84MHz on the discovery board) | ||
| // TODO: also include the MCU/APB clock setting in the equation | ||
| switch true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the true here, a switch can also work as a replacement for a long if / else if / else chain.
| switch true { | |
| switch { |
src/machine/machine_stm32l0x2.go
Outdated
| conf = stm32.SPI_PCLK_2 | ||
| default: | ||
| // None of the specific baudrates were selected; choose the lowest speed | ||
| conf = stm32.SPI_PCLK_256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd default to 4MHz, but if that is not possible you could use a value just below that.
You can add such a check at the top by checking for 0:
if config.Frequency == 0 {
config.Frequency = 4e6
}
src/machine/machine_stm32l0x2.go
Outdated
| case localFrequency < 328125: | ||
| conf = stm32.SPI_PCLK_256 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be useful to make this calculation explicit. For example:
const apb2Frequency = 84e6
// ...
switch {
case localFrequency >= apb2Frequency / 2:
conf = stm32.SPI_PCLK_2
case localFrequency >= apb2Frequency / 4:
conf = stm32.SPI_PCLK_4
// ...
case localFrequency >= apb2Frequency / 128:
conf = stm32.SPI_PCLK_128
default:
conf = stm32.SPI_PCLK_256
}This way the calculation is very explicit. This kind of calculation is always done at compile time, so you don't need to worry about any overhead it might introduce.
You can take a look here as an example: #1446
targets/stm32l0x2.json
Outdated
| "flash-method": "openocd", | ||
| "openocd-interface": "stlink-v2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "flash-method": "openocd", | |
| "openocd-interface": "stlink-v2", |
These two lines are specific to the board, so shouldn't be in the chip specification.
targets/stm32l0x2.json
Outdated
| "--target=armv6m-none-eabi", | ||
| "-Qunused-arguments" | ||
| ], | ||
| "linkerscript": "targets/stm32l072czt6.ld", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "linkerscript": "targets/stm32l072czt6.ld", |
Because this linker script is for a more specific chip (with a given amount of memory), it shouldn't be included in the more generic chip family specification.
|
And before I forget: can you also add a smoke test to the Makefile? You can see a list of commands there already to run the smoke tests. |
Add default LED declaration so example compiles Remove useless hardware init and comments Move all machine_stm32l0x2 code back to machine_stm32l0 as it'll probably work for stm32l0x1 Move Flash-method,linkerscript... from chip target to board target json
|
Hi @aykevl, Thanks for your detailed review, and all the suggestions. Please tell me if you have other improvements. Olivier |
aykevl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fixes! Looks good to me now.
|
I will squash/merge this PR now. Thank you very much for the contribution @ofauchon |
This PR provides support for :
Working:
Not working yet: